[Haskell-cafe] Re: Monads and Functions sequence and sequence_

Sebastian Fischer fischer at nii.ac.jp
Sat Oct 30 01:42:47 EDT 2010


On Oct 30, 2010, at 2:30 PM, Mark Spezzano wrote:

> If you use the type with Maybe Int like so:
>
> sequence [Just 1, Nothing, Just 2]
>
> then the result is Nothing.
>
> Whereas sequence [Just 1, Just 2, Just 3] gives
>
> Just [1, 2, 3]

Try

     do x <- Just 1
        y <- Nothing
        z <- Just 2
        return [x,y,z]

and

     do x <- Just 1
        y <- Just 2
        z <- Just 3
        return [x,y,z]

The results are the same as with your calls of `sequence`. It is  >>=   
which makes the difference, not `sequence`.

Sebastian


More information about the Haskell-Cafe mailing list