Whether fail should be in Monad, or whether we really want MonadZero,
MonadPlus, MonadError, or something else entirely has been open for
discussion, but it is easily shown
that Maybe is not the most general abstraction - it loses information
wrt to (Either String), for instance:
Prelude> let {f [] = fail "empty"; f [_] = fail "singleton"; f l =
Yes. But that's not what we're talking about.
We're talking about lookup and index which both have one and exactly one
failure mode : not found.
For these functions, Maybe a is both the most general and the most
precise type.
It is trivial to upgrade Maybe a by decorating it with an error should
you choose to do so:
maybe (throwError "better error message here") return
which I sometimes define as 'withError' or similar.
d <- M.lookup "foo" `withError` "Variable foo not in symbol table"
Jules
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe