On 09-Jul-1999, Fermin Reig Galilea <[EMAIL PROTECTED]> wrote:
> > > Miranda has something called diagonalizing list
> > comprehensions if I recall
> > > correctly. I think you would write:
> > >
> > > [(a,b) // a <- [1..], b <-[1..]]
> > >
> > > and the resulting list would be
> > >
> > > [(1,1), (1,2), (2,1) ...]
> >
> > Haskell has this too. :) The syntax is almost the same:
> >
> > [(a,b) | a <- [1..], b <- [1..]]
>
> No, your Haskell code will evaluate to: [(1,1), (1,2), (1,3), ...].
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) | sum <- [1..], a <- [1..sum], let b = sum-a+1]
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED] | -- the last words of T. S. Garp.