geniusfat <[EMAIL PROTECTED]> writes:
(snip)
> the order does not matter and each object can be chosen only once.
(snip)

In that case, with the help of Data.List.tails, one can do:

threeOf :: [a] -> [(a,a,a)]

threeOf xs =
    [ (p,q,r) | (p:ps) <- tails xs, (q:qs) <- tails ps, r <- qs ]

(the r <- qs is a simpler version of (r:rs) <- tails qs)

or maybe,

nOf :: Int -> [a] -> [[a]]

nOf _    []  = []
nOf 1    xs  = map return xs
nOf n (x:xs) = map (x:) (nOf (n-1) xs) ++ nOf n xs

(These are fairly naive versions that just took me a few minutes, but
perhaps they'll do.)

-- Mark

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

Reply via email to