[Haskell-cafe] pointer equality

Thiago Negri evohunz at gmail.com
Wed Jul 20 17:48:48 CEST 2011


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?

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).


E.g.,

Equivalent thunks, evaluates to True, does not need to evaluate its arguments:
    [1..] == [1..]


Another case:

fib = 1:1:zipWith (+) fib (tail fib)
fibA = 1:tail fib
fib == fibA -- True


Evaluating:

1:1:zipWith (+) fib (tail fib) == 1:tail fib -- first item match, check further
1:zipWith (+) fib (tail fib) == tail fib -- thunks do not match,
evaluate arguments
1:zipWith (+) fib (tail fib) == 1:zipWith (+) fib (tail fib) -- thunks
matches, comparison stops and the value is True


As I said before, I'm a newbie at Haskell. Sorry if my question or
examples makes no sense.

Thanks,
Thiago.



More information about the Haskell-Cafe mailing list