[Haskell-cafe] Pulling a monad out of a functor

Bryan Burgers bryan.burgers at gmail.com
Mon Mar 5 23:12:44 EST 2007


Recently, I have come across a couple of situations in which I need to
"pull a monad out of a functor" so to speak. The first time it was
needed, I didn't think much of it, but the second time started me
thinking whether there is already an existing construct for this. The
type signatures I have in mind are:

pull :: (Monad m, Functor f) => f (m a) -> m (f a)
fmapM :: (Monad m, Functor f) => (a -> m b) -> f a -> m (f b)
fmapM f = pull . fmap f

You may notice that these are already defined for the List functor as
'sequence' and 'mapM'. It seems to me that if this were a class, the
implementor would be defining a traversing order by defining pull; in
the list case this traversing sequence is clearly defined as head to

I am wondering if there is already a construct for this that I am not
aware of (a class, a way to defined it using monads and functors that
I am not aware of, an idiom)? Is this something that frequently
happens for others, or is it a sign a few of my designs have been
flawed recently?


More information about the Haskell-Cafe mailing list