From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id A8F0EBC84 for ; Thu, 24 Mar 2005 22:51:40 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j2OLpe5P005936 for ; Thu, 24 Mar 2005 22:51:40 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA19035 for ; Thu, 24 Mar 2005 22:51:39 +0100 (MET) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j2OLpc28005931 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Thu, 24 Mar 2005 22:51:39 +0100 Received: from root by ciao.gmane.org with local (Exim 4.43) id 1DEaEP-00085x-EP for caml-list@inria.fr; Thu, 24 Mar 2005 22:51:09 +0100 Received: from 0x50a5bb8d.odnxx9.adsl-dhcp.tele.dk ([80.165.187.141]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 24 Mar 2005 22:51:09 +0100 Received: from spam by 0x50a5bb8d.odnxx9.adsl-dhcp.tele.dk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 24 Mar 2005 22:51:09 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Bardur Arantsson Subject: Re: Pervasives.compare output type Date: Thu, 24 Mar 2005 22:38:39 +0100 Message-ID: References: <42430B3B.60408@barettadeit.com> <20050324194115.GB9518@furbychan.cocan.org> <87acosu5c9.fsf@qrnik.zagroda> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 0x50a5bb8d.odnxx9.adsl-dhcp.tele.dk User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050323) X-Accept-Language: en-us, en In-Reply-To: <87acosu5c9.fsf@qrnik.zagroda> Sender: news X-Gmane-MailScanner: Found to be clean X-Gmane-MailScanner: Found to be clean X-MailScanner-From: gclci-caml-list@m.gmane.org X-MailScanner-To: caml-list@inria.fr X-Miltered: at concorde with ID 4243366C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4243366A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; pervasives:01 pervasives:01 integers:01 subtraction:01 integers:01 ocaml:01 byterun:01 subtraction:01 sdu:01 wrote:01 writes:01 polymorphic:01 define:01 output:02 comparison:03 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Marcin 'Qrczak' Kowalczyk wrote: > Richard Jones writes: > > >>>type comparison_result = Less | Equals | Greater >>> >>>What are the reasons behind the present design choice? >> >>Wouldn't it be for speed? You could define Pervasives.compare over >>integers just as a subtraction. > > > You can't, because of overflow. > Actually, since integers in OCaml are limited to (n-1) bits where n=32 or n=64 depending on architecture, overflow shouldn't be a problem. (The comments in byterun/compare.c also seem to agree with that.) Even so, it would be very slow to the polymorphic compare to compare integers, so if one cares about efficiency, direct subtraction is preferable. -- Bardur Arantsson "Mr. T to pity fool." http://www.theonion.com