Thanks Senastian!<br><br>I would refine the equality as below:<br><br><div><font face="'courier new', monospace"> sequence [Just 2, Nothing]</font></div><div><font face="'courier new', monospace">= do x <- Just 2</font></div>
<div><font face="'courier new', monospace"> y <- sequence [Nothing]</font></div><div><font face="'courier new', monospace"> return (x:y)</font></div>
<div><font face="'courier new', monospace">= Just 2 >>= \x -> sequence [Nothing] >>= \y -> return (x:y)<br>= Nothing >>= </font><font face="'courier new', monospace">\y -> return (2:y)</font><br>
<span style="font-family: courier new,monospace;">= Nothing</span><br><font face="'courier new', monospace"><br></font></div><br clear="all">-Haisheng<br>
<br><br><div class="gmail_quote">On Mon, Jun 6, 2011 at 12:31 AM, Sebastian Hungerecker <span dir="ltr"><<a href="mailto:sepp2k@googlemail.com">sepp2k@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 05.06.2011 14:40, Haisheng Wu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
By looking at sequence implementation in Hugs:<br>
<br>
sequence (c:cs) = do x<- c<br>
xs<- sequence cs<br>
return (x:xs)<br>
<br>
Apply it against a list [Just 2, Nothing], we will have:<br>
sequence [Just 2, Nothing]<br>
= do x<- Just 2<br>
y<- sequence [Nothing]<br>
return (x:y)<br>
= return (2:Nothing)<br>
<br>
The question is<br>
Why/How `return (2:Nothing)` eval to `Nothing` ?<br>
<br>
</blockquote>
<br></div>
It doesn't. You went wrong in the last equality there. y doesn't have<br>
the value Nothing, in fact it never gets a value at all.<br>
Let's first look at what sequence [Nothing] evaluates to:<br>
<br>
do x <- Nothing<div class="im"><br>
y <- sequence [Nothing]<br>
return (x:y)<br>
<br></div>
Since Nothing >>= f evaluates to Nothing this means that the above<br>
do-block evaluates to Nothing, too. So y <- sequence [Nothing] becomes<br>
y <- Nothing and again the whole expression evaluates to Nothing and<br>
return (x:y) never is evaluated.<div><div></div><div class="h5"><br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br>