Std lib equivalent for liftM concat . sequence

A couple of days ago I had need for:
concatM :: Monad m => [m [a]] -> m [a] concatM = liftM concat . sequence
but found no such thing in the std libs, except perhaps for msum (I don't want to add instances for MonadPlus. Should I have to?). Have I missed something trivial? Alistair

Hello Alistair, Friday, May 16, 2008, 2:12:45 PM, you wrote:
concatM = liftM concat . sequence
but found no such thing in the std libs, except perhaps for msum (I don't want to add instances for MonadPlus. Should I have to?). Have I missed something trivial?
1. it's easy to define yourself 2. it's not widely used. at least, i have in my program for, foreach, concatMapM, filterM and lot of other monadic operations, but no one concatM -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Alistair Bayley wrote:
A couple of days ago I had need for: concatM :: Monad m => [m [a]] -> m [a] concatM = liftM concat . sequence but found no such thing in the std libs
It used to be in an older version of Haskell, but it was removed in Haskell 98. Bulat Ziganshin wrote:
2. it's not widely used.
Bulat is justifiably concerned about backwards compatibility issues when changing the core standard libraries, including when adding new functions. Despite Bulat's best efforts, there has been a trend lately of adding those kinds of things. If so, nowadays it can be made more general. In this case, you could at least generalize it to: concatM :: (Monad m, Traversable t, Foldable t, MonadPlus p) => t (m (p a)) -> m (p a) or concatA :: (Applicative f, Traversable t, Foldable t, MonadPlus p) => t (f (p a)) -> f (p a) I'm sure someone can do better than that. :) Regards, Yitz

Seems to be close to sequence :: [ListT m a] -> ListT m a Hmm? On 16 May 2008, at 14:12, Alistair Bayley wrote:
A couple of days ago I had need for:
concatM :: Monad m => [m [a]] -> m [a] concatM = liftM concat . sequence
but found no such thing in the std libs, except perhaps for msum (I don't want to add instances for MonadPlus. Should I have to?). Have I missed something trivial?
Alistair _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Oops, I was very wrong. Sorry. On 16 May 2008, at 20:13, Miguel Mitrofanov wrote:
Seems to be close to
sequence :: [ListT m a] -> ListT m a
Hmm?
On 16 May 2008, at 14:12, Alistair Bayley wrote:
A couple of days ago I had need for:
concatM :: Monad m => [m [a]] -> m [a] concatM = liftM concat . sequence
but found no such thing in the std libs, except perhaps for msum (I don't want to add instances for MonadPlus. Should I have to?). Have I missed something trivial?
Alistair _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Alistair Bayley wrote:
concatM :: Monad m => [m [a]] -> m [a] concatM = liftM concat . sequence
Miguel Mitrofanov wrote:
Seems to be close to sequence :: [ListT m a] -> ListT m a Hmm?
Yes. It is close to something like that for the old broken ListT - but let's not talk about that one. For "ListT done right", how about: concatM :: Monad m => [ListT m a] -> List m a concatM = join . liftList (http://www.haskell.org/haskellwiki/ListT_done_right) Regards, Yitz
participants (4)
-
Alistair Bayley
-
Bulat Ziganshin
-
Miguel Mitrofanov
-
Yitzchak Gale