[Haskell-beginners] Parser composition

Amy de Buitléir amy at nualeargais.ie
Fri Dec 3 00:15:46 CET 2010


Someone else can probably explain this better than I, but...

"return" takes a value and puts it in a minimal context that still
yields that value. I think of "return" as saying "take this ordinary
value and make a monadic value out of it, in the most straightforward
way possible". Consider the Maybe monad, for example. What kind of
value would you expect the expresion "return 7" to create? Well, there
are only two constructors for Maybe values, Just ___ and Nothing. The
latter wouldn't do any good, because it doesn't encapsulate the value
"7" in any way. So the only choice is "Just 7".

>>= is like function application, only instead of taking a normal value and feeding it to a normal function, it takes a monadic value and feeds it to a function that takes a normal value but returns a monadic value. It provides a convenient notation for chaining a series of monadic computations together.



More information about the Beginners mailing list