<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">So, my suspicions are confirmed.<br><br>Thanks, all.<br><br>Michael<br><br>--- On <b>Fri, 1/28/11, Daniel Peebles <i>&lt;pumpkingod@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Daniel Peebles &lt;pumpkingod@gmail.com&gt;<br>Subject: Re: [Haskell-cafe] Merry monad mixup?<br>To: "Chris Smith" &lt;cdsmith@gmail.com&gt;<br>Cc: "michael rice" &lt;nowgate@yahoo.com&gt;, "haskell cafe" &lt;haskell-cafe@haskell.org&gt;<br>Date: Friday, January 28, 2011, 2:47 PM<br><br><div id="yiv427223477">And by "works", I mean, ListT is is a monad only if the internal monad is commutative.<br><br><div class="yiv427223477gmail_quote">On Fri, Jan 28, 2011 at 2:46 PM, Daniel Peebles <span dir="ltr">&lt;<a rel="nofollow" ymailto="mailto:pumpkingod@gmail.com" target="_blank"
 href="/mc/compose?to=pumpkingod@gmail.com">pumpkingod@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="yiv427223477gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Beware of ListT. It only works if your internal monad is commutative, which IO is not. (Maybe would work, for example)<div>
<div></div><div class="yiv427223477h5"><br><br><div class="yiv427223477gmail_quote">On Fri, Jan 28, 2011 at 2:41 PM, Chris Smith <span dir="ltr">&lt;<a rel="nofollow" ymailto="mailto:cdsmith@gmail.com" target="_blank" href="/mc/compose?to=cdsmith@gmail.com">cdsmith@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="yiv427223477gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div>On Fri, 2011-01-28 at 11:20 -0800, michael rice wrote:<br>
&gt; The first and third work, but not the second. Why?<br>
<br>
</div>When you use a do block, it can be the syntactic sugar for whatever<br>
monad you like; but you do have to make a choice. &nbsp;Your first example<br>
had a do block for the IO monad. &nbsp;Your third example used the [] monad.<br>
Both are fine.<br>
<br>
The second, though, wasn't clear on what monad it was using. &nbsp;When you<br>
used the (&lt;-) syntax to nondeterministically choose from a list, the<br>
compiler settled upon the [] monad. &nbsp;But then the next line was a<br>
statement in the IO monad. &nbsp;That's inconsistent, hence the error.<br>
<br>
Perhaps you wanted to build a monad out of both behaviors? &nbsp;In this<br>
case, you should likely look into monad transformers, and in particular,<br>
the ListT monad transformer in the List package. &nbsp;This would allow you<br>
to write the code you did in a monad called ListT IO, except that the IO<br>
actions would need to be lifted through the use of either `lift` or<br>
`liftIO`.<br>
<br>
--<br>
<font color="#888888">Chris Smith<br>
</font><div><div></div><div><br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a rel="nofollow" ymailto="mailto:Haskell-Cafe@haskell.org" target="_blank" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a rel="nofollow" target="_blank" href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>
</div></blockquote></td></tr></table><br>