caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Private modules in packages
@ 2010-05-21  8:32 Hans Ole Rafaelsen
  2010-05-21  8:51 ` [Caml-list] " Michaël Grünewald
  2010-05-21  8:53 ` Julien Signoles
  0 siblings, 2 replies; 8+ messages in thread
From: Hans Ole Rafaelsen @ 2010-05-21  8:32 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 519 bytes --]

Hi,

When packing a set of modules into a top module using -pack, is there a way
to have some of the modules private to the package?

If I have the modules Helper, Foo and Bar. Helper provides helper functions
used by Foo and Bar. When I'm packing them into a top mudule P, I do not
want to expose the functions of Helper to users of P.

Is there some way to achieve this?  If not, do anyone know of other ways for
packing libraries and keeping some of the modules private to the library?


Thanks,

Hans Ole Rafaelsen

[-- Attachment #2: Type: text/html, Size: 563 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Private modules in packages
  2010-05-21  8:32 Private modules in packages Hans Ole Rafaelsen
@ 2010-05-21  8:51 ` Michaël Grünewald
  2010-05-21  8:53 ` Julien Signoles
  1 sibling, 0 replies; 8+ messages in thread
From: Michaël Grünewald @ 2010-05-21  8:51 UTC (permalink / raw)
  To: Hans Ole Rafaelsen; +Cc: caml-list

Hi Hans,
Hans Ole Rafaelsen wrote:

> When packing a set of modules into a top module using -pack, is there 
> a way to have some of the modules private to the package?
>
> If I have the modules Helper, Foo and Bar. Helper provides helper 
> functions used by Foo and Bar. When I'm packing them into a top mudule 
> P, I do not want to expose the functions of Helper to users of P.
>
> Is there some way to achieve this?  If not, do anyone know of other 
> ways for packing libraries and keeping some of the modules private to 
> the library?

IIRC you have to write an interface file (MLI) for the package.
-- 
Regards,
Michael


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Private modules in packages
  2010-05-21  8:32 Private modules in packages Hans Ole Rafaelsen
  2010-05-21  8:51 ` [Caml-list] " Michaël Grünewald
@ 2010-05-21  8:53 ` Julien Signoles
  2010-05-21  9:51   ` Hans Ole Rafaelsen
  1 sibling, 1 reply; 8+ messages in thread
From: Julien Signoles @ 2010-05-21  8:53 UTC (permalink / raw)
  To: Hans Ole Rafaelsen; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1266 bytes --]

Hello,

2010/5/21 Hans Ole Rafaelsen <hrafaelsen@gmail.com>

> When packing a set of modules into a top module using -pack, is there a way
> to have some of the modules private to the package?
>
> If I have the modules Helper, Foo and Bar. Helper provides helper functions
> used by Foo and Bar. When I'm packing them into a top mudule P, I do not
> want to expose the functions of Helper to users of P.
>
> Is there some way to achieve this?  If not, do anyone know of other ways
> for packing libraries and keeping some of the modules private to the
> library?
>

Just write yourself a file p.mli without your private modules:
=== p.mli ===
module Foo : ...
module Bar : ...
==========
Of course, you can not refer to signatures of modules Foo and Bar in p.mli.
Thus you have to duplicate them or, better, to write them somewhere outside
the package.

>From a compilation point of view, be sure to generate p.cmi by using p.mli
before generating the pack files p.cm[ox].

We use such a trick in the Frama-C tool (http://frama-c.com) for providing
(usually empty) interfaces of its plug-ins. But I do not recommend you to
read the Frama-C Makefiles for looking at the corresponding compilation
lines (except if you are **very** motivated).

Hope this helps,
Julien

[-- Attachment #2: Type: text/html, Size: 1642 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Private modules in packages
  2010-05-21  8:53 ` Julien Signoles
@ 2010-05-21  9:51   ` Hans Ole Rafaelsen
  2010-05-21 13:54     ` Ashish Agarwal
  0 siblings, 1 reply; 8+ messages in thread
From: Hans Ole Rafaelsen @ 2010-05-21  9:51 UTC (permalink / raw)
  To: Julien Signoles, Michael.Grunewald; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1761 bytes --]

Thanks Michael and Julien,

That did the trick. I manually inserted the content of the Bar.mli and
Foo.mli into the P.mli file. Guess unless it is some way to include this
automatically the best will be to write a script to generate the P.mli file
automatically based on current version of Bar.mli and Foo.mli as part of the
build process.

-- 
Hans Ole

On Fri, May 21, 2010 at 10:53 AM, Julien Signoles <julien.signoles@gmail.com
> wrote:

> Hello,
>
> 2010/5/21 Hans Ole Rafaelsen <hrafaelsen@gmail.com>
>
> When packing a set of modules into a top module using -pack, is there a way
>> to have some of the modules private to the package?
>>
>> If I have the modules Helper, Foo and Bar. Helper provides helper
>> functions used by Foo and Bar. When I'm packing them into a top mudule P, I
>> do not want to expose the functions of Helper to users of P.
>>
>> Is there some way to achieve this?  If not, do anyone know of other ways
>> for packing libraries and keeping some of the modules private to the
>> library?
>>
>
> Just write yourself a file p.mli without your private modules:
> === p.mli ===
> module Foo : ...
> module Bar : ...
> ==========
> Of course, you can not refer to signatures of modules Foo and Bar in p.mli.
> Thus you have to duplicate them or, better, to write them somewhere outside
> the package.
>
> From a compilation point of view, be sure to generate p.cmi by using p.mli
> before generating the pack files p.cm[ox].
>
> We use such a trick in the Frama-C tool (http://frama-c.com) for providing
> (usually empty) interfaces of its plug-ins. But I do not recommend you to
> read the Frama-C Makefiles for looking at the corresponding compilation
> lines (except if you are **very** motivated).
>
> Hope this helps,
> Julien
>

[-- Attachment #2: Type: text/html, Size: 2445 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Private modules in packages
  2010-05-21  9:51   ` Hans Ole Rafaelsen
@ 2010-05-21 13:54     ` Ashish Agarwal
  2010-05-21 15:42       ` Julien Signoles
  0 siblings, 1 reply; 8+ messages in thread
From: Ashish Agarwal @ 2010-05-21 13:54 UTC (permalink / raw)
  To: Hans Ole Rafaelsen; +Cc: Julien Signoles, Michael.Grunewald, caml-list

[-- Attachment #1: Type: text/plain, Size: 2338 bytes --]

> write a script to generate the P.mli file

Why do you need Bar.mli and Foo.mli at all? Just write the P.mli only.


On Fri, May 21, 2010 at 5:51 AM, Hans Ole Rafaelsen <hrafaelsen@gmail.com>wrote:

> Thanks Michael and Julien,
>
> That did the trick. I manually inserted the content of the Bar.mli and
> Foo.mli into the P.mli file. Guess unless it is some way to include this
> automatically the best will be to write a script to generate the P.mli file
> automatically based on current version of Bar.mli and Foo.mli as part of the
> build process.
>
> --
> Hans Ole
>
>
> On Fri, May 21, 2010 at 10:53 AM, Julien Signoles <
> julien.signoles@gmail.com> wrote:
>
>> Hello,
>>
>> 2010/5/21 Hans Ole Rafaelsen <hrafaelsen@gmail.com>
>>
>> When packing a set of modules into a top module using -pack, is there a
>>> way to have some of the modules private to the package?
>>>
>>> If I have the modules Helper, Foo and Bar. Helper provides helper
>>> functions used by Foo and Bar. When I'm packing them into a top mudule P, I
>>> do not want to expose the functions of Helper to users of P.
>>>
>>> Is there some way to achieve this?  If not, do anyone know of other ways
>>> for packing libraries and keeping some of the modules private to the
>>> library?
>>>
>>
>> Just write yourself a file p.mli without your private modules:
>> === p.mli ===
>> module Foo : ...
>> module Bar : ...
>> ==========
>> Of course, you can not refer to signatures of modules Foo and Bar in
>> p.mli. Thus you have to duplicate them or, better, to write them somewhere
>> outside the package.
>>
>> From a compilation point of view, be sure to generate p.cmi by using p.mli
>> before generating the pack files p.cm[ox].
>>
>> We use such a trick in the Frama-C tool (http://frama-c.com) for
>> providing (usually empty) interfaces of its plug-ins. But I do not recommend
>> you to read the Frama-C Makefiles for looking at the corresponding
>> compilation lines (except if you are **very** motivated).
>>
>> Hope this helps,
>> Julien
>>
>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>

[-- Attachment #2: Type: text/html, Size: 3630 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Private modules in packages
  2010-05-21 13:54     ` Ashish Agarwal
@ 2010-05-21 15:42       ` Julien Signoles
  2010-05-21 18:04         ` Goswin von Brederlow
  0 siblings, 1 reply; 8+ messages in thread
From: Julien Signoles @ 2010-05-21 15:42 UTC (permalink / raw)
  To: Ashish Agarwal; +Cc: Hans Ole Rafaelsen, Michael.Grunewald, caml-list

[-- Attachment #1: Type: text/plain, Size: 414 bytes --]

Hello,

2010/5/21 Ashish Agarwal <agarwal1975@gmail.com>

> > write a script to generate the P.mli file
>
> Why do you need Bar.mli and Foo.mli at all? Just write the P.mli only.
>

If your pack is big, you may want to mask internals of Bar and Foo to others
modules of the pack. Actually, values exported in Bar/Foo but not in P
exactly are the module counterparts of "friend methods" in OO languages.

--
Julien

[-- Attachment #2: Type: text/html, Size: 1099 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Private modules in packages
  2010-05-21 15:42       ` Julien Signoles
@ 2010-05-21 18:04         ` Goswin von Brederlow
  2010-05-21 19:52           ` Julien Signoles
  0 siblings, 1 reply; 8+ messages in thread
From: Goswin von Brederlow @ 2010-05-21 18:04 UTC (permalink / raw)
  To: Julien Signoles; +Cc: Ashish Agarwal, Michael.Grunewald, caml-list

Julien Signoles <julien.signoles@gmail.com> writes:

> Hello,
>
> 2010/5/21 Ashish Agarwal <agarwal1975@gmail.com>
>
>     > write a script to generate the P.mli file
>
>     Why do you need Bar.mli and Foo.mli at all? Just write the P.mli only.
>
>
> If your pack is big, you may want to mask internals of Bar and Foo to others
> modules of the pack. Actually, values exported in Bar/Foo but not in P exactly
> are the module counterparts of "friend methods" in OO languages.

But then, if you have methods in Bar and Foo visible inside the pack but
not from outside, you can't just cat Bar.mli and Foo.mli into
P.mli. You need to process it to remove the 'friends' functions.

Doesn't batteries have some script for this?

MfG
        Goswin


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Private modules in packages
  2010-05-21 18:04         ` Goswin von Brederlow
@ 2010-05-21 19:52           ` Julien Signoles
  0 siblings, 0 replies; 8+ messages in thread
From: Julien Signoles @ 2010-05-21 19:52 UTC (permalink / raw)
  To: Goswin von Brederlow; +Cc: Ashish Agarwal, Michael.Grunewald, caml-list

[-- Attachment #1: Type: text/plain, Size: 1168 bytes --]

2010/5/21 Goswin von Brederlow <goswin-v-b@web.de>

> Julien Signoles <julien.signoles@gmail.com> writes:
>
> > Hello,
> >
> > 2010/5/21 Ashish Agarwal <agarwal1975@gmail.com>
> >
> >     > write a script to generate the P.mli file
> >
> >     Why do you need Bar.mli and Foo.mli at all? Just write the P.mli
> only.
> >
> >
> > If your pack is big, you may want to mask internals of Bar and Foo to
> others
> > modules of the pack. Actually, values exported in Bar/Foo but not in P
> exactly
> > are the module counterparts of "friend methods" in OO languages.
>
> But then, if you have methods in Bar and Foo visible inside the pack but
> not from outside, you can't just cat Bar.mli and Foo.mli into
> P.mli. You need to process it to remove the 'friends' functions.
>

You can do something like that (pure ocaml without any external script):

=== file baz.mli (outside the pack P) ===
module type Foo = sig ... (* my public values here *) end

=== file p.mli ===
module Foo: Baz.Foo

=== file foo.mli ===
include Baz.Foo
... (* my friend values *)

=== file foo.ml ===
... (* all my internals: defining my public+friends+private values *)

Hope this helps,
Julien

[-- Attachment #2: Type: text/html, Size: 2133 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-05-21 19:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-21  8:32 Private modules in packages Hans Ole Rafaelsen
2010-05-21  8:51 ` [Caml-list] " Michaël Grünewald
2010-05-21  8:53 ` Julien Signoles
2010-05-21  9:51   ` Hans Ole Rafaelsen
2010-05-21 13:54     ` Ashish Agarwal
2010-05-21 15:42       ` Julien Signoles
2010-05-21 18:04         ` Goswin von Brederlow
2010-05-21 19:52           ` Julien Signoles

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).