On 18 dec 2006, at 18.22, Stefan O'Rear wrote:

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

I agree that this is useful. Several of my applications and libraries include this somewhere (with different names: maybeM and maybeToM). Though the RHS isn't much shorter than the LHS, unless its name is made shorter.

/Björn_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to