[Haskell-cafe] Re: Applicative but not Monad

Ryan Ingram ryani.spam at gmail.com
Sat Oct 31 15:26:00 EDT 2009


On Sat, Oct 31, 2009 at 8:38 AM, David Menendez <dave at zednenem.com> wrote:

> On Sat, Oct 31, 2009 at 6:22 AM, Heinrich Apfelmus
> <apfelmus at quantentunnel.de> wrote:
> > The only possible monad instance would be
> >
> >   return x = Const mempty
> >   fmap f (Const b) = Const b
> >   join (Const b)   = Const b
> >
> > but that's not just  ()  turned into a monad.
>
> This is inconsistent with the Applicative instance given above.
>
> Const a <*> Const b = Const (a `mappend` b)
>
> Const a `ap` Const b = Const a
>
> In other words, Const has at least two Applicative instances, one of
> which is not also a monad.
>

But this "Monad" instance isn't a monad either:

f True = Const [1]
f False = Const [2]

return True >>= f
{- by monad laws -}
= f True
= Const [1]

but by this code

return True >>= f
{- apply return, monoid [a] -}
= Const [] >>= f
{- definition of >>= -}
= join (fmap f (Const []))
{- apply join and fmap -}
= Const []
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091031/733d8182/attachment.html


More information about the Haskell-Cafe mailing list