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
Scripting in ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-12-21 (22:06)
From: Serge Aleynikov <serge@h...>
Subject: Re: [Caml-list] Scripting in ocaml
Philippe Wang wrote:
>> What I meant by "strict typing" was performing type checks *at 
>> runtime*, i.e. that there are no unsafe operations.
>> Say, as an example, doing type checks of function arguments at runtime:
>> let f = fun i when is_integer (i) -> i
>>           | x when is_float   (x) -> int_of_float x;;
>> (raising Bad_match of some sort if neither one of the two guards pass)
>> Direct application of this could be for making the Marshal/Unmarshal 
>> modules more safe when marshaling data over files/sockets between 
>> applications written in heterogeneous languages.
> If you want to do that, use Lisp...

Indeed. I am also quite happy with having that feature in Erlang.  ;-)

> Or use sum types...
> type t = Int of int | Float of float | ...
> OCaml forgets types at runtime !
> This means that you can't know without a huge cost (cf. SafeUnmarshal 
> costs), because what you can do in O(1) is to know whether a value is an 
> int or a pointer...

There doesn't seem to be a large overhead for knowing if a value is a 
closure, string, float or float array either (they have dedicated tag 
values accessed with a single dereferencing).  With having the compiler 
reserve some tag values for other basic types that could optionally be 
inspected at run-time, it perhaps wouldn't penalize efficiency very badly.

> If OCaml is particularly efficient, it's probably mostly because of that!
> ...

This thread began with John's statement that "interaction of the static 
typing and dynamic loading was not easy".  Any dynamic type check by all 
means would reduce efficiency of a statically typed language.  But maybe 
it's possible to do dynamic type checking optional and make it available 
if explicitly requested.  At least if would make dynamic code loading 
less complicated.


Serge Aleynikov
Routing R&D, IDT Telecom
Tel: +1 (973) 438-3436
Fax: +1 (973) 438-1464