[Haskell-beginners] Sequence function

Jimbo jimbo4350 at gmail.com
Tue Sep 26 16:59:05 UTC 2017


Hello everyone,

Just trying to understand the sequence function as follows:

sequence [Just 1]

-- evaluates to Just [1]

sequence = foldr mcons (return [])
     where mcons p q = p >>= \x -> q >>= \y -> return (x:y)

-- I'm trying to walk through the code as follows, I understand what is 
below isn't
-- haskell code

p >>= \x ->              []
q >>= \y ->        Just 1
return (x:y)    --  [] : Just 1

Am I thinking of sequence correctly here?

Best regards,

Jim



More information about the Beginners mailing list