[Haskell-cafe] elem of infinite set of tuple

Henning Thielemann lemming at henning-thielemann.de
Fri May 16 09:23:30 EDT 2008


On Fri, 16 May 2008, David Roundy wrote:

> On Fri, May 16, 2008 at 07:58:40AM -0400, Dan Doel wrote:
>> On Friday 16 May 2008, leledumbo wrote:
>>> 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..] ]
>>
>> FYI: The control-monad-omega package on hackage.haskell.org can handle this
>> sort of thing (liberties taken with ghci formatting):
>>
>> Prelude> :m + Control.Monad.Omega
>> Prelude Control.Monad.Omega>
>>   (1,1) `elem` runOmega (do x <- each [0..] ; y <- each [0..] ; return (x,y))
>> True
>> Prelude Control.Monad.Omega>
>>
>> It does breadth-first instead of depth-first search.
>
> You could also just use [ (b,a-b) | a <- [0..], b <- [0..a]]

I wonder whether Georg Cantor could imagine that his diagonalization 
method would be practically applied some day.

   http://de.wikipedia.org/wiki/Cantor-Diagonalisierung


More information about the Haskell-Cafe mailing list