[Haskell-cafe] how can I select all the 3-element-combination out of a list efficiently

Jules Bean jules at jellybean.co.uk
Sun May 20 08:49:43 EDT 2007


geniusfat wrote:
> hi dear haskell lover ;)
> what I want to do is simply this:
> select3 :: [a] -> [(a, a, a)]
> and how can it be done efficiently?
> thanks in advance!


Oh, hang on. I just read your subject line. Do you really mean all the 
3-elem combinations?

that's much easier:

Prelude> let l = [1,5,9,15] in [(a,b,c) | a <- l, b <- l, c <- l]
[(1,1,1),(1,1,5),(1,1,9),(1,1,15),(1,5,1),(1,5,5),(1,5,9),(1,5,15),(1,9,1),(1,9,5),(1,9,9),(1,9,15),(1,15,1),(1,15,5),(1,15,9),(1,15,15),(5,1,1),(5,1,5),(5,1,9),(5,1,15),(5,5,1),(5,5,5),(5,5,9),(5,5,15),(5,9,1),(5,9,5),(5,9,9),(5,9,15),(5,15,1),(5,15,5),(5,15,9),(5,15,15),(9,1,1),(9,1,5),(9,1,9),(9,1,15),(9,5,1),(9,5,5),(9,5,9),(9,5,15),(9,9,1),(9,9,5),(9,9,9),(9,9,15),(9,15,1),(9,15,5),(9,15,9),(9,15,15),(15,1,1),(15,1,5),(15,1,9),(15,1,15),(15,5,1),(15,5,5),(15,5,9),(15,5,15),(15,9,1),(15,9,5),(15,9,9),(15,9,15),(15,15,1),(15,15,5),(15,15,9),(15,15,15)]


Jules



More information about the Haskell-Cafe mailing list