
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
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@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners