[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Bardur Arantsson <spam@s...> |
| Subject: | Re: Pervasives.compare output type |
Marcin 'Qrczak' Kowalczyk wrote:
> Richard Jones <rich@annexia.org> 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
<bardur@imada.sdu.dk>
<bardur@scientician.net>
"Mr. T to pity fool."
http://www.theonion.com