[Haskell-cafe] Combinations

Lennart Augustsson lennart at augustsson.net
Tue Jun 6 08:23:27 EDT 2006


Sounds like cartesian product to me.
So you could try
combinations [] = [[]]
combinations (xs:xss) = liftM2 (:) xs (combinations xss)

	-- Lennart

developer at imaginando.net wrote:
> Hi,
> 
> I need a functions which takes as argument a list of lists like this one:
> 
> [[1,2],[3],[4]]
> 
> and gives me a list of list with all the possible combinations like this one:
> 
> [[1,3,4],[2,3,4]]
> 
> In this case there are only 2 combinations but if there was more than one
> element in the other lists the results were much more.
> 
> I'm a little stuck in this simple problem.
> 
> First i was thinking in cartesian product but then i realized that i may
> not be what i really need.
> 
> Any tip?
> 
> Many thx,
> 
> Nuno Santos
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 



More information about the Haskell-Cafe mailing list