That is a result of the implementation of the specific Monad instance, and that does depend on the type, as you say (but it isn&#39;t determined for sequence(_) specifically).<div><br></div><div>Nothing &gt;&gt;= f = Nothing</div>
<div>Just x &gt;&gt;= f = f x </div><div><br></div><div>is why a Nothing &quot;pollutes&quot; the sequenced lists of Maybes. If Maybe is a Monad representing computations that can fail (to produce a result), then if you sequence a bunch of such computations together, if any one computation fails, your entire computation fails. This reflects the natural behavior of the Maybe monad, where if you use &quot;x &lt;- maybe computation&quot;, the only way to produce that x is if the computation returned Just.</div>
<div><br></div><div>In other monads, sequence will behave in the &quot;right way&quot; for that monad.<br><br><div class="gmail_quote">On Sat, Oct 30, 2010 at 1:30 AM, Mark Spezzano <span dir="ltr">&lt;<a href="mailto:mark.spezzano@chariot.net.au">mark.spezzano@chariot.net.au</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Not exactly. If you use the type with Maybe Int like so:<br>
<br>
sequence [Just 1, Nothing, Just 2]<br>
<br>
then the result is Nothing.<br>
<br>
Whereas sequence [Just 1, Just 2, Just 3] gives<br>
<br>
Just [1, 2, 3]<br>
<br>
Why?<br>
<br>
I assume there&#39;s special implementations of sequence and sequence_ depending on the type of monad used. If it&#39;s a sequence_ [putStrLn &quot;hello&quot;, putStrLn &quot;goodbye&quot;] then this prints out hello and goodbye on separate lines.<br>

<br>
It seems to work differently for different types.<br>
<font color="#888888"><br>
Mark<br>
</font><div><div></div><div class="h5"><br>
<br>
On 30/10/2010, at 3:42 PM, Bardur Arantsson wrote:<br>
<br>
&gt; On 2010-10-30 07:07, Mark Spezzano wrote:<br>
&gt;&gt; Hi,<br>
&gt;&gt;<br>
&gt;&gt; Can somebody please explain exactly how the monad functions &quot;sequence&quot; and &quot;sequence_&quot; are meant to work?<br>
&gt;&gt;<br>
&gt;&gt; I have almost every Haskell textbook, but there&#39;s surprisingly little information in them about the two functions.<br>
&gt;&gt;<br>
&gt;&gt; From what I can gather, &quot;sequence&quot; and &quot;sequence_&quot; behave differently depending on the types of the Monads that they are processing. Is this correct? Some concrete examples would be really helpful.<br>

&gt;&gt;<br>
&gt;<br>
&gt; sequence [m1,m2,m3,m4,...] = do<br>
&gt;  x1 &lt;- m1<br>
&gt;  x2 &lt;- m2<br>
&gt;  x3 &lt;- m3<br>
&gt;  x4 &lt;- m4<br>
&gt;  ...<br>
&gt;  return [x1,x2,x3,x4,...]<br>
&gt;<br>
&gt; sequence_ [m1,m2,m3,m4,...] = do<br>
&gt;  m1<br>
&gt;  m2<br>
&gt;  m3<br>
&gt;  m4<br>
&gt;  ...<br>
&gt;  return ()<br>
&gt;<br>
&gt; Cheers,<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Haskell-Cafe mailing list<br>
&gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;<br>
&gt;<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">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>