Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread output type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Bardur Arantsson <spam@s...>
Subject: Re: output type
Marcin 'Qrczak' Kowalczyk wrote:
> Bardur Arantsson <> writes:
>>>>Wouldn't it be for speed?  You could define 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

Indeed, I mistook compare_val for caml_compare.

Still if you can make sufficient guarantees about the ranges of the
integers being compared, you *can* use '-' which *should* be faster than
branching according to conventional wisdom.

The more 'relaxed' requirement that comparison functions can return
anything<0, 0 or anything>0 just means that any higher-order functions
which take comparison functions as arguments *might* run slightly
faster... whether this is true in practise is another matter entirely.


Bardur Arantsson

It's not often you see something that's both romantic *and*
                                               Dawn, 'The Office'