[Haskell-beginners] Maybe, Either

Yusaku Hashimoto nonowarn at gmail.com
Tue Sep 15 02:14:28 EDT 2009


I prefer Alternative to MonadPlus for explaining failure. It has
better name and operator for failure and try-another.

import Control.Applicative

aLookup :: (Alternative f, Eq k) => k -> [(k,v)] -> f v
aLookup key pairs = maybe empty pure $ lookup key pairs

-nwn
On Tue, Sep 15, 2009 at 12:21 PM, Brandon S. Allbery KF8NH
<allbery at ece.cmu.edu> wrote:
> On Sep 14, 2009, at 14:42 , Michael Snoyman wrote:
>
> I understand that fail being in Monad is controversial, but my version of
> the function works in *all* monads. This is very
>
> Not really; "fail" in non-MonadPlus-es is a rather poorly defined notion,
> and there are no guarantees that the result will be at all sane.  "mzero" is
> well defined.
> --
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
> system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
> electrical and computer engineering, carnegie mellon university    KF8NH
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>


More information about the Beginners mailing list