Monads and Maybe
Jon Cast
jcast@cate0-46.reshall.ou.edu
Thu, 21 Aug 2003 16:21:09 -0500
> tor 2003-08-21 klockan 22.26 skrev Jon Cast:
> > Yes. Many complicated proposals have been made, but there's a
> > straightforward, general mechanism:
> >
> > > addMaybe :: Num alpha => Maybe alpha -> Maybe alpha -> Maybe alpha
> > > addMaybe a b = a >>= \x ->
> > > b >>= \y ->
> > > return (x + y)
> >
> > or
> >
> > > addMaybe a b = do
> > > x <- a
> > > y <- b
> > > return (x + y)
>
> or
>
> addMaybe = Monad.liftM2 (+)
>
> I personally use those monadic lifting functions a lot. Monad.sequence
> combined with list comprehension is another favorite.
So do I. But that style doesn't work as well with functions that are
already in the monad. So, I mentioned the more general style.
Jon Cast