# Exposing modules in library

**URL:** <https://discuss.ocaml.org/t/exposing-modules-in-library/2962>\
**Category:** Learning\
**Tags:** dune\
**Created:** [November 27, 2018, 11:10pm UTC](https://discuss.ocaml.org/t/exposing-modules-in-library/2962 "2018-11-27T23:10:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![giltho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/giltho/32/3521_2.png) [@giltho](https://discuss.ocaml.org/u/giltho)\
**Post date:** [November 27, 2018, 11:10pm UTC](https://discuss.ocaml.org/t/exposing-modules-in-library/2962/1 "2018-11-27T23:10:34Z")

</div>

Hello,

I’ve been developing on OCaml projects for some time now, however, it is my first time writing an OCaml library using dune.

My main issue is that I want my library to expose several modules (in particular, some modules contains functions / functors that can be used by the users, and other modules contains types (and related functions) that should be used to construct parameters for said functions / functors.

What is the best practice for doing this ?  
The solution I use is simply to import these modules in the main library file, which will contain

```
module FirstExposedMod = FirstExposedMod
module SecondExposedMod = SecondExposedMod
module ThirdExposedMod = ThirdExposedMod
module FourthExposedMod = FourthExposedMod

```

Is it the best way of doing things ? I haven’t been able to find informations on that anywhere.

Thank you very much !

---

<div class="post-metadata">

**Author:** ![jeremiedimino](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jeremiedimino/32/699_2.png) [@jeremiedimino](https://discuss.ocaml.org/u/jeremiedimino)\
**Post date:** [November 28, 2018, 10:20am UTC](https://discuss.ocaml.org/t/exposing-modules-in-library/2962/2 "2018-11-28T10:20:05Z")

</div>

Hi @giltho,

If you want to expose all of the modules of your library, then you can simply skip writing a main library file, and dune will simply expose all the modules.

If you want to hide a few of them because they are private, then you can use the `private_modules` field:

```auto
(library
 (name foo)
 (private_modules common utils))

```

Writing an explicit main library file is only relevant in the following cases:

- when you want to expose some modules with a different name/path, for instance `module X = Foo.Bar.X`
- when you want to have toplevel values in your library
- when you simply want to expose a different API to the outside world

I hope that answers your question.

---

<div class="post-metadata">

**Author:** ![giltho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/giltho/32/3521_2.png) [@giltho](https://discuss.ocaml.org/u/giltho)\
**Post date:** [November 28, 2018, 10:34am UTC](https://discuss.ocaml.org/t/exposing-modules-in-library/2962/3 "2018-11-28T10:34:47Z")

</div>

Hi @jeremiedimino,

This answers my question perfectly thank you very much.  
Dune keeps surprising me with its elegance as I use it.

Thank you !

---

<div class="post-metadata">

**Author:** ![UnixJunkie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/unixjunkie/32/638_2.png) [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Post date:** [November 29, 2018, 9:12am UTC](https://discuss.ocaml.org/t/exposing-modules-in-library/2962/4 "2018-11-29T09:12:10Z")

</div>

Since when do we have private\_modules?  
I needed that one.

---

<div class="post-metadata">

**Author:** ![emillon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/emillon/32/1206_2.png) [@emillon](https://discuss.ocaml.org/u/emillon)\
**Post date:** [November 29, 2018, 9:15am UTC](https://discuss.ocaml.org/t/exposing-modules-in-library/2962/5 "2018-11-29T09:15:03Z")

</div>

It was added in 1.2.0; you can find [the full changelog here](https://github.com/ocaml/dune/blob/master/CHANGES.md).
