[Haskell-cafe] Combination-lock problem

Florian Boehl flo at namespacepollution.net
Thu Aug 12 00:21:15 EDT 2004


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


More information about the Haskell-Cafe mailing list