caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: "Damien Guichard" <alphablock@orange.fr>
Cc: "caml-list@yquem.inria.fr" <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Linking mutually dependent modules for fun
Date: Mon, 19 Oct 2009 13:01:12 +0200	[thread overview]
Message-ID: <877hurzlzb.fsf@frosties.localdomain> (raw)
In-Reply-To: <200910161841331259870@orange.fr> (Damien Guichard's message of "Fri, 16 Oct 2009 18:41:34 +0200")

"Damien Guichard" <alphablock@orange.fr> writes:

> Hi Dawid,
>
>  
>
> Have you ever considered recursive modules ?
>
> [[http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc75]]

The problem there is that that places everything in one file.

>> The following is what I got when studying OCaml's linking issues:
>> A.mli: val flip : unit - > unit
>> A.ml: let flip () = print_string "1"; B.flop ()  let _ = flip ()
>> B.mli: val flop : unit - > unit
>> B.ml: let flop () = print_string "0"; A.flip ()
>> C.ml: let _ = print_endline "C"

One solution is to use a closure argument to lift dependency out of A
into B:

A.mli: val flip : (unit -> unit) -> unit - > unit
A.ml: let flip flop () = print_string "1"; flop ()
B.mli: val flop : unit - > unit
B.ml: let rec flop () = print_string "0"; A.flip flop ()
C.ml: let _ = print_endline "C"; let _ = A.flip B.flop ()


I had the same problem myself several times and asked why ocaml does
not allow mutually dependencies of modules wheren each ml file only
depends on the other mli file. The reason I was given is
that ocaml does cross module inlining. That means B.ml depends on A.ml
(in its compiled form) for inlining and A.ml depends on B.ml for
inlining. So the dependency is not just on the mli files.

In say C the *.c files only depend on the *.h files and the mutual
dependencies between *.c files are only link time while in ocaml the
cross module inlining makes it a compile time issue.

MfG
        Goswin


      reply	other threads:[~2009-10-19 11:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-12 14:38 Dawid Toton
2009-10-16 16:41 ` [Caml-list] " Damien Guichard
2009-10-19 11:01   ` Goswin von Brederlow [this message]

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=877hurzlzb.fsf@frosties.localdomain \
    --to=goswin-v-b@web.de \
    --cc=alphablock@orange.fr \
    --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;
as well as URLs for NNTP newsgroup(s).