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

> On Sat, Oct 31, 2009 at 6:22 AM, Heinrich Apfelmus
> <apfel...@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 []
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to