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 5EF9E5D5 for ; Thu, 26 Apr 2018 15:06:38 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.49,330,1520895600"; d="scan'208,217";a="324617789" Received: from sympa.inria.fr ([193.51.193.213]) by mail2-relais-roc.national.inria.fr with ESMTP; 26 Apr 2018 17:06:36 +0200 Received: by sympa.inria.fr (Postfix, from userid 20132) id 73CE682451; Thu, 26 Apr 2018 17:06:36 +0200 (CEST) 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 C2B7382416 for ; Thu, 26 Apr 2018 17:06:24 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=ivg@ieee.org; spf=Pass smtp.mailfrom=ivg@ieee.org; spf=None smtp.helo=postmaster@mail-lf0-f47.google.com IronPort-PHdr: =?us-ascii?q?9a23=3ArNHxqBBduNXTnKtQzq3/UyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSPTyosbcNUDSrc9gkEXOFd2Cra4c0KyO6+jJYi8p2d65qncMcZhBBVcuqP?= =?us-ascii?q?49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6?= =?us-ascii?q?JvjvGo7Vks+7y/2+94fcbglUijexe69+IAmrpgjNq8cahpdvJLwswRXTuHtIfO?= =?us-ascii?q?pWxWJsJV2Nmhv3+9m98p1+/SlOovwt78FPX7n0cKQ+VrxYES8pM3sp683xtBnM?= =?us-ascii?q?VhWA630BWWgLiBVIAgzF7BbnXpfttybxq+Rw1DWGMcDwULs5Qiqp4bt1RxD0iS?= =?us-ascii?q?cHLz85/3/Risxsl6JQvRatqwViz4LIfI2ZMfxzcaTAc9MHXmpBRtheWDBdAo2y?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Iton40+Jn1lEtDntSjtmjKwCuZNxb2GCZFy9bjTjSCoepRNjk3e3a?= =?us-ascii?q?xktGEIB8tCMWr82/x6/gnXQorHywCXy/nseqMb0yrAsmyEyDjWsQ=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DEAACk6eFahi/XVdFbGwEBAQEDAQEBC?= =?us-ascii?q?QEBAYNnPRdjKAqDYYEdk1yBdIEPgUAnhQuHMYUEgQ4DUwsjgxKBNwKCPQcZBwE?= =?us-ascii?q?ENBQBAgEBAQEBAQEBARMBAQEICwsIKCMMgjUkgkoBAgIBIwQZAQEsCwEECwsLG?= =?us-ascii?q?h0CAiEBEgEFAQoSBhMShGUDCAUID5w+PIoYbYFpM4JvAQEFhBcDCoErgj0IEod?= =?us-ascii?q?/gVQ/g2wugk83CwICgRgOZYJTglSGEAh8kEssCIVjhWiCfYFximSJPUWGKg8DH?= =?us-ascii?q?oEEDCeBc30IOw0NFwaCDAmBZyQaGoM0gT6BJoE8hk4jMAGOdII3AQE?= X-IPAS-Result: =?us-ascii?q?A0DEAACk6eFahi/XVdFbGwEBAQEDAQEBCQEBAYNnPRdjKAq?= =?us-ascii?q?DYYEdk1yBdIEPgUAnhQuHMYUEgQ4DUwsjgxKBNwKCPQcZBwEENBQBAgEBAQEBA?= =?us-ascii?q?QEBARMBAQEICwsIKCMMgjUkgkoBAgIBIwQZAQEsCwEECwsLGh0CAiEBEgEFAQo?= =?us-ascii?q?SBhMShGUDCAUID5w+PIoYbYFpM4JvAQEFhBcDCoErgj0IEod/gVQ/g2wugk83C?= =?us-ascii?q?wICgRgOZYJTglSGEAh8kEssCIVjhWiCfYFximSJPUWGKg8DHoEEDCeBc30IOw0?= =?us-ascii?q?NFwaCDAmBZyQaGoM0gT6BJoE8hk4jMAGOdII3AQE?= X-IronPort-AV: E=Sophos;i="5.49,330,1520895600"; d="scan'208,217";a="324617662" Received: from mail-lf0-f47.google.com ([209.85.215.47]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 26 Apr 2018 17:06:23 +0200 Received: by mail-lf0-f47.google.com with SMTP id b23-v6so31289204lfg.4 for ; Thu, 26 Apr 2018 08:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ieee-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=o01+kuPe7Gjo20y53kbnp56K4dNEJ33ZHbMLVv/bV4g=; b=Ui6ESTtO4Ev52g0j626rTAisFDktcTom2fHehwTE4IQWTRIpbgbelHV8lNkEoKI4ih CewABGiP8zL8ZaqI8AS1LaF7W2LQyJRLjaxueWvXIwVNJpvYTfIxoc3Ccxbl+4Un6Bso RS6ReCLMtVYdWrSm96FkwCn61UlALEn4HWJDo4XSa6+lYYRbJv3h9/WVJoYoA4uXCl7/ hgY5rh22+IiabkBi0ujyJvOzm2NERpJUhSNRtTs2NpX4VkB5ZkiLVt7ClJ3TjZLoaDNb 1QVggZzBc4ZeY6W/p4RHATJ1QxZWQ5hoM1uhmRfSPcY3AF1EEyc+9+p4bzEfwqV45QOy KuFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=o01+kuPe7Gjo20y53kbnp56K4dNEJ33ZHbMLVv/bV4g=; b=Ai1LAfn84R4lD1vuLb6FydX7vMfIU0hDu2eHCRVA/QbewG3eEFDYZOhJtpgB5mVbqT FF/BO2FpTCTenUY9lDlCpSnp6HqkJThAXt5GVrLIUS13IEnGnDqyL6jMJepxCwQcqHB4 ia4z/5U9zwhwqpzz5stROKO10fE/uGQQkSEjqJzXDia3TbORv+7eu4pHDNEK7FeN66nO 86P+IziIi2E/NnN/6R6Yzn8iYwGfILpXrU1H5piYC/OA66D+S79cBxt6i03H9TvsayHK PKKpsjr3MyUJBcIYU3ZavyqGiMlfpAKEP0lWgxlvthVBshyKSb2qVDBuUR6ImstSNZYt I3pQ== X-Gm-Message-State: ALQs6tDskR6pV6+R9q7AfvDWCCXX1hn3X+Xsd5k5iVTWYz9Rzhmoqy2O zP7gp/njoLVq0s6QrhY93DM+rZpQETwvUQxWz/Ef1Q== X-Google-Smtp-Source: AIpwx48lwMQ7N/3BUzoHMJty9R2RoQhHuYBUQZ6hpOecUaeyX0ELagV6rgeskjx+0jv6yPE/qXKiojVYxBb08pKq6/U= X-Received: by 10.46.158.5 with SMTP id e5mr23091445ljk.16.1524755182425; Thu, 26 Apr 2018 08:06:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.46.134.68 with HTTP; Thu, 26 Apr 2018 08:06:21 -0700 (PDT) In-Reply-To: References: From: Ivan Gotovchits Date: Thu, 26 Apr 2018 11:06:21 -0400 Message-ID: To: Jun Inoue Cc: caml list Content-Type: multipart/alternative; boundary="883d24f1b2d804bfa6056ac1bbaa" Subject: Re: [Caml-list] Type That's Concrete From Within A Library Abstract From Without Reply-To: Ivan Gotovchits X-Loop: caml-list@inria.fr X-Sequence: 16855 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: --883d24f1b2d804bfa6056ac1bbaa Content-Type: text/plain; charset="UTF-8" Hi Jun, You can achieve this by implying an extra layer of indirection, i.e., by having two levels of interfaces. For example, * A.ml - implementation of module A * A.mli - private interface of module A * B.ml - implementation of module B that may rely on anything in A.mli * Std.ml - a set of modules that you would like to import, e.g., `module A = A`, `module B = B` * Std.mli - public interface specification Next, you deploy `std.cmxa` and `std.cmi` but keep `a.cmi` and `b.cmi` to yourself. This will prevent users from accessing your private modules A and B directly. (In oasis you can use PrivateModules stanza for this) Now you will have `Std.A` and `Std.B` that exposes as much as you want. Not sure whether it will work with the `-pack`, but you can use this approach instead of it. This is how we address the same issue in [BAP][1] Cheers, Ivan [1]: https://github.com/BinaryAnalysisPlatform/bap On Thu, Apr 26, 2018 at 10:18 AM, Jun Inoue wrote: > Dear list, > > Is there a way to make a type concrete inside a library, yet opaque to > library users, preferably in a way that works with -pack? This is a > nagging issue in our sundials package > (http://inria-parkas.github.io/sundialsml/). > > Basically, we have a type declared in one module of the library that > is pattern-matched upon in other modules, like: > > (* private.ml *) > type opaque_type = Foo | Bar > > (* public.ml *) > let f : opaque_type -> int = function > | Foo -> 0 > | Bar -> 1 > > There are a few constraints: > - We don't want users to be able to pattern-match on opaque_type. > - We need multiple modules in the library to pattern-match on > opaque-type (so moving opaque_typ e to public.ml is not an option). > - To avoid namespace pollution, we want to pack the whole library > (with ocamlc -pack) as a single Sundials module, so the user sees a > Sundials.Public module instead of just Public. > > Is this possible? Right now, we just collect public.cmo and > private.cmo into sundials.cma and throw away private.cmi. But this > doesn't work with packing: > > $ ocamlc -pack -o sundials.cmo private.cmo public.cmo > > demands that there be a private.cmi. > > -- > Jun Inoue > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- Caml-list mailing list. Subscription management and archives: https://sympa.inria.fr/sympa/arc/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs --883d24f1b2d804bfa6056ac1bbaa Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Jun,

You can achieve this by i= mplying an extra layer of indirection, i.e., by having two levels of interf= aces. For example,=C2=A0

=C2=A0 =C2=A0* A.ml - implement= ation of module=C2=A0A
=C2=A0 =C2=A0* A.mli=C2=A0- private interf= ace of module=C2=A0A
=C2=A0 =C2=A0* B.ml=C2=A0 - implementation o= f module=C2=A0B that may rely on anything in A.mli
=C2=A0 =C2=A0*= Std.ml - a set of modules that you would like to import, e.g., `module A = =3D A`, `module B =3D B`=C2=A0
=C2=A0 =C2=A0* Std.mli=C2=A0- publ= ic interface specification


Next, yo= u deploy `std.cmxa` and `std.cmi` but keep `a.cmi` and `b.cmi` to yourself.= This will prevent users from accessing your private modules A and B direct= ly. (In oasis you can use PrivateModules stanza for this)

Now you will have `Std.A` and `Std.B` that exposes as much as you w= ant. Not sure whether it will work with the `-pack`, but you can use this a= pproach instead of it. This is how we address the same issue in [BAP][1]

Cheers,
Ivan

=C2=A0 =C2=A0
<= div class=3D"gmail_extra">
On Thu, Apr 26, 20= 18 at 10:18 AM, Jun Inoue <jun.lambda@gmail.com> wrote:
Dear list,

Is there a way to make a type concrete inside a library, yet opaque to
library users, preferably in a way that works with -pack?=C2=A0 This is a nagging issue in our sundials package
(http://inria-parkas.github.io/sundialsml/).

Basically, we have a type declared in one module of the library that
is pattern-matched upon in other modules, like:

(* priva= te.ml *)
type opaque_type =3D Foo | Bar

(* public= .ml *)
let f : opaque_type -> int =3D function
=C2=A0 | Foo -> 0
=C2=A0 | Bar -> 1

There are a few constraints:
- We don't want users to be able to pattern-match on opaque_type.
- We need multiple modules in the library to pattern-match on
opaque-type (so moving opaque_typ e to public.ml is not an option).
- To avoid namespace pollution, we want to pack the whole library
(with ocamlc -pack) as a single Sundials module, so the user sees a
Sundials.Public module instead of just Public.

Is this possible?=C2=A0 Right now, we just collect public.cmo and
private.cmo into sundials.cma and throw away private.cmi.=C2=A0 But this
doesn't work with packing:

$ ocamlc -pack -o sundials.cmo private.cmo public.cmo

demands that there be a private.cmi.

--
Jun Inoue

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

--883d24f1b2d804bfa6056ac1bbaa--