Take the 2-minute tour ×

If I have a list of lists, say [[1,2,3],[1,2,3],[1,2,3]], is there any way in Haskell to turn this into just 1 list, like [1,2,3,1,2,3,1,2,3]?

Thanks in advance!

share|improve this question
add comment

3 Answers

up vote 13 down vote accepted

Concat does what you'd like:

concat [[1,2,3],[1,2,3],[1,2,3]]

To find these sorts of functions in the future, you can use hoogle http://www.haskell.org/hoogle/

You can search for a type - your required function is [[Int]] -> [Int], so you could do this search. The top function is concat.

I should mention that in fact


So it works on any list of lists, and you could also quite happily search hoogle with that type instead. Hoogle's smart enough to understand which types are appropriately close to what you asked for, though.

share|improve this answer
Cool! Thanks for the tip! :) –  user1670032 Oct 8 '12 at 19:57
add comment

There are some ways to do it, you can use list comprehensions, for example:

[y | x <- [[1,2,3],[1,2,3],[1,2,3]], y <- x]

or join function, that, actually, same way:

import Control.Monad (join)
join [[1,2,3],[1,2,3],[1,2,3]]

or concat function:


or msum (same with concat):

import Control.Monad (msum)
msum [[1,2,3],[1,2,3],[1,2,3]]

or mconcat (same with concat):

import Data.Monoid (mconcat)
mconcat [[1,2,3],[1,2,3],[1,2,3]]
share|improve this answer
Thanks! This is really useful to see the different ways you can do one thing! :) –  user1670032 Oct 8 '12 at 19:59
add comment

Direct Answer

> concat [[1,2,3],[1,2,3],[1,2,3]]

You should try hoogle whenever you want to search for any function. Sometimes type is enough to get information about a function you need.

share|improve this answer
Exactly what I was looking for! Thanks! :) –  user1670032 Oct 8 '12 at 19:56
add comment

Your Answer


