Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Oleg <oleg@okmij.org>
To: caml-list@inria.fr
Subject: [Caml-list] Separate compilation
Date: Sat, 5 Apr 2025 13:26:53 +0900	[thread overview]
Message-ID: <Z/CxDairaiIpSICa@Magus.localnet> (raw)


In designing separate compilation, OCaml has decided to restrict the
correspondence between separately compiled modules and their
interfaces to one-to-one. The restriction is indeed limiting: making
the linking with alternative/improved implementations, and the
implementation extension/evolution ungainly (in fact, seemingly
impossible).

To be concrete: suppose we have an interface A.mli and two implementations 
of it: A1.ml and A2.ml. We also have the user code B.ml:
        open A
        ... using the operations of A
We want to compile B.ml and link that B.cmo with either
implementation. As posed, the problem seem unsolvable: we need either
modify the source B.ml to refer to a particular implementation, or turn
B.ml into a functor (which could be inconvenient, and also suboptimal:
calls to A operations become indirect). 

For the next problem, assume the interface U.mli and its
implementation U.ml. We want to extend them -- say, add a new
operation to the interface and the implementation -- without modifying
U.mli/U.ml and without cut-and-paste. That is, we want merely `include'
U and add the new operation -- making a `diff' so to speak. If U.mli
abstracts away the implementation details, and if they are needed to
implement the new operation, the problem seem unsolvable.

It turns out there are work-arounds for both problems, which solve
them, albeit not elegantly. The full explanation is a bit too long for
this message; please see
        https://okmij.org/ftp/ML/module-extensibility.html

The work-arounds are simple. Should OCaml developers be so inclined, they
may be incorporated in OCaml.


             reply	other threads:[~2025-04-05  4:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-05  4:26 Oleg [this message]
2025-04-07 21:55 ` Edwin Török
  -- strict thread matches above, loose matches on Subject: below --
2011-09-08 14:26 [Caml-list] separate compilation Walter Cazzola
2011-09-08 14:33 ` Philippe Wang
2011-09-08 14:40   ` Walter Cazzola
2011-09-08 14:33 ` Esther Baruk
2011-09-08 14:42   ` Walter Cazzola
2011-09-08 15:55     ` AUGER Cedric
2011-09-09  6:50       ` Walter Cazzola
2011-09-09  7:06         ` David Allsopp

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=Z/CxDairaiIpSICa@Magus.localnet \
    --to=oleg@okmij.org \
    --cc=caml-list@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