[Haskell-cafe] maybeToM

Stefan O'Rear stefanor at cox.net
Mon Dec 18 12:22:18 EST 2006

> > I can't see how such a generalization could look like, especially since
> > "maybe" can be used with arbitrary monad:
> >     maybe (fail "Nothing") return
> Well, that???s a possible implementation of a maybeToM. The question is:
> Is it useful enough for a name on it???s own?

I thought it was useful enough in genericserialize:

module Data.Generics.Serialization.Standard ...

-- |Convert a 'Maybe' object into any monad, using the imbedding defined by
-- fail and return.
fromMaybeM :: Monad m => String -> Maybe a -> m a
fromMaybeM st = maybe (fail st) return

More information about the Haskell-Cafe mailing list