Browse thread
Physical counterpart to Pervasives.compare?
-
Elnatan Reisner
-
Edgar Friendly
- Edgar Friendly
- Alain Frisch
-
Edgar Friendly
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Edgar Friendly <thelema314@g...> |
| Subject: | Re: [Caml-list] Physical counterpart to Pervasives.compare? |
Edgar Friendly wrote: > Elnatan Reisner wrote: >> I'm afraid of getting into trouble with Obj.magic, but what would this do: >> let f (x:'a) (y:'a) = compare (Obj.magic x) (Obj.magic y) >> ? Or would annotations make any difference: >> let f (x:'a) (y:'a) = compare (Obj.magic x : int) (Obj.magic y : int) >> >> -Elnatan > > Nope, Obj.magic and casting only have compile-time effects, the code > given compiles exactly the same as [let f x y = compare x y]. > It looks like I'm wrong on this - there's versions of compare specialized for floats, strings and ints. Maybe you *could* trigger the use of the caml_int_compare by this kind of type system manipulation. It looks quite safe to use on non-ints. Testing on your platform is possible, by trying to find store pointers to ints, so that caml_compare compares the ints, but the tricked caml_int_compare compares the pointers, and gets a different result. E