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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 0B508BC0A for ; Thu, 21 Dec 2006 23:06:26 +0100 (CET) Received: from mail.corp.idt.net (mail.corp.idt.net [169.132.25.53]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id kBLM6P2h011129 for ; Thu, 21 Dec 2006 23:06:25 +0100 Received: from [169.132.9.113] (account saleyn HELO [169.132.9.113]) by mail.corp.idt.net (CommuniGate Pro SMTP 4.2.10) with ESMTP id 192983446; Thu, 21 Dec 2006 17:06:24 -0500 Message-ID: <458B0560.8090400@hq.idt.net> Date: Thu, 21 Dec 2006 17:06:24 -0500 From: Serge Aleynikov User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: Philippe Wang Cc: caml-list@inria.fr Subject: Re: [Caml-list] Scripting in ocaml References: <6dbd4d000612201941wcd4b09anc503a13889576512@mail.gmail.com> <20061221153413.8f99e8ed.mle+ocaml@mega-nerd.com> <1166685756.5337.4.camel@rosella.wigram> <458A8C7B.7050204@hq.idt.net> <1166709162.5653.11.camel@rosella.wigram> <458AA143.3090303@hq.idt.net> <20061221202520.GG9440@apotheon.com> <458AF864.20902@hq.idt.net> <458AFC39.70707@philippewang.info> In-Reply-To: <458AFC39.70707@philippewang.info> Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 458B0561.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 runtime:01 runtime:01 marshaling:01 sockets:01 erlang:01 ocaml:01 pointer:01 compiler:01 optionally:01 run-time:01 statically:01 wrote:01 typing:01 integer:01 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. BR, Serge -- Serge Aleynikov Routing R&D, IDT Telecom Tel: +1 (973) 438-3436 Fax: +1 (973) 438-1464