[Haskell-cafe] Combinations

Mirko Rahn rahn at ira.uka.de
Tue Jun 6 09:12:11 EDT 2006


Henning Thielemann wrote:

 > combinations = foldr (Monad.liftM2 (:)) [[]]

Lennart Augustsson wrote:

> combinations [] = [[]]
> combinations (xs:xss) = liftM2 (:) xs (combinations xss)

List comprehension is faster when compiled with ghc-6.4.2 -O:

combinations [] = [[]]
combinations (xs:xss) = [ x:y | x <- xs, y <- combinations xss ]

BTW, I think 'cross_many' would be a better name.

-- 
-- Mirko Rahn -- Tel +49-721 608 7504 --
--- http://liinwww.ira.uka.de/~rahn/ ---


More information about the Haskell-Cafe mailing list