Hi,

Do you need to expose that B.t and = A.t are the same?

Because if you don't it work= s.

\$ cat > a.ml
type t =3D Foo of int
let x : t =3D Foo 3
\$ cat > b.ml
type t =3D A.t
<= span style=3D"font-size:12.8px">let x2 =3D A.x
\$ cat > p.mli
module B : sig type = t val x2 : t end
\$ ocamlc -for-pack P -c a.ml= =C2=A0b.ml
\$ ocamlc -c p.mli
\$ ocamlc -pack -o p.cmo a.cmo b.cmo
<= br>

If you need to expose the type equality you ca= n make it work by adding the signature of the module A while still keeping = A.t abstract in p.mli (or not, depending on your needs)

\$ cat > a= .ml
type t =3D Foo of int
let x : t =3D Foo 3
\$ cat > b.m= l
type t =3D A.t
let x2 =3D A.x
\$ cat > p.mli
module A : sig type= t end
modul= e B : sig type t =3D A.t val x2 : t end
\$ ocamlc -for-pack P -c a.ml=C2=A0b.ml
\$ ocamlc -c p.mli
\$ ocamlc -pack -o p.= cmo a.cmo b.cmo

I hope it helps.

2018-04-27 10:53 GMT+02:00 = Jun Inoue :
Hi Jacques,

OCaml gives a type error if a public type in b.ml references a
non-trivial type in a.ml.=C2=A0 Is there a way around this?

\$ cat > a.m= l
type t =3D Foo of int
let x : t =3D Foo 3
\$ cat > b.m= l
type t =3D A.t
let x2 =3D A.x
\$ cat > p.mli
module B : sig type t =3D A.t val x2 : t end
\$ ocamlc -for-pack P -c a.ml b.ml
\$ ocamlc -c p.mli
\$ ocamlc -pack -o p.cmo a.cmo b.cmo
File "_none_", line 1:
Error: The implementation (obtained by packing)
=C2=A0 =C2=A0 =C2=A0 =C2=A0does not match the interface p.mli:
=C2=A0 =C2=A0 =C2=A0 =C2=A0In module B:
=C2=A0 =C2=A0 =C2=A0 =C2=A0Modules do not match:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sig type t =3D A.t val x2 : A.t end
=C2=A0 =C2=A0 =C2=A0 =C2=A0is not included in
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sig type t =3D A.t val x2 : t end
=C2=A0 =C2=A0 =C2=A0 =C2=A0In module B:
=C2=A0 =C2=A0 =C2=A0 =C2=A0Type declarations do not match:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0type t =3D A.t
=C2=A0 =C2=A0 =C2=A0 =C2=A0is not included in
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0type t =3D A.t

On Fri, Apr 27, 2018 at 3:05 PM, Jacques Garrigue
<garrigue@math.nagoya-u.= ac.jp> wrote:
> You can provide a mli for the -pack.
> Just compile it before.
>
> \$ cat > a.ml
> type t =3D int
> let x : int =3D 3
> \$ cat > b.ml
> let x2 =3D A.x * A.x
> \$ ocamlc -for-pack P a.ml b.ml
> \$ cat > p.mli
> module A : sig type t val x : t end
> module B : sig val x2 : int end
> \$ ocamlc -c p.mli
> \$ ocamlc -pack -o p.cmo a.cmo b.cmo
>
> Now, if you use your library with only p.cmo and p.cmi available, you = will
> only be able to access it through the interface you provided.
>
> Also, the method using module aliases can work too: you just have
> to use longer file names for the internal modules, to reduce the risk = of
> conflicts. But this is more involved than using -pack with a mli.
>
> Jacques Garrigue
>
> On 2018/04/27 14:48, Jun Inoue wrote:
>>
>> Hi Ivan,
>>
>> That's basically our current approach, but it doesn't solv= e the
>> namespace pollution problem.=C2=A0 In your example, when someone i= nstalls a
>> file named b.cmi (whose interface is unrelated to your b.ml), the name
>>
>> \$ ocaml
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 OCaml version 4.04.0
>>
>> # #show B;;
>> module B : sig val foo : int end
>> The files std.cma and b.cmi disagree over interface B
>>
>> So the technique makes B inaccessible but doesn't remove it fr= om the
>> namespace.=C2=A0 This is why we want to -pack things, because our = analogue
>> of b.= ml is named matrix.ml, and there's no other sensible name for it.
>>
>> This technique doesn't work with -pack because that option dem= ands all
>> .cmi's, including b.cmi.=C2=A0 I guess we could rename matrix.ml to=
>> matrix_internal_dont_touch.ml, but we wanted to kno= w if there's a
>> cleaner approach.=C2=A0 I wish we could supply a .mli file to the = product
>> of -pack, but that also doesn't work...
>>
>> On Fri, Apr 27, 2018 at 12:06 AM, Ivan Gotovchits <ivg@ieee.org> wrote:
>>> Hi Jun,
>>>
>>> You can achieve this by implying an extra layer of indirection= , i.e., by
>>> having two levels of interfaces. For example,
>>>
>>>=C2=A0 =C2=A0* A.ml - implementation of module A
>>>=C2=A0 =C2=A0* A.mli - private interface of module A
>>>=C2=A0 =C2=A0* B.ml=C2=A0 - implementation of module B 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* 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 th= is)
>>>
>>> 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 th= is approach
>>> instead of it. This is how we address the same issue in [BAP][= 1]
>>>
>>> Cheers,
>>> Ivan
>>>
>>> [1]: https://github.com/BinaryAnalysi= sPlatform/bap
>>>
>>>
>>> On Thu, Apr 26, 2018 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, y= et 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/sundia= lsml/).
>>>>
>>>> Basically, we have a type declared in one module of the li= brary that
>>>> is pattern-matched upon in other modules, like:
>>>>
>>>> (* private.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 o= paque_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 opti= on).
>>>> - To avoid namespace pollution, we want to pack the whole = library
>>>> (with ocamlc -pack) as a single Sundials module, so the us= er 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/cam= l-list
>>>> Beginner's list: http://groups.yah= oo.com/group/ocaml_beginners
>>>> Bug reports: http://caml.inria.fr/bin/caml-b= ugs
>
>
>

--
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