[Haskell-cafe] pointer equality
evohunz at gmail.com
Wed Jul 20 17:48:48 CEST 2011
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).
Equivalent thunks, evaluates to True, does not need to evaluate its arguments:
[1..] == [1..]
fib = 1:1:zipWith (+) fib (tail fib)
fibA = 1:tail fib
fib == fibA -- True
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,
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.
More information about the Haskell-Cafe