Well I can see that I haven't done any learning of Haskell for ages. Now that I look back at it, it all looks like gobbledigook to me. Well I probably need to get on with doing some questions:
Exercises
- Redo the "Haskell greeting" exercise in Simple input and output/Controlling actions, this time using a
case
statement.
myDoGuessing num = do
putStrLn "Enter your guess:"
guess <- getLine
case compare (read guess) num of
LT -> do putStrLn "Too low!"
myDoGuessing num
GT -> do putStrLn "Too high!"
myDoGuessing num
EQ -> do putStrLn "You Win!"
- What does the following program print out? And why?
main = do x <- getX putStrLn x getX = do return "My Shangri-La" return "beneath" return "the summer moon" return "I will" return "return" return "again"
I thought it would print out 'again'. The reason is that getX executes a series of actions and the last one is what the function evaluates to.