From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id B22D4BBAF for ; Mon, 19 Oct 2009 13:01:15 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgECAMrj20rZSMDji2dsb2JhbACBUZk9AQEBCgsKBxEFvxqEMQSBWw X-IronPort-AV: E=Sophos;i="4.44,584,1249250400"; d="scan'208";a="36607011" Received: from fmmailgate02.web.de ([217.72.192.227]) by mail3-smtp-sop.national.inria.fr with ESMTP; 19 Oct 2009 13:01:14 +0200 Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate02.web.de (Postfix) with ESMTP id EA5AF13475D1D; Mon, 19 Oct 2009 13:01:13 +0200 (CEST) Received: from [95.208.117.111] (helo=frosties.localdomain) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #314) id 1MzpzF-00038N-00; Mon, 19 Oct 2009 13:01:13 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1MzpzE-0006eo-UZ; Mon, 19 Oct 2009 13:01:12 +0200 From: Goswin von Brederlow To: "Damien Guichard" Cc: "caml-list@yquem.inria.fr" Subject: Re: [Caml-list] Linking mutually dependent modules for fun References: <4AD33F66.4020200@wp.pl> <200910161841331259870@orange.fr> Date: Mon, 19 Oct 2009 13:01:12 +0200 In-Reply-To: <200910161841331259870@orange.fr> (Damien Guichard's message of "Fri, 16 Oct 2009 18:41:34 +0200") Message-ID: <877hurzlzb.fsf@frosties.localdomain> User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.22 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1+hOK7LCjmRPU461G1GHlhJ2h8Wcz9/7XrOd24k u38zCT0HX6YqbrP9mHZZSB0jrw6S8mPZ9n59upC6ayPtdQvp9e THNoI+Tuc= X-Spam: no; 0.00; damien:01 guichard:01 recursive:01 ocaml's:01 mli:01 val:01 mli:01 val:01 endline:01 endline:01 ocaml:01 dependencies:01 ocaml:01 inlining:01 inlining:01 "Damien Guichard" 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