[Haskell-cafe] maybeToM

Joachim Breitner mail at joachim-breitner.de
Mon Dec 18 04:29:24 EST 2006


dons mentions in his blog post that Data.Map’s lookup is generalized
over the Monads, whereas Prelude.maybe isn’t. Are there good reasons not
to do that to Prelude.maybe as well?

Alternatively, how about adding this function to Data.Maybe, analogous
to maybeToList

> maybeToM Nothing  = fail "Nothing"
> maybeToM (Just x) = return x

(Incidentially, this function is the same as maybeToList if run in the
List Monad).

This way, Prelude.lookup (or any function that returns a Maybe) can be
generalized as (maybeToM . lookup).


Joachim "nomeata" Breitner
  mail: mail at joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
  JID: joachimbreitner at amessage.de | http://www.joachim-breitner.de/
  Debian Developer: nomeata at debian.org

More information about the Haskell-Cafe mailing list