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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Franck.Delaplace@l...
Subject: Polymorphic comparison

>I think this polymorphic comparison is quite easy to implement in the
>following way:

>#open "hashtbl";;
>let c x y = (hash x) <= (hash y);;
>

this kind of comparison would not be  appropriate in some cases.
for example when you want to use it for sorting strings 

    c "ace" "af";;

gives

- : bool = false


by convention, we intend to have this relation "ace" <= "af" since the comparison is defined
by comparing the substrings "ac" "af"