Version française
Home     About     Download     Resources     Contact us    
Browse thread
ambitious proposal: polymorphic arithmetics
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: padiolea@i...
Subject: Re: [Caml-list] ambitious proposal: polymorphic arithmetics
> Eijiro Sumii <eijiro_sumii@anet.ne.jp> writes:
>
>> So here it goes: why don't we have polymorphic +, -, etc. while we
>> have polymorphic =, <, etc.?
>

[...]

>
> OCaml doesn't have a mechanism for making +, - applicable to a limited
> set of types and for dispatching their implementation based on the type
> rather than on the physical representation.

In the module Obj of the caml library there is a function
 external is_int : t -> bool = "%obj_is_int"
I guess that the value are represented internally as "cells" and that
cells have a bit indicating wether it is an int or a pointer (and also
a bit for the gc)

By using more bits we could know wether or not it is a float, and
so have also a function
 is_float: t -> bool
and so we could then code a "generic" + function
(but it would lead to an overhead due to the dispatch).

Nevertheless I dont think that making + generic is an ambitious/important
feature.
My big wish for ocaml would be to have some better tracing facilities,
a generic print function, and the possibilty to print backtraces,
some features available in langage such as perl and that makes the life
of the developper far easier.