From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id C75FE7FE44 for ; Sat, 9 Jul 2016 22:10:10 +0200 (CEST) IronPort-PHdr: 9a23:KKkYBBF6+jgDLeDPUqPtkJ1GYnF86YWxBRYc798ds5kLTJ75rs6wAkXT6L1XgUPTWs2DsrQf2rKQ6PurADBZqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZvIaytQ8iJ3pzxjLv5osGKKyxzxxOFKYtoKxu3qQiD/uI3uqBFbpgL9x3Sv3FTcP5Xz247bXianhL7+9vitMU7q3cYk7sb+sVBSaT3ebgjBfwdVWx+cjN92Mq+/yHOUReC/DM1FC0riBlFDwHBplmuRp7sqCj3uuN58CafNMzyC7szXGLxwb1sTUrKjyEOKz4w9invkMtsnq9doxXp8x54xYfIYIiTcuJkeb/PcNUZQkJOW89QU2pKBYbqPNhHNPYIIesN99q1nFAJtxbrQFD0XO4= Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=jonathan.protzenko@gmail.com; spf=Pass smtp.mailfrom=jonathan.protzenko@gmail.com; spf=None smtp.helo=postmaster@mail-pf0-f175.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of jonathan.protzenko@gmail.com) identity=pra; client-ip=209.85.192.175; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jonathan.protzenko@gmail.com"; x-sender="jonathan.protzenko@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of jonathan.protzenko@gmail.com designates 209.85.192.175 as permitted sender) identity=mailfrom; client-ip=209.85.192.175; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jonathan.protzenko@gmail.com"; x-sender="jonathan.protzenko@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-pf0-f175.google.com) identity=helo; client-ip=209.85.192.175; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jonathan.protzenko@gmail.com"; x-sender="postmaster@mail-pf0-f175.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BkAAB9WYFXhq/AVdFchBQqQw+mEYdPiziBeiKCP4M3AoEjOBQBAQEBAQEBAREBAQEICwsJIS+CMgQBEgGCEwEFEhEECwEFCAEIEx0BAwwGBQsNAgImAgIjEQEFARwGDQYCAQEeh3MBAxcOoUaBMT4xizuBaoJaBYUnChknDVKDSQEBAQEBAQEBAQEBAQEBAQEBAQEWAgYQcYMbgguBeIJVh0KCWgWOeooegVuEMohFgjiHBw6FX45QMIEPHoJQgXdOiXoBAQE X-IPAS-Result: A0BkAAB9WYFXhq/AVdFchBQqQw+mEYdPiziBeiKCP4M3AoEjOBQBAQEBAQEBAREBAQEICwsJIS+CMgQBEgGCEwEFEhEECwEFCAEIEx0BAwwGBQsNAgImAgIjEQEFARwGDQYCAQEeh3MBAxcOoUaBMT4xizuBaoJaBYUnChknDVKDSQEBAQEBAQEBAQEBAQEBAQEBAQEWAgYQcYMbgguBeIJVh0KCWgWOeooegVuEMohFgjiHBw6FX45QMIEPHoJQgXdOiXoBAQE X-IronPort-AV: E=Sophos;i="5.28,338,1464645600"; d="scan'208";a="226188362" Received: from mail-pf0-f175.google.com ([209.85.192.175]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 09 Jul 2016 22:10:09 +0200 Received: by mail-pf0-f175.google.com with SMTP id c2so23185038pfa.2 for ; Sat, 09 Jul 2016 13:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=jgnh3maiASxZN2xNy7UkOMTRhUvMRXbbsmyVzr6yt4M=; b=xBPX9xqUBryTGjyuX5L7vXJw9h6xdsShQIqLKXCfp573jZldiYeOINMcupDf0356KR U1eXi4ODRIqsndf/Xi5CdnmL0zTt7FEmfSp8KD2l4UoFz21S3GeaIiyJnqovm6hQvbVg 4q02OvjAV6dfkYaGUM0MlRPsGwSuFE12ju4RvGOFk5DoACPI2uc0Nqh33ClGox17gBDa 4zljkJLXt9xZFWeEsCHGkHRADTWEoXiSo46uUquZF5+wPhWjQu6ZbLOC2scu25my/xq5 jvrfQ75g9WWoKwRRl03QLRr20+Qz0hcKvArhiRRD0BSTmr91yF4RwUJ4Y+2et7vZegEo Cngg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=jgnh3maiASxZN2xNy7UkOMTRhUvMRXbbsmyVzr6yt4M=; b=FBjBfVq+oWh9b70FArkFHRngsuM8+Zz9KQ1WZxdz8EUuWusWU2sKSzGmb+qMYExWc6 XZhcJUGGBXFMmr6lmnpG4K0Ms8j5Lmi1DCj608oT9k8G3AFsIQEk17kTchWFB62n9BGA b6j9QOK2JF6Qm+pD9hPwZQz2rtxCz1nu1nBj+7fg7JfdXc0ewVS1FX+c695d08YvQbfe mNu6dZjE+xwsuXfwjCz7eMI8ZKbyI/nihnRs6/ElHq/Xy0ibmIjzU4Sc72nzl0VA92Bi d56+n5U3CZxhYO1g7eYeCqlnojbhdk/hcT6Y+udwKuHsBL/ExJmHGhdZh+zUMtBCmouz EZcg== X-Gm-Message-State: ALyK8tIcjU8PnkUlET893pZ8tF2VKCo5vQ/dHk1BU8/4HZqvUI1k1vg9oKnB1yFLdhdGOA== X-Received: by 10.98.79.194 with SMTP id f63mr20988148pfj.95.1468095007471; Sat, 09 Jul 2016 13:10:07 -0700 (PDT) Received: from [192.168.1.53] ([162.222.170.100]) by smtp.gmail.com with ESMTPSA id h189sm5561588pfc.52.2016.07.09.13.10.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Jul 2016 13:10:06 -0700 (PDT) From: Jonathan Protzenko To: "Petter A. Urkedal" Cc: Gabriel Scherer , "caml-list@inria.fr" , "Soegtrop, Michael" References: <0F7D3B1B3C4B894D824F5B822E3E5A172CF204AF@IRSMSX102.ger.corp.intel.com> <0F7D3B1B3C4B894D824F5B822E3E5A172CF20547@IRSMSX102.ger.corp.intel.com> Message-ID: <2782bd72-cd55-d2af-37d9-2d097bdeef2b@gmail.com> Date: Sat, 9 Jul 2016 13:09:53 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:49.0) Gecko/20100101 Thunderbird/49.0a2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] ocambuild vs ocamldep circular dependencies FYI, here's how the source code of OCaml deals with this very problem. https://github.com/ocaml/ocaml/blob/trunk/typing/typecore.ml#L84 (forward reference...) https://github.com/ocaml/ocaml/blob/trunk/typing/typemod.ml#L1564 (filled later on). Arguably a dirty hack, but works really nicely in practice imho. Works with OCamlbuild too. ~ jonathan On 7/9/16 9:16 AM, Petter A. Urkedal wrote: > There is a way to do it if I understood the problem right by > functorizing and linking explicitly with the `module rec` construct: > > $ cat first_sig.mli > module type S = sig > type a > type b > val null : unit -> a > val succ : b -> a > end > > $ cat second_sig.mli > module type S = sig > type a > type b > val null : b > val succ : a -> b > end > > $ cat first.ml > module Make (X : Second_sig.S) = struct > type b = X.b > type a = N | B of b > let null () = N > let succ x = B x > end > > $ cat second.ml > module Make (X : First_sig.S) = struct > type a = X.a > type b = N | A of a > let null = N > let succ x = A x > end > > $ cat both.ml > module rec A : First_sig.S with type b = B.b = First.Make (B) > and B : Second_sig.S with type a = A.a = Second.Make (A) > > There are typically some shared types at the top of the signatures, > which could be put into a separate file and included. > > > On 9 July 2016 at 17:16, Soegtrop, Michael wrote: >> Dear Gabriel, >> >> >> >> The current implementation happens to allow them, but this does not mean >> that they are "valid programs". >> >> I see what you mean: since I can’t put both modules into a single file >> without changing the two let into let rec / and or using recursive modules, >> it is not valid OCaml, although the compiler accepts it if presented >> separately. >> >> >> >> Let me see what I can do here. The mutual dependent part is a large part of >> both modules so it wouldn’t be very nice to put them into one file. But if >> it is the only option to get a valid OCaml program, I will look into it. >> >> >> >> Still I think it is unfortunate that OCaml doesn’t support this. It makes it >> harder to structure software in an aspect oriented way. For simple data >> structures it is fine to bundle all aspects into a single module or file. >> For a data structure like a C AST, the module / file will get quite large. I >> can separate off the statements easily, but this is only a small part of the >> AST. The largest part are expressions and types, and these are recursively >> dependent on each other. >> >> >> >> Best regards, >> >> >> >> Michael >> >> Intel Deutschland GmbH >> Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany >> Tel: +49 89 99 8853-0, www.intel.de >> Managing Directors: Christin Eisenschmid, Christian Lamprechter >> Chairperson of the Supervisory Board: Nicole Lau >> Registered Office: Munich >> Commercial Register: Amtsgericht Muenchen HRB 186928