Version française
Home     About     Download     Resources     Contact us    
Browse thread
Pervasives.compare output type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Marcin 'Qrczak' Kowalczyk <qrczak@k...>
Subject: Re: [Caml-list] Re: Pervasives.compare output type
Bardur Arantsson <spam@scientician.net> writes:

>>>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.

compare must eventually return an OCaml int. It can use subtraction
only in its internal recursion, but when presenting the result to
OCaml code it can't just pass the result of subtraction.

It can use subtraction internally no matter whether the OCaml
interface uses intergers whose sign only matters, or an enumeration.

And thus there seems to be no performance advantage in using ints
instead of the enumeration.

In practice it returns -1,0,1 anyway:
# compare 10 20;;
- : int = -1

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/