# Introduction to the module system

**URL:** <https://discuss.ocaml.org/t/introduction-to-the-module-system/6760>\
**Category:** Learning\
**Created:** [November 13, 2020, 5:20pm UTC](https://discuss.ocaml.org/t/introduction-to-the-module-system/6760 "2020-11-13T17:20:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [November 13, 2020, 5:20pm UTC](https://discuss.ocaml.org/t/introduction-to-the-module-system/6760/1 "2020-11-13T17:20:05Z")

</div>

Stephen Diehl has started a series of blog posts about [module systems](https://www.stephendiehl.com/posts/exotic01.html) using OCaml as an example. This provides a nice introduction to the finer points.

---

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [November 14, 2020, 10:33am UTC](https://discuss.ocaml.org/t/introduction-to-the-module-system/6760/2 "2020-11-14T10:33:56Z")

</div>

I believe the last example in the blog aims to demonstrate that generative functors create new (incompatible) types.

> a _generative functor_ which is denoted by an extra parameter `()` which will produce an output module containing non-equal abstract types

But this is not the case here. Maybe I’m misunderstanding the point of the example.

```auto
module FA = F(A);;
module type S = sig type t val s : t end
module A : S
module F : functor (M : S) -> sig type a = M.t val b : a end
module FA : sig type a = A.t val b : a end
module GA = G(A)();;
module G : functor (M : S) () -> sig type a = M.t val b : a end
module GA : sig type a = FA.a val b : a end

utop # FA.b = GA.b;;
- : bool = true

```

---

<div class="post-metadata">

**Author:** ![SkySkimmer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/skyskimmer/32/1672_2.png) [@SkySkimmer](https://discuss.ocaml.org/u/SkySkimmer)\
**Post date:** [November 14, 2020, 11:08am UTC](https://discuss.ocaml.org/t/introduction-to-the-module-system/6760/3 "2020-11-14T11:08:38Z")

</div>

`G.a` isn’t abstract.

> a generative functor which is denoted by an extra parameter () which will produce an output module containing non-equal abstract types

means “if the functor produces an abstract type `t`, separate applications will make the resulting `t`s not equal”

---

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [November 14, 2020, 11:11am UTC](https://discuss.ocaml.org/t/introduction-to-the-module-system/6760/4 "2020-11-14T11:11:48Z")

</div>

Yes. So the example given in the article doesn’t demonstrate what it talks about. Which is a bit unexpected.

---

<div class="post-metadata">

**Author:** ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)\
**Post date:** [November 14, 2020, 1:49pm UTC](https://discuss.ocaml.org/t/introduction-to-the-module-system/6760/5 "2020-11-14T13:49:48Z")

</div>

It is not a matter of abstract types or not but a question of definitions

```ocaml
module F() = struct
   type t = A | B
end
module M = F()
module N = F()
let error = [M.A;N.A] 

```

compared to abbreviations

```ocaml
type original = A | B | C
module F () = struct
  type t = original = A | B | C
end
module M = F()
module N = F()
let ok = [M.A; N.A]

```
