Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] How can I check for the use of polymorphic equality?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: brogoff@s...
Subject: Re: [Caml-list] How can I check for the use of polymorphic equality?
Quite a conundrum, since equality wouldn't be polymorphic if it didn't work for 
all (non-functional) values!

Following that silly parenthetical comment, you could explicitly tag values with 
a functional fields. As long as they are the first field you're OK (try 
swapping the field order if you don't see what I mean). 

# type 'a no_eq = { no_eq_tag : unit -> int; data : 'a };;
type 'a no_eq = { no_eq_tag : unit -> int; data : 'a; } 
# let x0 = {data = 0; no_eq_tag = fun () -> 0};;          
val x0 : int no_eq = {no_eq_tag = <fun>; data = 0}
# let x1 = {data = 1; no_eq_tag = fun () -> 1};;
val x1 : int no_eq = {no_eq_tag = <fun>; data = 1}
# x0 = x1;;
Exception: Invalid_argument "equal: functional value".

You can use tuples isntead of records if you wish too. BTW, this tagging  
strikes me as very ugly. 

A cleaner solution IMO is be to use your own order data type patterned after 
every other FPL, type order = Less | Equal | Greater, or your own equality data 
type, to avoid this if it starts becoming a problem.

Equality is a rough edge in just about every programming language. 

-- Brian

On Mon, 31 Mar 2003, Neel Krishnaswami wrote:

> 
> I spent the last few hours tracking down a bug that was the result of
> accidentally using the polymorphic equality rather than a custom
> comparison function. Is there any way I can tell the compiler not to
> allow the use of polymorphic equality at certain types, or even just
> to raise an exception when it tries to compare values of those types?
> 
> -- 
> Neel Krishnaswami
> neelk@alum.mit.edu
> 
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> 

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners