Fergus Henderson wrote:
| Yes, the correct Haskell syntax for this is somewhat different.
| You can use
|
| [(a, b-a) | b <- [1..], a <- [1..b-1]]
Or:
[ (a,b) | (a,b) <- [1..] // [1..] ]
For a suitable definition of (//), for example:
(//) :: [a] -> [b] -> [(a,b)]
xs // ys = diagonalize 1 [[(x,y) | x <- xs] | y <- ys]
where
diagonalize n xss =
xs ++ diagonalize (n+1) (xss1 ++ xss2)
where
(xs,xss1) = unzip [ (x,xs) | (x:xs) <- take n xss ]
xss2 = drop n xss
And it works for any type.
This corresponds nicely with Clean's zip-comprehensions, which are denoted
by:
[ a+b | a <- [1..] & b <- [1..] ]
(this evaluates to: [ 2, 4, 6, ..]
You can write this in haskell as:
[ a+b | (a,b) <- [1..] & [1..] ]
For a suitable definition of (&), for example:
(&) = zip
Regards,
Koen.
--
Koen Claessen http://www.cs.chalmers.se/~koen
phone:+46-31-772 5424 e-mail:[EMAIL PROTECTED]
-----------------------------------------------------
Chalmers University of Technology, Gothenburg, Sweden