Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Why + vs +. but "fake" parametric polymorphism for <
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-10-13 (13:53)
From: Gerd Stolpmann <info@g...>
Subject: Re: [Caml-list] Why + vs +. but "fake" parametric polymorphism for <
Am Freitag, den 13.10.2006, 14:46 +0200 schrieb Diego Olivier FERNANDEZ
>      Bonjour,
> Quoting Gerd Stolpmann <>:
> > Well, this is quite easy. The .mli file does not influence code
> > generation. Code is generated when the .ml file is compiled, and it is
> > only _checked_ afterwards if the types match the .mli file. This is
> > simply the logic of the .mli.
> Very well, but why ?

I think the answer is that ocaml uses the model of separate compilation.
That means you can compile the top-level modules separately (in a
certain order) and link them later together. Of course, this implies
that the compilation and code generation steps must be applied in a
certain order. Ocaml is already cleverer than most other implementations
of separate compilation because it allows to defer some parts of code
generation (the so-called cross-module inlining feature).

One can imagine different models. For example, you could do code
generation when a function is _used_, not when the function is seen by
the compiler for the first time. That way, you can always specialize the
function in the generated code to what the types allow. Such a model is
seen as quite problematic, however, because it is unclear how to create
pre-compiled libraries. (In the C++ world often a variation of this
model is used, and is an endless source of problems.)

Of course, you may ask why Ocaml's inlining feature isn't clever enough
to do late specialisation, at least of functions that can be inlined. I
don't know.

Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
Phone: +49-6151-153855                  Fax: +49-6151-997714