Reputation: 483
Hey so I am trying to learn haskell and im running into trouble writing a program that requires me to collect Ints from the user in the terminal. how would i do this ive tried things like this
import Data.Char (digitToInt)
getArguments :: IO Int
getArguments =
do putStrLn "Enter the number of arguments you want to have"
arguments <- getChar
return (digitToInt arguments)
main :: IO()
main = do
putStrLn "Welcome to Random Argument Generator"
let x = getArguments
print x+1
but this does not work plz help!
Upvotes: 1
Views: 106
Reputation: 61
replace let x = getArguments
with x <- getArguments
the type signature for getArguments
is (correctly) :: IO Int
, which means that Int
is 'wrapped' inside the IO monad, which means that you have to use the val <- func
syntax to unwrap it.
If getArguments
were a pure function (:: Int
) the let syntax would have been correct.
Upvotes: 6