[Haskell-cafe] elem of infinite set of tuple
abhay.parvate at gmail.com
Fri May 16 07:49:53 EDT 2008
It's not exactly a question of Haskell's behaviour. The list [ (a,b) | a <-
[0..], b <- [0..] ]
is such that apart from pairs starting with zero, no other pair is
associated with a finite index. In other words, [ (a,b) | a <- [0..], b <-
[0..] ] is not a correct 'enumeration' of all pairs of nonnegative integers.
You need to reorder them if you need a finite index associated with every
On Fri, May 16, 2008 at 5:12 PM, leledumbo <leledumbo_cool at yahoo.co.id>
> I don't know how Haskell should behave on this. Consider this function:
> elemOf (x,y) = (x,y) `elem` [ (a,b) | a <- [0..], b <- [0..] ]
> If I try to query elemOf (1,1), the program keeps searching and searching
> but it never makes it. But if I query elemOf (0,1) (or anything as long as
> the first element is 0), it can find it easily. I wonder how it's handled.
> >From my point of view, instead of starting from (1,0), the program starts
> from (0,0), which will never finish since the limit of the second element
> View this message in context:
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe