Re:IO Monad Considered Harmful
by rapala on Friday January 23, 2015 @02:45AM
(#8933825)
Which can then be made to look exactly like the
case by doing
(Edited to include the definition of main)
[ Parent
| on HN ]
Re:IO Monad Considered Harmful
by ggchappell on Friday January 23, 2015 @02:54AM
(#8933844)
This is a nice approach. Thanks to all of you in this thread. I think I'll try something like this when I introduce Haskell I/O in my Programming Languages class in a month or two.
If this is meant to be under main, you need a "let":
main = do
let greet name = putStrLn ("Hello, " ++ name)
getLine >>= greet
For whatever reason, I didn't learn about the magic let syntax in do-notation until relatively late. Anyways this is very elegant, but not something I could have generated early on, especially because it mixes two different sequencing syntaxes (do-notation and >>=).