From: Jan Rochel <jan@besport.com>
To: caml-list@inria.fr
Subject: [Caml-list] Mutually recursive dependent files
Date: Fri, 6 Mar 2020 17:06:44 +0100 [thread overview]
Message-ID: <5ceb9ffd-943b-b1f2-4851-e4bf528a791d@rochel.info> (raw)
I'm sure that most of you have tripped at one point or another over the problem
of OCaml not allowing for module files that mutually depend on each other. The
fact that this is possible for modules within the same file raises the
question: why not for module files?
If I had to guess I'd say that the following reasoning led to that limitation:
OCaml's semantics is script-like in that there is not a specific, explicitly
defined entry point (such as a main-function in C), but each file is
interpreted from top to bottom, so the order of the declarations within a file
is critically important (due to side effects they may have). This also pertains
to the order imposed on the module files before compilation and linking. (This
order is either imposed by the user or a dependency generator). Now if one were
to allow for recursive module files, then there would be no well-defined linear
order imposable on them and therefore the semantics would become ambiguous.
My first question:
Is this the actual reasoning behind the limitation or are there other (perhaps
more pertinent) reasons?
My contention:
The above-mentioned ambiguity already exists if a dependency generator is used.
If we have modules A -> B <- C, then there are two orders possible: BAC and
BCA. A and C may both produce side-effects within B during "initialisation" and
unexpected things might happen in B. Given this fact, it should already be
considered bad practice to write OCaml programs that are sensitive to module
linking order. But if OCaml programs already have to be written with this
semantic ambiguity in mind, then why not simply allow for mutually recursive
module files?
My second question:
If the answer to my first question is yes, and if my contention is to the
point, then I'd be curious to to know how difficult it would be to add a flag
to the OCaml compiler allowing for mutually recursive dependencies?
Jan
next reply other threads:[~2020-03-06 16:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-06 16:06 Jan Rochel [this message]
2020-03-11 8:25 ` Jacques Garrigue
2020-03-11 9:35 ` Mark Shinwell
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=5ceb9ffd-943b-b1f2-4851-e4bf528a791d@rochel.info \
--to=jan@besport.com \
--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