Correct way to reference module.t

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

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

Is there a more correct way to do this?

Additionally the


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

type t
module T = Bla (struct type nonrec t = t end)
1 Like

Ah so the nonrec keyword removes the shadowing issue?

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.