On Sat, Oct 31, 2009 at 8:38 AM, David Menendez <span dir="ltr">&lt;<a href="mailto:dave@zednenem.com">dave@zednenem.com</a>&gt;</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>
&lt;<a href="mailto:apfelmus@quantentunnel.de">apfelmus@quantentunnel.de</a>&gt; wrote:<br>
&gt; The only possible monad instance would be<br>
&gt;<br>
&gt;   return x = Const mempty<br>
&gt;   fmap f (Const b) = Const b<br>
&gt;   join (Const b)   = Const b<br>
&gt;<br>
&gt; but that&#39;s not just  ()  turned into a monad.<br>
<br>
</div>This is inconsistent with the Applicative instance given above.<br>
<br>
Const a &lt;*&gt; 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 &quot;Monad&quot; instance isn&#39;t a monad either:<br><br>f True = Const [1]<br>f False = Const [2]<br><br>return True &gt;&gt;= f<br>{- by monad laws -}<br>= f True<br>
= Const [1]<br><br>but by this code<br><br>return True &gt;&gt;= f<br>{- apply return, monoid [a] -}<br>= Const [] &gt;&gt;= f<br></div>{- definition of &gt;&gt;= -}<br>= join (fmap f (Const []))<br>{- apply join and fmap -}<br>
= Const []<br><br>