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.0 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 588DDBC37 for ; Wed, 29 Jul 2009 05:07:05 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjICADtZb0rRVdi/mWdsb2JhbACZST8BAQEBAQgLCgcTqWCBH5AcAQMCBIQMBYlo X-IronPort-AV: E=Sophos;i="4.43,286,1246831200"; d="scan'208";a="33751911" Received: from mail-px0-f191.google.com ([209.85.216.191]) by mail1-smtp-roc.national.inria.fr with ESMTP; 29 Jul 2009 05:07:04 +0200 Received: by pxi29 with SMTP id 29so327125pxi.1 for ; Tue, 28 Jul 2009 20:07:03 -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=fBjZlSfK+vII0wS9CyEI/DIAN9FmeTnVOYvKcYMPC40=; b=lFUMMnoTOp6o/YW+MSArqxmQwgLoiZCf2+lBrVFfeRTeIml3/HUAv53OUMGxmy/Z2B ZFpqSfIqltHV0YCpI5T5xgXdc7D/TChhQ69XIOiRjSTuQCEgt2MN9CnKEgFuimirrUoB oy6G30cUrPf4xL7hYLdLZH8L3eanjRuXHM4m8= 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=IL3Gfo8y6pGAnKdmMVN9GSCFZzS2PoIgwT+ZubsvBrfBB7c0MZQmjGM/SMKkLy9vt6 Ee5Ov9MD7AYxFaZNYRMi0+nfcJq1qrqU4FdEJqJCVFUz103WDH01HuC84z+VCAImPtUb w9PDrqQwXy3y315ggRiYwaajcAN5kyYiOtt14= Received: by 10.114.240.8 with SMTP id n8mr13132932wah.221.1248836823441; Tue, 28 Jul 2009 20:07:03 -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 l30sm653106waf.35.2009.07.28.20.06.58 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 28 Jul 2009 20:07:02 -0700 (PDT) Message-ID: <4A6FBCBF.4070900@gmail.com> Date: Tue, 28 Jul 2009 22:06:39 -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> In-Reply-To: <1501.208.59.169.96.1248830737.squirrel@webmail.cs.umd.edu> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; pervasives:01 pervasives:01 trivial:01 annotations:01 compile-time:01 ocaml:01 ocaml:01 edgar:98 polymorphic:01 wrote:01 compiles:01 caml-list:01 int:01 int:01 let:03 Elnatan Reisner wrote: > Is there something that can complete this analogy: > (=) is to (==) as Pervasives.compare is to ___? > > That is, is there a polymorphic total ordering with respect to *physical* > entities, rather than to their structure? > No, but it'd be pretty trivial to implement through the C interface. > 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]. If you had to stay in the OCaml realm, you might be able to do [let phys_comp (x:'a) (y:'a) = (Obj.magic x) - (Obj.magic y)], but it depends on the exact implementation of (-) on your architecture, as it may produce a value that's not an OCaml int when given non-ints as input. E