Mark T.B. Carroll wrote:

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

No! With this implementation we have nOf 0 _ == [] but it should be nOf 0 _ == [[]]: The list of all sublists of length 0 is not empty, it contains the empty list!

Correct (and more natural):

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

BR,

--
-- Mirko Rahn -- Tel +49-721 608 7504 --
--- http://liinwww.ira.uka.de/~rahn/ ---
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to