From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by c5ff346549e7 (Postfix) with ESMTP id C83DD5D4 for ; Sat, 29 Feb 2020 09:06:03 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.70,499,1574118000"; d="scan'208,217";a="438142853" Received: from sympa.inria.fr ([193.51.193.213]) by mail2-relais-roc.national.inria.fr with ESMTP; 29 Feb 2020 10:06:02 +0100 Received: by sympa.inria.fr (Postfix, from userid 20132) id E0C397F442; Sat, 29 Feb 2020 10:06:02 +0100 (CET) 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 F2F297F423 for ; Sat, 29 Feb 2020 10:05:54 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-qt1-f176.google.com IronPort-PHdr: =?us-ascii?q?9a23=3AgN+PaxGC4P1zOxik3oAXOZ1GYnF86YWxBRYc798d?= =?us-ascii?q?s5kLTJ7yps2wAkXT6L1XgUPTWs2DsrQY0raQ4vGrADZZqb+681k8M7V0Hycfjs?= =?us-ascii?q?sXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aFRrwLxd6?= =?us-ascii?q?KfroEYDOkcu3y/qy+5rOaAlUmTaxe7x/IAi5oAnLssQbhYRuJrsvxhfUv3BFZ/?= =?us-ascii?q?lYyWR0KF2cmBrx+t2+94N5/SRKvPIh+c9AUaHkcKk9ULdVEjcoPX0r6cPyrRXM?= =?us-ascii?q?QheB6XUaUmUNjxpHGBPF4w3gXpfwqST1qOxw0zSHMMLsTLA0XTOi77p3SBLtlS?= =?us-ascii?q?wKOSI1/H3Rh8dtl69Qvg6vqAJjzI7VeIGVNeRxfqX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-ascii?q?ee2IRCkrR4tokdALakd5Xd6li0Kbhnf4M/ouj7WOQacM3Ofc0nz2fZgvzn/H0O?= =?us-ascii?q?w4kwBjTJIQayupgalw8wWVDInMwR3AxvSaMJ8E1SuIz1+tiG+HvUVWSgl1CPyX?= =?us-ascii?q?UnUWZ0+QptP8tBrP?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DyBwCEKFpef7CgVdFmhRJEgQcqhBSBH?= =?us-ascii?q?IJeiwOCEYMPh1qQVQkBAwEMJQoEAQGDCnFFAoIKHAcBBDQTAhABAQUBAQECAQI?= =?us-ascii?q?DBAETAQEJCwsIJ4VfDII7KQGCfwEBAQIBEhEdARsdAQMBCwYFCzcCAiIBEQEFA?= =?us-ascii?q?RwGEyKDBYJJAQMOIA+hRoEEPYsogRUFAReDAAWBREGCPwoZJw1iA4EyAgcSgSa?= =?us-ascii?q?MJQ+BTD+BR4IwLj6CZAICghCCZIJeBI1ISohjgimHPo8/B4I/eASGVY8UHINIl?= =?us-ascii?q?2mXbJJlDyOBRoF6MxojUDGCOwlHGA2NeYQXgT6CYoY2QzACj3ABAQ?= X-IPAS-Result: =?us-ascii?q?A0DyBwCEKFpef7CgVdFmhRJEgQcqhBSBHIJeiwOCEYMPh1q?= =?us-ascii?q?QVQkBAwEMJQoEAQGDCnFFAoIKHAcBBDQTAhABAQUBAQECAQIDBAETAQEJCwsIJ?= =?us-ascii?q?4VfDII7KQGCfwEBAQIBEhEdARsdAQMBCwYFCzcCAiIBEQEFARwGEyKDBYJJAQM?= =?us-ascii?q?OIA+hRoEEPYsogRUFAReDAAWBREGCPwoZJw1iA4EyAgcSgSaMJQ+BTD+BR4IwL?= =?us-ascii?q?j6CZAICghCCZIJeBI1ISohjgimHPo8/B4I/eASGVY8UHINIl2mXbJJlDyOBRoF?= =?us-ascii?q?6MxojUDGCOwlHGA2NeYQXgT6CYoY2QzACj3ABAQ?= X-IronPort-AV: E=Sophos;i="5.70,499,1574118000"; d="scan'208,217";a="438142821" X-MGA-submission: =?us-ascii?q?MDEeB/6tekR4gMnofFNYeSepeWD9gvOpg+ss02?= =?us-ascii?q?DMJHGbYtwIdPCcGTQKQ1CS/mWAtyi7XipfwTI1W/DZoJxghrZ38+xwg1?= =?us-ascii?q?iDmsGNtaYHLqaxmG9k3AzOYGwO5zKV3s7RoDpsi3rsM1z/xIAy5tH2rD?= =?us-ascii?q?obTNfeDyUU84JCN/H9WbnVHg=3D=3D?= Received: from mail-qt1-f176.google.com ([209.85.160.176]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 29 Feb 2020 10:05:54 +0100 Received: by mail-qt1-f176.google.com with SMTP id e20so3947912qto.5 for ; Sat, 29 Feb 2020 01:05:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZHkyuZMPRfXIYBVztbTjjnb1eQAZL25s6tS26QlEM0I=; b=opMOt0K1Y3v2ffOVEzJdIXA9pwVdjxQ1PrXZ3bDrGGlcZHrG1yTVQYUX/OJv3UnoI1 wbtki0enDbM4eCKNOs5ONuqmJf/OTb+QOMlrd/v4cnnXvOA7A43wQDZjYhDnX+KxrmCn Ip6lgozHCo76ok0MAqjFhBHua/5qGuNQKIIphZRAdoZp+SDeYsUeDuYX5x1AuyKJltVp BAZFLFK4r/uyRjlFwnKJvkIXVu+A7/pFeOZdROrGnSj1x7z2HzlaXxBhVxiie6p2H67G MH2QRPJIqgGJgvuJi+JBBI7QIeByFP+AwD96xxHAj8Wc+PkAbdEweHaHJqoATHZQ9fEl V/bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZHkyuZMPRfXIYBVztbTjjnb1eQAZL25s6tS26QlEM0I=; b=ripfARvNaEzRIQj+7t4m0r06ioVu/+s8EzIj7T1wHILv+zvzNWlcSbwt93+TePKhIX Y/D5SJNFEAWY48GeGUjYE1sLVE5lDz3MyKH7h7g+96tIkxwCp9s/GKbUKorUUQ6lXTAp fqbQw9kElutHss/XyZmA/oUcOK07lrFJo3N08QsL4JEFxVHuAhTiUpOdpfO5K4necAS1 KqbhcePDNDsF4YJNPhgCr7a+aA9tw+piFYW/7x4h1/gFJ5NkemKtEy1V4bAZSoTe13UF cpmmWn9hjJM0z9kafyQ6v0vo81Q+6oEq40K2neMGM82tVsZO2E6HhCtF89szYpITsQvm nxAw== X-Gm-Message-State: APjAAAVgh/DpqguuiHNOCin/m4QZBFA7Qi9R3jbQyR8iV/xZoGDY0FbN CPolB2PbXSa6CKE8fG2ogg6rEDTo/98wG3y7f8HBcEDuDNo= X-Google-Smtp-Source: APXvYqxGnB1aZGhCzCc1Cy0AeK06Tp1sIi81RQQ7Qfq5l1wIXmR2Wh5YSppEuBFFhCwv4nfEN8MXtvFc3HyEKFvqRKM= X-Received: by 2002:ac8:1baf:: with SMTP id z44mr7887435qtj.127.1582967152783; Sat, 29 Feb 2020 01:05:52 -0800 (PST) MIME-Version: 1.0 References: <20200229085319.GD11122@rich.annexia.org> In-Reply-To: <20200229085319.GD11122@rich.annexia.org> From: Gabriel Scherer Date: Sat, 29 Feb 2020 10:09:51 +0100 Message-ID: To: "Richard W.M. Jones" Cc: caml users Content-Type: multipart/alternative; boundary="000000000000d53639059fb342cc" Subject: Re: [Caml-list] #use is not textual inclusion Reply-To: Gabriel Scherer X-Loop: caml-list@inria.fr X-Sequence: 18029 Errors-to: caml-list-owner@inria.fr Precedence: list Precedence: bulk Sender: caml-list-request@inria.fr X-no-archive: yes List-Id: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --000000000000d53639059fb342cc Content-Type: text/plain; charset="UTF-8" I think that your example is rejected not because of the semantics of #use, but because toplevel directives in general are parsed at the level of toplevel *phrases*, and not possibly-in-depth structure items. In other words, a toplevel script is a sequence of structure items or toplevel directives, but directives are not (nestable) structure items. The documentation seems correct -- consistent with this behavior. I see a way to do what you want using #mod_use, but it is a bit indirect because #mod_use does not directly support signature checking: module type Foo_sig = sig ... end #mod_use "implementation.ml";; module Foo = (Implementation : Foo_sig);; This approach defines a suitably restricted Foo, but it also exposes the Implementation module in the rest of the scope. You can avoid this if you use the same .ml name as the module name you want, so that shadowing hides the implementation module module type Foo_sig = sig ... end #mod_use "foo.ml ";; module Foo = (Foo : Foo_sig);; On Sat, Feb 29, 2020 at 9:54 AM Richard W.M. Jones wrote: > I was trying to break up a large ocaml interpreted script: > > https://github.com/libguestfs/libnbd/blob/master/generator/generator > > The script contains sections like: > > module Foo : sig > (* type signature *) > end = struct > (* very long implementation *) > end > > and it would be convenient for me to move the implementations into > separate files. However this doesn't work: > > module Foo : sig > (* type signature *) > end = struct > #use "implementation.ml" (* with or without ;; here *) > end > > So I guess #use only works for top level statements, which surprised > me and contradicts the documentation here too: > > > https://caml.inria.fr/pub/docs/manual-ocaml/toplevel.html#s%3Atoplevel-directives > > I could move the whole module definition to the file, but then I would > lose the advantage of hiding the implementation while keeping the > signature visible in the main file. > > Given the constraint that we can't use ocamlc or cppo (because of > minimal build dependencies), are there any alternatives? My first > thought was C's cpp, but it seems impossible to get that working with > #!/usr/bin/env and preserve the "scriptiness" of being able to just do > ./generator/generator to run it. > > Rich. > --000000000000d53639059fb342cc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I think that your example is rejected not because of = the semantics of #use, but because toplevel directives in general are parse= d at the level of toplevel *phrases*, and not possibly-in-depth structure i= tems. In other words, a toplevel script is a sequence of structure items or= toplevel directives, but directives are not (nestable) structure items. Th= e documentation seems correct -- consistent with this behavior.
<= br>
I see a way to do what you want using #mod_use, but it is a b= it indirect because #mod_use does not directly support signature checking:<= /div>

=C2=A0 =C2=A0 module type Foo_sig =3D sig ... end<= /div>
=C2=A0 =C2=A0 #mod_use "implementation.ml";;
=C2=A0 =C2=A0 mo= dule Foo =3D (Implementation : Foo_sig);;

This app= roach defines a suitably restricted Foo, but it also exposes the Implementa= tion module in the rest of the scope. You can avoid this if you use the sam= e .ml name as the module name you want, so that shadowing hides the impleme= ntation module

=C2=A0 =C2=A0 module type = Foo_sig =3D sig ... end
=C2=A0 =C2=A0 #mod_use "foo.ml";;
= =C2=A0 =C2=A0 module Foo =3D (Foo : Foo_sig);;


On= Sat, Feb 29, 2020 at 9:54 AM Richard W.M. Jones <rich@annexia.org> wrote:
I was trying to break up a = large ocaml interpreted script:

=C2=A0 https://github.com/libgue= stfs/libnbd/blob/master/generator/generator

The script contains sections like:

=C2=A0 module Foo : sig
=C2=A0 (* type signature *)
=C2=A0 end =3D struct
=C2=A0 (* very long implementation *)
=C2=A0 end

and it would be convenient for me to move the implementations into
separate files.=C2=A0 However this doesn't work:

=C2=A0 module Foo : sig
=C2=A0 (* type signature *)
=C2=A0 end =3D struct
=C2=A0 #use "implementation.ml"=C2=A0 (* with or without ;; he= re *)
=C2=A0 end

So I guess #use only works for top level statements, which surprised
me and contradicts the documentation here too:

=C2=A0 https://caml= .inria.fr/pub/docs/manual-ocaml/toplevel.html#s%3Atoplevel-directives
I could move the whole module definition to the file, but then I would
lose the advantage of hiding the implementation while keeping the
signature visible in the main file.

Given the constraint that we can't use ocamlc or cppo (because of
minimal build dependencies), are there any alternatives?=C2=A0 My first
thought was C's cpp, but it seems impossible to get that working with #!/usr/bin/env and preserve the "scriptiness" of being able to ju= st do
./generator/generator to run it.

Rich.
--000000000000d53639059fb342cc--