I am writing my first Haskell program and I am having difficulties in making a function use a user-entered input value. I don't yet understand enough about the language, so I started off simply, by creating a function that reads in a user-input value and returns this as an integer. Then, in the main calling function I want to use this value as the input to another function. This is the code scenario:
module Main where
square :: Int -> Int
square n = n*n
getInt :: IO Integer
getInt = do
putStrLn "Enter a positive integer: "
s <- getLine
putStrLn("The number you entered is " ++ s)
let num = read s :: Integer
return num
main :: IO ()
main = do
num <- getInt
print num -- works
print $ square (getInt) -- breaks down here
print $ square (num) -- also does not work
print $ square (5) -- works