From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id BBE7CBC0A for ; Fri, 22 Dec 2006 01:48:01 +0100 (CET) Received: from mta1.cl.cam.ac.uk (mta1.cl.cam.ac.uk [128.232.0.15]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kBM0m1vR012136 for ; Fri, 22 Dec 2006 01:48:01 +0100 Received: from stem.cl.cam.ac.uk ([128.232.9.62] helo=cl.cam.ac.uk) by mta1.cl.cam.ac.uk with esmtp (Exim 3.092 #1) id 1GxYZt-0005RY-00 for caml-list@yquem.inria.fr; Fri, 22 Dec 2006 00:48:01 +0000 To: caml-list@yquem.inria.fr Subject: Re: Caml-list Digest, Vol 18, Issue 36 In-Reply-To: Message from caml-list-request@yquem.inria.fr of "Thu, 21 Dec 2006 23:17:25 +0100." <20061221221725.5B539BC6F@yquem.inria.fr> Date: Fri, 22 Dec 2006 00:48:01 +0000 From: Peter Sewell Message-Id: X-Miltered: at discorde with ID 458B2B41.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; runtime:01 runtime:01 marshaling:01 sockets:01 ocaml:01 pointer:01 ocaml:01 statically:01 type-safe:01 marshalling:01 outrageous:98 wrote:01 wrote:01 typing:01 integer:01 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 . 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