Browse thread
Scripting in ocaml
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2006-12-21 (21:27) |
From: | Philippe Wang <lists@p...> |
Subject: | Re: [Caml-list] Scripting in ocaml |
Serge Aleynikov a écrit : > 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! ... Cheers, -- Philippe Wang mail(at)philippewang.info