Thanks Senastian!
I would refine the equality as below:
On 05.06.2011 14:40, Haisheng Wu wrote:It doesn't. You went wrong in the last equality there. y doesn't have
By looking at sequence implementation in Hugs:
sequence (c:cs) = do x<- c
xs<- sequence cs
return (x:xs)
Apply it against a list [Just 2, Nothing], we will have:
sequence [Just 2, Nothing]
= do x<- Just 2
y<- sequence [Nothing]
return (x:y)
= return (2:Nothing)
The question is
Why/How `return (2:Nothing)` eval to `Nothing` ?
the value Nothing, in fact it never gets a value at all.
Let's first look at what sequence [Nothing] evaluates to:
do x <- NothingSince Nothing >>= f evaluates to Nothing this means that the above
y <- sequence [Nothing]
return (x:y)
do-block evaluates to Nothing, too. So y <- sequence [Nothing] becomes
y <- Nothing and again the whole expression evaluates to Nothing and
return (x:y) never is evaluated.
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners