[Haskell-cafe] Short circuiting and the Maybe monad

Dan Piponi dpiponi at gmail.com
Fri May 16 18:00:28 EDT 2008

On Fri, May 16, 2008 at 12:03 PM, Andrew Coppin
<andrewcoppin at btinternet.com> wrote:

> Since a tree is a kind of container, yes, it should be a monad. [I'm still
> not really sure whether it's "useful".]

Not so much containers in general, but 'flattenable' containers. You
can flatten a list of lists to a list like this:
[[1,2,3],[4,5],[6]] -> [1,2,3,4,5,6]

Similarly you can 'flatten' some kinds of trees of trees by grafting
the contained trees directly into the containing tree.

But consider containers that always contain exactly two elements. It's
not immediately obvious how to flatten such a thing because a
container of containers will have 4 elements so at the least you'll
have to throw two elements away. In fact, you can use the Reader monad
as a fixed size container monad.

> On the other hand, Maybe is a rather odd kind of container, but a very useful monad...

Do you really find it odd? It's like many ordinary household
containers: there's room to contain one object, but it might in fact
be empty.

More information about the Haskell-Cafe mailing list