Absolutely wonderful introduction to monads. I really appreciate the time you take to explain things from scratch. Can't wait to read the next article :) !
Thanks for your comments, and sorry to be responding so long after you posted this!
Anyway, IO values and regular values are often conflated at the ghci toplevel in ways that would never happen in a running Haskell program. For instance:
Prelude> return 10 10 Prelude> :t it 10 :: Integer
Essentially, "it" must unpack the IO value "return 10" into just 10. The way to think about it is that all of ghci is running inside the IO monad. So you can do stuff like this:
Prelude> s <- getLine foobar Prelude> s "foobar"
In a compiled Haskell program, this would have to be inside a do expression or it wouldn't compile.
Comments 18
Reply
Reply
Reply
Reply
Reply
Reply
Thanks!
Reply
Reply
Btw I am wondering why when applying getLine the "it" value is type as String not as IO String?
Prelude> getLine
ertrtet
"ertrtet"
it :: String
Prelude>
Reply
Anyway, IO values and regular values are often conflated at the ghci toplevel in ways that would never happen in a running Haskell program. For instance:
Prelude> return 10
10
Prelude> :t it
10 :: Integer
Essentially, "it" must unpack the IO value "return 10" into just 10. The way to think about it is that all of ghci is running inside the IO monad. So you can do stuff like this:
Prelude> s <- getLine
foobar
Prelude> s
"foobar"
In a compiled Haskell program, this would have to be inside a do expression or it wouldn't compile.
Hope this helps!
Reply
Leave a comment