From: Edgar Friendly <thelema314@gmail.com>
To: Elnatan Reisner <elnatan@cs.umd.edu>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Physical counterpart to Pervasives.compare?
Date: Tue, 28 Jul 2009 22:58:03 -0500 [thread overview]
Message-ID: <4A6FC8CB.4010009@gmail.com> (raw)
In-Reply-To: <4A6FBCBF.4070900@gmail.com>
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
next prev parent reply other threads:[~2009-07-29 3:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-29 1:25 Elnatan Reisner
2009-07-29 3:06 ` [Caml-list] " Edgar Friendly
2009-07-29 3:58 ` Edgar Friendly [this message]
2009-07-29 6:13 ` Alain Frisch
[not found] <20090729030710.BB3C6BC5C@yquem.inria.fr>
2009-07-29 7:04 ` Pascal Cuoq
2009-08-24 7:01 ` Jean-Christophe Filliâtre
[not found] <20090824100004.6DBBDBBAF@yquem.inria.fr>
2009-08-24 12:30 ` Pascal Cuoq
2009-08-25 18:03 ` Christophe Raffalli
2009-08-26 10:25 ` Damien Doligez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A6FC8CB.4010009@gmail.com \
--to=thelema314@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=elnatan@cs.umd.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox