On Sat, Oct 31, 2009 at 8:38 AM, David Menendez <span dir="ltr"><<a href="mailto:dave@zednenem.com">dave@zednenem.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Sat, Oct 31, 2009 at 6:22 AM, Heinrich Apfelmus<br>
<<a href="mailto:apfelmus@quantentunnel.de">apfelmus@quantentunnel.de</a>> wrote:<br>
> The only possible monad instance would be<br>
><br>
> return x = Const mempty<br>
> fmap f (Const b) = Const b<br>
> join (Const b) = Const b<br>
><br>
> but that's not just () turned into a monad.<br>
<br>
</div>This is inconsistent with the Applicative instance given above.<br>
<br>
Const a <*> Const b = Const (a `mappend` b)<br>
<br>
Const a `ap` Const b = Const a<br>
<br>
In other words, Const has at least two Applicative instances, one of<br>
which is not also a monad.<br></blockquote><br>But this "Monad" instance isn't a monad either:<br><br>f True = Const [1]<br>f False = Const [2]<br><br>return True >>= f<br>{- by monad laws -}<br>= f True<br>
= Const [1]<br><br>but by this code<br><br>return True >>= f<br>{- apply return, monoid [a] -}<br>= Const [] >>= f<br></div>{- definition of >>= -}<br>= join (fmap f (Const []))<br>{- apply join and fmap -}<br>
= Const []<br><br>