Chris.Bitmead@alcatel.com.au (Chris Bitmead uid(x22068)) writes:
> email@example.com (Andrew Koenig) writes:
> > > In the tree example that you started with, what is wrong with just
> > > passing round the whole subtree so that it can be compared with as
> > > necessary? Any reasonable implementation will only be passing round a
> > > pointer so you lose nothing.
> > Because it will compare equal with any other subtree that happens to
> > have the same structure, which is not what I want.
> So all you have to do is generate a unique name for each node, right?
> Just an incremental number perhaps.
All languages are equivalent, so there is certainly a way to encode
any language in another. But this is not the point here. The point is
that physically those trees are represented by pointers, and the
question is whether you should be able to access this pointer in some
way or not. In terms of efficiency, there is a difference.
Remark that being able to acceed a pointer is not anecdotical. For
instance, being able to compare physically pointers with < or > means
restrictions on the garbage collector, that should keep these
inequalities when moving values around. Most GC's don't. C's pointer
arithmetic is even worse. On the other hand, GC's do keep pointer
identity. So being able to compare pointers for == and != should not
be so harmful. This is a constraint for the language: pointer identity
should be defined in some way, and some abstract operations might
It seems that SML chose not to allow pointer comparisons (you have to
explicitely buld a ref), while CAML does allow them (== and != do
compare pointers, not values, those being compared with = and
<>). This may be seen as a question of taste. I prefer the last one,
since anyway ML is a strict language, and all implementations that I
know of do satisfy the requisite to make it meaningful. But people may
prefer to be forced to write thing in a functional way, and not be
implementation dependent. By the way, since most implementations of
SML do allow you to make unsafe casts, you can perfectly convert your
trees to integers, and then compare them!
Finally, all this is a problem of how far a language is specified. C
is specified to such a level that you cannot touch anything without
observable change. Abstractly specified language allow potentially a
lot to the implementation, but this is rarely used. In the middle,
languages like Lisp, Scheme and CAML, allow almost anything to the
user, while defining what is unsafe, to give more power to the
Also, do not criticize a paradigm based on properties of a
language. This is only an instance of this paradigm, and other
instances may have other properties. Finally, you choose your language
based on the paradigm and the properties you like to have.
Jacques Garrigue Kyoto University firstname.lastname@example.org