From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.1 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 43D56BC37 for ; Wed, 29 Jul 2009 05:58:26 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvgBAGtlb0rRVcbmkGdsb2JhbACZSj8BAQEBCQkMBxMDqSSBH5AWAQMCBIQMBYlo X-IronPort-AV: E=Sophos;i="4.43,286,1246831200"; d="scan'208";a="30514232" Received: from rv-out-0506.google.com ([209.85.198.230]) by mail2-smtp-roc.national.inria.fr with ESMTP; 29 Jul 2009 05:58:25 +0200 Received: by rv-out-0506.google.com with SMTP id b25so164193rvf.3 for ; Tue, 28 Jul 2009 20:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=hmuyzY4qr2RQzhXEnl2kMtzuefyVfNB5DhzU5yMvGS0=; b=Rj3fQ0XGkE3yg9PSTPSUxih/yEppCDIYN9WKz/saKiQPXBWSvBmwdQ1RFLPjm9xtFx VtFC5hXc4qTAha9hu2PdhbtPf3mwobW4SfJ2pcL48Uo/ITeKl7RUVwPE6fCvBTaGaR15 BuBbMa6iO45ZCdxDjE/k0ojcRPLI73fLxzymk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=uPdBnjL8tl3cLlf2sKMtLMyT7wMvqHGWWueRCljq167/DPXkfVhimA4zvR3SQUuRld HS76B+KnnQVH3nq5ncsod90VRswXefVIMx65t+pGZUiL2pXpsu6KPL94N09nQjKpwplh u11/3CPIzzeiWTEWhG3ZDaySu0A7+di4XLIOM= Received: by 10.141.22.2 with SMTP id z2mr5743637rvi.5.1248839904363; Tue, 28 Jul 2009 20:58:24 -0700 (PDT) Received: from ?192.168.0.11? (adsl-69-154-216-226.dsl.stlsmo.swbell.net [69.154.216.226]) by mx.google.com with ESMTPS id f21sm1934604rvb.10.2009.07.28.20.58.21 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 28 Jul 2009 20:58:23 -0700 (PDT) Message-ID: <4A6FC8CB.4010009@gmail.com> Date: Tue, 28 Jul 2009 22:58:03 -0500 From: Edgar Friendly User-Agent: Thunderbird 2.0.0.22 (X11/20090608) MIME-Version: 1.0 To: Elnatan Reisner , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Physical counterpart to Pervasives.compare? References: <1501.208.59.169.96.1248830737.squirrel@webmail.cs.umd.edu> <4A6FBCBF.4070900@gmail.com> In-Reply-To: <4A6FBCBF.4070900@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; pervasives:01 annotations:01 compile-time:01 pointers:01 pointers:01 edgar:98 edgar:98 wrote:01 wrote:01 ints:01 ints:01 compiles:01 caml-list:01 compares:01 compares:01 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