And by &quot;works&quot;, I mean, ListT is is a monad only if the internal monad is commutative.<br><br><div class="gmail_quote">On Fri, Jan 28, 2011 at 2:46 PM, Daniel Peebles <span dir="ltr">&lt;<a href="mailto:pumpkingod@gmail.com">pumpkingod@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;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="h5"><br><br><div class="gmail_quote">On Fri, Jan 28, 2011 at 2:41 PM, Chris Smith <span dir="ltr">&lt;<a href="mailto:cdsmith@gmail.com" target="_blank">cdsmith@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;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.  Your first example<br>
had a do block for the IO monad.  Your third example used the [] monad.<br>
Both are fine.<br>
<br>
The second, though, wasn&#39;t clear on what monad it was using.  When you<br>
used the (&lt;-) syntax to nondeterministically choose from a list, the<br>
compiler settled upon the [] monad.  But then the next line was a<br>
statement in the IO monad.  That&#39;s inconsistent, hence the error.<br>
<br>
Perhaps you wanted to build a monad out of both behaviors?  In this<br>
case, you should likely look into monad transformers, and in particular,<br>
the ListT monad transformer in the List package.  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 href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>