Quoting Thiago Negri <evoh...@gmail.com>:

> Hello all,
> I'm a newbie at Haskell and I was not aware of this problem.
> So, equality comparison can run into an infinite-loop?

Yes, comparing infinite lists is a non-terminating computation. 

> My current knowledge of the language tells me that everything is
> Haskell is a thunk until it's value is really needed.
> Is it possible to implement (==) that first check these thunks before
> evaluating it? (Considering both arguments has pure types).

You're correct in your perception of thunks, however that doesn't help.
That would pretty much only be possible in the very simplest of cases.  
Consider the following:

> let a = [1..]
>     b = [1..]
> in a == b

It's a lot harder to compare independently generated thunks.  And this 
complexity is pretty much unbounded:

> foo = [10-9..]
> let b = [1..]
> in b == foo

etc..

Instead, if you know your input is unbounded, you need to decide how much of it 
it is reasonable to process, regardless of the language.

> take 10000000 [1..] == take 10000000 [1..]

-KQ


-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to