# Correct way to reference module.t

**URL:** <https://discuss.ocaml.org/t/correct-way-to-reference-module-t/4452>\
**Category:** Learning\
**Tags:** module, functor\
**Created:** [September 27, 2019, 2:17pm UTC](https://discuss.ocaml.org/t/correct-way-to-reference-module-t/4452 "2019-09-27T14:17:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cjen1](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cjen1/32/1731_2.png) [@Cjen1](https://discuss.ocaml.org/u/Cjen1)\
**Post date:** [September 27, 2019, 2:17pm UTC](https://discuss.ocaml.org/t/correct-way-to-reference-module-t/4452/1 "2019-09-27T14:17:53Z")

</div>

I’m currently working with functors in a library and often I want to do something like:

```
type t

module T = Functor (struct 
  type t = t
end)

```

However invariably I have to create a temporary type to prevent the shadowing:

```
type t

type tt = t
module T = Functor(struct
  type t = tt
end)

```

Is there a more correct way to do this?

Additionally the

```
Functor(struct
...
end)

```

feels quite clunky (two delimiters) is there any way to clean this up?

---

<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:** [September 27, 2019, 2:32pm UTC](https://discuss.ocaml.org/t/correct-way-to-reference-module-t/4452/2 "2019-09-27T14:32:04Z")

</div>

```ocaml
type t
module T = Bla (struct type nonrec t = t end)

```

---

<div class="post-metadata">

**Author:** ![Cjen1](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cjen1/32/1731_2.png) [@Cjen1](https://discuss.ocaml.org/u/Cjen1)\
**Post date:** [September 27, 2019, 2:35pm UTC](https://discuss.ocaml.org/t/correct-way-to-reference-module-t/4452/3 "2019-09-27T14:35:26Z")

</div>

> [@SkySkimmer](#):
>
> ```auto
> module T = Bla (struct type nonrec t = t end)
> 
> ```

Ah so the `nonrec` keyword removes the shadowing issue?

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [September 27, 2019, 2:40pm UTC](https://discuss.ocaml.org/t/correct-way-to-reference-module-t/4452/4 "2019-09-27T14:40:25Z")

</div>

Type definitions are recursive by default – you can mention the type you are defining on the right-hand side of the definition.

`type nonrec` makes it non recursive, so in `type nonrec t = t` it looks for the `t` that is currently in scope not the one you are defining and the one that is scope is the one that came just before.

The opposite is true for values: `let` is not recursive by default, you have to use `let rec` if you want to use the name you are defining on the right-hand side.
