[EMAIL PROTECTED] wrote:
Then you want "triples1" from the code below.

The idea for triples1, triples2, and triples3 is that each pickOne returns a
list of pairs.  The first element of each pair is the chosen element and the
second element of each pair is the list of choices for the next element (given
the current choice).

In the spirit of multiple implementations; another approach is to note that you're really asking for all 3-element sublists:

power [] = [[]]
power (x:xs) = power xs ++ map (x:) (power xs)

triples1' l = [ t | t <- power l, length t == 3]

(this implementation also preserves sorting)

Jules


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to