I am new to Haskell. I want to have a function in which I get an Int value from the user using
putStr "Please Enter Your Number : "
submit_ans<- getLine
then after a series of calculations returns another Int which will be used by another function that has called it. What is the type of the described function? should I use return function at the end?
thanks in advance!
Update #1
ok I updated the function as below:
myFunction :: Int -> IO Int
myFunction action = do
putStr "\tPlease Enter Your Number : "
submit_ans <- getLine
if action == 1
then do
myFunctionII read submit_ans
else do
putStrLn("\n")
it gives me this error:
*** Term : myFunction
*** Type : Int -> IO Int
*** Does not match : IO a
IO Intif one cannot use the returned value?IOmonad. Part of the "point" is indeed to dinstinguish between pure (non-IO) and impure (IO) code! A pure function always returns the same when given the same input. An impure one could burn down your house and eat your cat every third full moon on days beginning with s. It's nice to be able to treat the two kinds of functions differently.getLineto get the number, and then from that function call the pure functions that you want do stuff with the number you got (which you can get, since you're in the IO monad now). In other words: Have the IO code call the pure code, not the other way around.