[Haskell-cafe] Re: [Haskell] ANN: random-access-list-0.1
Jules Bean
jules at jellybean.co.uk
Fri Jun 13 09:33:00 EDT 2008
> 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
More information about the Haskell-Cafe
mailing list