My question is about the sequence
function in Prelude
, the signature of which is as follows:
sequence :: Monad m => [m a] ->
Just to explain, why the application of sequence to a list of lists is so different from the application of sequence to a list of Maybe-values:
When you apply sequence
to a list of lists, then the type of sequence is specialized from
sequence :: Monad m => [m a] -> m [a]
to (with the type constructor m set to [])
sequence :: [[] a] -> [] [a]
(which is the same as sequence :: [[a]] -> [[a]]
)
internally, sequence uses (>>=) -- i.e. the monadic bind function. For lists this bind function is implemented completly different than for m set to Maybe!