Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: Polymorphic comparison
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <xleroy@p...>
Subject: Re: Polymorphic comparison
Yes, I have been thinking for a while about generalizing the
generic equality function to a generic ordering function (with three
possible results: "equal", "less than", "greater than").

It's a simple extension of the code for generic equality (order base
types as usual and use a lexicographic extension for data structures)
--- no more of a hack than generic equality itself.

Usefulness: canonical representatives (as John Harrison mentioned),
ordered binary trees such as those implementing sets and maps (but the
problem remains to attach user-defined orderings to some types), and a
unified notation for comparisons over integers, floats, strings and
characters.

There are a few difficulties in the implementation that remain to iron out
(what to do with pointers outside the heap which may point to
well-formed objects, in which case a recursive descent is needed,
but may also point to foreign objects, in which case comparison should
fail), so I can't promise this will be in the next release, but I'll
give it a try.

- Xavier Leroy