[Haskell-cafe] [Haskell] Functor => Applicative => Monad

Maciej Piechotka uzytkownik2 at gmail.com
Wed Dec 15 18:25:30 CET 2010


On Wed, 2010-12-15 at 13:51 +0200, John Smith wrote:
> On 15/12/2010 11:39, Lennart Augustsson wrote:
> > Any refutable pattern match in do would force MonadFail (or MonadPlus if you prefer).  So
> > 1.  (MonadFail m) => a -> m a,   \ a -> return a
> > 2.  (MonadFail m) => m a,   mfail "..."
> > 3.  (MonadFail m) => Maybe a -> m a,   \ a -> case a of Nothing -> mfail "..."; Just x -> return x
> > 4.  (Monad m) => a -> b -> m a,   \ a b -> return a
> > 5.  (Monad m) => (a, b) -> m a,   \ (a, b) -> return a
> >
> > As far as type inference and desugaring goes, it seems very little would have to be changed in an implementation.
> 
> Is there a need for a MonadFail, as distinct from mzero? fail always seems to be defined as error in ordinary monads, 
> and as mzero in MonadPlus (or left at the default error).

Not all types can implement mplus to begin with even if they can have
'zero' type. For example technically Maybe breaks the laws while still
having useful fail:

(guard . even) =<< (Just 1 <|> Just 2)
(guard . even) =<< Just 1
guard (even 1)
guard False
Nothing
/=
Just ()
Nothing <|> Just ()
guard False <|> guard True
(guard (even 1)) <|> (guard (even 2))
((guard . even) =<< Just 1) <|> ((guard . even) =<< Just 2)

Regards

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101215/c6a8579e/attachment.pgp>


More information about the Haskell-Cafe mailing list