Yet Another Monad Tutorial (part 1: basics)

Jul 25, 2010 18:57


It's a standing joke in the Haskell community that every Haskell programmer ( Read more... )

Leave a comment

Comments 18

Thank you anonymous May 4 2011, 20:59:18 UTC
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 :) !

Reply

Re: Thank you mvanier May 5 2011, 00:52:30 UTC
You're welcome! I'm always happy when people get something out of my blog posts.

Reply


Fantastic Tutorial ext_558365 May 16 2011, 03:58:29 UTC
I have been struggling with Monads for weeks, and this is the tutorial that finally helped me understand them. Thanks a ton for writing this!

Reply

Re: Fantastic Tutorial mvanier May 16 2011, 07:33:17 UTC
Thanks a ton for reading it! :-) I'm glad it helped you understand monads. There will be more to come.

Reply


Very, very helpful anonymous May 20 2011, 00:53:18 UTC
Clarity like this is all too rare. Nice job - just the monad jumpstart I needed

Reply

Re: Very, very helpful mvanier May 20 2011, 01:02:21 UTC
Thanks! Clarity is my #1 priority.

Reply


Very nice introduction! anonymous June 28 2011, 23:24:33 UTC
I especially like the use of unit to explain an "action". Sure makes it clearer than some of those other tutorials.

Thanks!

Reply

Re: Very nice introduction! mvanier June 28 2011, 23:55:46 UTC
Thanks for your kind comments!

Reply


Nice instroduction mathk September 6 2011, 15:25:43 UTC
Nice introduction. That is very helpful.
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

mvanier November 15 2012, 03:54:54 UTC
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.

Hope this helps!

Reply


Leave a comment

Up