[Haskell-cafe] Generalized list-comprehension

Koji Nakahara yu- at div.club.ne.jp
Sun Feb 1 15:51:12 EST 2004


> I need to map(\x->otherFunction x) [1..], but this
> "next"-function is almost identical to what the
> built-in listcomprehension does.
> I just don't like my solution.

Sorry, I didn't read this.
You may prefer something like this to map (\x -> otherFunction x), 
though mechanical translation:

	xs = [[]]:[[ y:z | y <- [1..n], z <- x] | x <- xs]


Hope it helps,
 
Koji Nakahara

On Sun, 1 Feb 2004 15:22:01 +0900
Koji Nakahara <yu- at div.club.ne.jp> wrote:

> Hi,
> 
> Another solution:
> 
> f m n = concat $ take m $ tail xs 
>   where
>     xs = [[]]:map (\x -> concatMap (\y -> map (y:) x) [1..n]) xs
> 
> 
> f 3 4 gives your f 4.
 


More information about the Haskell-Cafe mailing list