One way to think of Maybe in a monad is to interpret Maybe T as a
possible missing value of type T.  Given a function f, the result is
missing if any argument is missing.  

It's pretty easy to make use of this using the lift functions in the
monad library:

Monad> liftM2 (+) (Just 1) (Just 2)
liftM2 (+) (Just 1) (Just 2)
Just 3
Monad> liftM2 (++) (Just "Hello") Nothing
liftM2 (++) (Just "Hello") Nothing
Nothing
Monad> liftM2 (++) (Just "Hello") (Just "World")
liftM2 (++) (Just "Hello") (Just "World")
Just "HelloWorld"

I find that I use the Maybe monad fairly often in this manner.

  John



Reply via email to