From: Peter Sewell <Peter.Sewell@cl.cam.ac.uk>
To: caml-list@yquem.inria.fr
Subject: Re: Caml-list Digest, Vol 18, Issue 36
Date: Fri, 22 Dec 2006 00:48:01 +0000 [thread overview]
Message-ID: <E1GxYZt-0005RY-00@mta1.cl.cam.ac.uk> (raw)
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>
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
next parent reply other threads:[~2006-12-22 0:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20061221221725.5B539BC6F@yquem.inria.fr>
2006-12-22 0:48 ` Peter Sewell [this message]
2006-12-22 2:03 ` [Caml-list] " Till Varoquaux
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1GxYZt-0005RY-00@mta1.cl.cam.ac.uk \
--to=peter.sewell@cl.cam.ac.uk \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox