# Most idiomatic way to reference module in signature?

**URL:** https://discuss.ocaml.org/t/most-idiomatic-way-to-reference-module-in-signature/17526
**Category:** Learning
**Created:** [November 25, 2025, 11:05am UTC](https://discuss.ocaml.org/t/most-idiomatic-way-to-reference-module-in-signature/17526 "2025-11-25T11:05:48Z")
**Posts on this page:** 4
**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 25, 2025, 11:05am UTC](https://discuss.ocaml.org/t/most-idiomatic-way-to-reference-module-in-signature/17526/1 "2025-11-25T11:05:48Z")

</div>

Hello,

In my codebase I have a few modules that are parametric on a monad. Some of them are also functors, and receive other parameters that are parametric on this monad, and all arguments must match.  
I see two solutions to enforce that.

First solution:

```ocaml
module type Param = sig
  module MyMonad
  ...
end

module F
  (M: MyMonad)
  (P: Param with module MyMonad = MyMonad) =
struct ... end

```

Second solution:

```ocaml
module Param (M: MyMonad) = struct 
  module type S = sig ... end
end

module F
  (M: MyMonad)
  (P: Param(MyMonad).S) =
struct ... end

```

I prefer the second one, it’s easier to instantiate.  
But 1) is this some footgun I can’t see coming and 2) is there a more idiomatic way of doing this?

---

<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, 2025, 3:46pm UTC](https://discuss.ocaml.org/t/most-idiomatic-way-to-reference-module-in-signature/17526/2 "2025-11-27T15:46:37Z")

</div>

The lack of answers makes me more worried that I’m doing something entirely wrong and unusual here 😅

---

<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 27, 2025, 4:43pm UTC](https://discuss.ocaml.org/t/most-idiomatic-way-to-reference-module-in-signature/17526/3 "2025-11-27T16:43:38Z")

</div>

I have used both approaches, and they do work.

As far as I can see, the first variant is quite more common.  
However I would recommend to use a destructive substitution in this case

```ocaml
module F
  (M: MyMonad)
  (P: Param with module MyMonad := MyMonad) = ...

```

to avoid carrying around copies of modules (which can interfere with applicative functors).

Personally, I tend to switch to the functor variant once the module type dependencies start to get complicated.

---

<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, 2025, 9:57am UTC](https://discuss.ocaml.org/t/most-idiomatic-way-to-reference-module-in-signature/17526/4 "2025-11-28T09:57:31Z")

</div>

Great thank you very much!  
Didn’t think about the destructive subst for some reason 🤔
