|
|
Subject: [Caml-list] Re: Caml-list Digest, Vol 18, Issue 36
From: Peter Sewell
Date: 12/22/2006 12:50:06 AM
Philippe Wang wrote:
>Serge Aleynikov 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...
>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...
>
>If OCaml is particularly efficient, it's probably mostly because of that!
If you want an upper bound on the cost of maintaining enough
information to calculate real type information at runtime, given
statically Caml-typable programs, you may like to look at the HashCaml
type-safe marshalling implementation
<http://www.cl.cam.ac.uk/~pes20/hashcaml/index.html>. We didn't
investigate performance in detail, and the code is not highly
optimized, but the cost certainly didn't seem to be outrageous.
Peter
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
|