
12 Aug
2004
12 Aug
'04
12:21 a.m.
Hi Cale, On Wed, Aug 11, 2004 at 02:38:51PM -0400, Cale Gibbard wrote:
I would write it as one of the following, ---- keys [] = [[]] keys (x:xs) = [0..x] >>= (\k -> map (k:) (keys xs)) -- or, keys' [] = [[]] keys' (x:xs) = do { k <- [0..x] ; map (k:) (keys' xs) } -- or, keys'' [] = [[]] keys'' (x:xs) = concat [map (k:) (keys'' xs) | k <- [0..x]] -- or, keys''' [] = [[]] keys''' (x:xs) = concat (map (\k -> map (k:) (keys''' xs)) [0..x]) ---- Thanks for your detailed reply. I chose the third function, because I understood it immediatly (and it's shorter than the fourth ;) ). Unfortunately I'm not really common to monads yet (but willing to learn of course).
Bye Flo