[Haskell-cafe] How to check object's identity?

Lauri Alanko la at iki.fi
Sun Jan 4 05:12:11 EST 2009


On Sun, Jan 04, 2009 at 04:19:38PM +0800, Evan Laforge wrote:
> If you don't have set-car!, then identity and equality are impossible
> to differentiate.

There's still eqv?. (I wish people wouldn't use eq? as an example of
an identity-comparison operation. It's as underdefined as
unsafePtrEq.)

So although state implies identity, the converse is not true. You can
also have immutable objects with distinct identities.

Some dialects of Scheme have recently started leaning towards making
pairs immutable, but whether they should also make them
indistinguishable is a separate question:

http://groups.google.com/group/comp.lang.scheme/browse_thread/thread/7eccba9fb4eebb44

And having a limited form of observable identity has even been
proposed for Haskell:

http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.4053

Personally, I find the idea appealing (and have implemented the Refs
in the paper with IORefs and unsafePerformIO), because really, even
currently a programmer has to care about sharing since it can have
radical implications for performance and memory usage. Making it
observable in the program would just mean acknowledging the fact that
in real-world programming, you can't _really_ replace a variable with
its definition without changing its behavior in important ways.


Lauri


More information about the Haskell-Cafe mailing list