Understanding Monads Via Python List Comprehensions « All Unkept - 0 views
-
But here we have taken it to a higher level -- the Monad interface is like an abstraction of any kind of container.
-
This in turn leads to the concept that a monadic value represents a computation -- a method for computing a value, bound together with its input value.
-
Writing monads is hard, but it pays off as using them in Haskell is surprisingly easy, and allows you to do some very powerful things.
- ...3 more annotations...
-
One of them you have seen explicitly -- it's the 'return' method, responsible for packing things up into the monad. The other is called 'bind' or '>>=', and it does the 'unpacking' involved with the <- arrow in the do notation.
-
the 'bind' method doesn't really unpack and return the data. Instead, it is defined in such a way that it handles all unpacking 'internally', and you have to provide functions that always have to return data inside the monad.
-
It looks very much like 'unpack this data from the monad so I can use it', so it helps conceptually. In fact, together with the rest of the body of the 'do' block it forms an anonymous lambda function,