Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] equality over functional value
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <frisch@c...>
Subject: Re: [Caml-list] equality over functional value
On Mon, 23 Apr 2001, Xavier Leroy wrote:

> More generally, equality between functions can be interpreted in
> several ways:
>...
> 3- By representation: two functions are equal iff their closures are
> structurally equal, i.e. they have the same code pointer and contain
> equal values in their environment.
> 
> Interpretation 3- is useless I think, because it depends very much on
> the compiler's closure representation strategy.  In other terms, while
> a "true" result guarantees that the two functions are extensionally
> equal, a "false" result does not mean anything.

For equality testing, this comparison doesn't make much sense. But it may
be useful because it defines a total (quasi-)ordering on functional values
whose associated equivalence is: 

- coarser than physical equality 

- finer than observational equivalence

It is probably bad style to rely heavily on such an ordering, but it is
sometimes annoying not to be able to use generic comparison function when
you have functional types somewhere in your complex data structures.
Even if you associate a "stamp" to functional values, you can't use
generic comparisons.


Having said that, being able to define custom operation for Caml values
seems much more important and general to me. The interface may be
something like:

type 'a t
type 'a operations = { compare: 'a -> 'a -> int ; hash : 'a -> int ; ... }
val wrap : 'a operations -> 'a -> 'a t
val extract : 'a t -> 'a


-- 
  Alain Frisch

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr