# \#module

**URL:** https://discuss.ocaml.org/tag/module/96.md

[Latest](https://discuss.ocaml.org/latest.md) · [Categories](https://discuss.ocaml.org/categories.md) · [Tags](https://discuss.ocaml.org/tags.md)

---

## [How to achieve implicit state without using classes and objects](https://discuss.ocaml.org/t/how-to-achieve-implicit-state-without-using-classes-and-objects/18582)

<div class="topic-metadata">

**Author:** [@rvdalen](https://discuss.ocaml.org/u/rvdalen)\
**Replies:** 5\
**Last updated:** [October 7, 2026, 1:38am UTC](https://discuss.ocaml.org/t/how-to-achieve-implicit-state-without-using-classes-and-objects/18582 "2026-10-07T01:38:20Z")

</div>

Hi everyone, I am new to OCaml and I am trying to write my own parser library just for fun. The easiest way to start of course is explicitly passing the updated parser state around. For example: let my\_parser (st: To…

---

## [Default argument to functors?](https://discuss.ocaml.org/t/default-argument-to-functors/18157)

<div class="topic-metadata">

**Author:** [@fnfun](https://discuss.ocaml.org/u/fnfun)\
**Replies:** 2\
**Last updated:** [May 22, 2026, 11:05am UTC](https://discuss.ocaml.org/t/default-argument-to-functors/18157 "2026-05-22T11:05:24Z")

</div>

I’m trying to create a functor with a sort of polymorphic default argument, but having no luck. Here’s the failed idea: First, a module with a pretty printer for a container element: module type PP = sig type t …

---

## [\[Real world Ocaml\] Put t first](https://discuss.ocaml.org/t/real-world-ocaml-put-t-first/17721)

<div class="topic-metadata">

**Author:** [@louisono](https://discuss.ocaml.org/u/louisono)\
**Replies:** 13\
**Last updated:** [January 22, 2026, 11:16pm UTC](https://discuss.ocaml.org/t/real-world-ocaml-put-t-first/17721 "2026-01-22T23:16:44Z")

</div>

Hello, I just finished reading the early module chapter of “Real world Ocaml” and wondered about the rationale behind one of the module design guidelines shared towards the end of the chapter (guideline used apparently i…

---

## [A trick to define abstract types without writing down module types](https://discuss.ocaml.org/t/a-trick-to-define-abstract-types-without-writing-down-module-types/17597)

<div class="topic-metadata">

**Author:** [@threepwood](https://discuss.ocaml.org/u/threepwood)\
**Replies:** 5\
**Last updated:** [December 16, 2025, 3:40pm UTC](https://discuss.ocaml.org/t/a-trick-to-define-abstract-types-without-writing-down-module-types/17597 "2025-12-16T15:40:56Z")

</div>

I was amused, perhaps surprised to see that you can define a module with an abstract type without writing down any module types using the following trick where you open an anonymous module (this is copy-pasted from the 5…

---

## [Module definitions are not transparent?](https://discuss.ocaml.org/t/module-definitions-are-not-transparent/16781)

<div class="topic-metadata">

**Author:** [@viritrilbia](https://discuss.ocaml.org/u/viritrilbia)\
**Replies:** 9\
**Last updated:** [June 11, 2025, 8:27pm UTC](https://discuss.ocaml.org/t/module-definitions-are-not-transparent/16781 "2025-06-11T20:27:39Z")

</div>

The following code produces an error: module type Empty = sig end module TT (S : Empty) = struct type t = T end module Mapper (S1 : Empty) (S2 : Empty) = struct module C1 = TT (S1) module C2 = TT (S2) let map…

---

## [How to make two different modules implement the same 'interface'](https://discuss.ocaml.org/t/how-to-make-two-different-modules-implement-the-same-interface/13079)

<div class="topic-metadata">

**Author:** [@Kris\_De\_Volder](https://discuss.ocaml.org/u/Kris_De_Volder)\
**Replies:** 8\
**Last updated:** [May 22, 2025, 4:22pm UTC](https://discuss.ocaml.org/t/how-to-make-two-different-modules-implement-the-same-interface/13079 "2025-05-22T16:22:01Z")

</div>

I am trying to make a library that provides two different implementations of the same interface. But I am getting stuck with a puzzling error that tells me that my second implementation ‘doesn’t match’ the interface. Fo…

---

## [OCaml-like modules using untyped languages](https://discuss.ocaml.org/t/ocaml-like-modules-using-untyped-languages/16663)

<div class="topic-metadata">

**Author:** [@SpiceGuid](https://discuss.ocaml.org/u/SpiceGuid)\
**Replies:** 3\
**Last updated:** [May 19, 2025, 3:08am UTC](https://discuss.ocaml.org/t/ocaml-like-modules-using-untyped-languages/16663 "2025-05-19T03:08:37Z")

</div>

When reading Les Accepteurs : Un nouveau modèle de programmation i realized this tiny untyped language can actually mimic OCaml modules : set-make (Compare) =\> ( nil -\> ( size =\> 0 || add(Item) =\> set(nil,I…

---

## [Is it possible open a module for all files in a dune library or dune project?](https://discuss.ocaml.org/t/is-it-possible-open-a-module-for-all-files-in-a-dune-library-or-dune-project/15611)

<div class="topic-metadata">

**Author:** [@adl](https://discuss.ocaml.org/u/adl)\
**Replies:** 1\
**Last updated:** [November 14, 2024, 8:43pm UTC](https://discuss.ocaml.org/t/is-it-possible-open-a-module-for-all-files-in-a-dune-library-or-dune-project/15611 "2024-11-14T20:43:11Z")

</div>

Let’s say I want to open Base for all files in a dune library or a dune project. Do I have to say open Base in every file or can I tell dune somehow to open Base automatically for all files?

---

## [Properly "include" modules?](https://discuss.ocaml.org/t/properly-include-modules/15235)

<div class="topic-metadata">

**Author:** [@gantsev.denis](https://discuss.ocaml.org/u/gantsev.denis)\
**Replies:** 9\
**Last updated:** [September 5, 2024, 2:26pm UTC](https://discuss.ocaml.org/t/properly-include-modules/15235 "2024-09-05T14:26:55Z")

</div>

Some context: I am writing a json schema validator, as a way to properly learn OCaml; I basically forked ocplib-json-typed and working from that. Now the problem: I would like to have 2 sets of validation functions, the…

---

## [What is an unsafe functor?](https://discuss.ocaml.org/t/what-is-an-unsafe-functor/14204)

<div class="topic-metadata">

**Author:** [@viritrilbia](https://discuss.ocaml.org/u/viritrilbia)\
**Replies:** 9\
**Last updated:** [September 5, 2024, 10:29am UTC](https://discuss.ocaml.org/t/what-is-an-unsafe-functor/14204 "2024-09-05T10:29:04Z")

</div>

I am getting the following error: Error: Cannot safely evaluate the definition of the following cycle of recursively-defined modules: Value -\> Value. There are no safe modules in this cycle (see manual sec…

---

## [Splitting submodules with Dune](https://discuss.ocaml.org/t/splitting-submodules-with-dune/15109)

<div class="topic-metadata">

**Author:** [@Averybadveteran](https://discuss.ocaml.org/u/Averybadveteran)\
**Replies:** 5\
**Last updated:** [August 12, 2024, 11:54am UTC](https://discuss.ocaml.org/t/splitting-submodules-with-dune/15109 "2024-08-12T11:54:40Z")

</div>

Greetings, Second post in here I’ve yet another problem understanding the module system, and how dune make them work. My program contains simple functor called “Trip”, taking two modules as parametric modules : “Train”…

---

## [Troubles using a simple functorised module for a list type](https://discuss.ocaml.org/t/troubles-using-a-simple-functorised-module-for-a-list-type/14835)

<div class="topic-metadata">

**Author:** [@chshersh](https://discuss.ocaml.org/u/chshersh)\
**Replies:** 5\
**Last updated:** [June 23, 2024, 12:54pm UTC](https://discuss.ocaml.org/t/troubles-using-a-simple-functorised-module-for-a-list-type/14835 "2024-06-23T12:54:22Z")

</div>

I’m playing with first-class modules in OCaml, and since I’m still a noob, I stumbled upon a compiler error I can’t resolve on my own. So I’d appreciate any help! :pray: I want to make a simple module for a semigroup li…

---

## [Use a module's abstract type in other compilation unit](https://discuss.ocaml.org/t/use-a-modules-abstract-type-in-other-compilation-unit/14823)

<div class="topic-metadata">

**Author:** [@Averybadveteran](https://discuss.ocaml.org/u/Averybadveteran)\
**Replies:** 9\
**Last updated:** [June 20, 2024, 7:35pm UTC](https://discuss.ocaml.org/t/use-a-modules-abstract-type-in-other-compilation-unit/14823 "2024-06-20T19:35:49Z")

</div>

Greetings, I’m having trouble compilling my program separated in 2 files. The idea is to make a small factory of Item, an abstract type defined in its module (Item). item.ml: module type Item = sig type it…

---

## [How to combine a list of modules?](https://discuss.ocaml.org/t/how-to-combine-a-list-of-modules/14669)

<div class="topic-metadata">

**Author:** [@KazMiller](https://discuss.ocaml.org/u/KazMiller)\
**Replies:** 2\
**Last updated:** [May 20, 2024, 12:32pm UTC](https://discuss.ocaml.org/t/how-to-combine-a-list-of-modules/14669 "2024-05-20T12:32:25Z")

</div>

I would like to know if it is possible to reduce a list of first class modules into one modules. The goal would be to generate the cartesian product of an arbitrary number of algebraic structures. For instance, given a …

---

## [Mismatched types between customized compilation units](https://discuss.ocaml.org/t/mismatched-types-between-customized-compilation-units/14253)

<div class="topic-metadata">

**Author:** [@Marietta\_Galea](https://discuss.ocaml.org/u/Marietta_Galea)\
**Replies:** 7\
**Last updated:** [March 5, 2024, 5:08pm UTC](https://discuss.ocaml.org/t/mismatched-types-between-customized-compilation-units/14253 "2024-03-05T17:08:13Z")

</div>

Hello! I am trying to build a modularized system in OCaml, which consists of two compilation units named Instr and Monitor along with run\_file.ml that makes use of these two modules. Monitor has a function called run\_mo…

---

## [Generic Module Signatures](https://discuss.ocaml.org/t/generic-module-signatures/14223)

<div class="topic-metadata">

**Author:** [@danielkelshaw](https://discuss.ocaml.org/u/danielkelshaw)\
**Replies:** 4\
**Last updated:** [March 1, 2024, 5:22pm UTC](https://discuss.ocaml.org/t/generic-module-signatures/14223 "2024-03-01T17:22:10Z")

</div>

I am currently trying to write an ocaml package to send API requests for a given service. For each endpoint I wish to handle, I produce a module with a record type defining the fields which must be supplied. I then use y…

---

## [Generalised abstract data types, phantom types and modules](https://discuss.ocaml.org/t/generalised-abstract-data-types-phantom-types-and-modules/14211)

<div class="topic-metadata">

**Author:** [@koizel](https://discuss.ocaml.org/u/koizel)\
**Replies:** 2\
**Last updated:** [February 28, 2024, 10:47am UTC](https://discuss.ocaml.org/t/generalised-abstract-data-types-phantom-types-and-modules/14211 "2024-02-28T10:47:03Z")

</div>

Consider the two following code snippets type atp type smt type \_ config = | ConfigSmt : smt config | ConfigAtp : atp config let digest : smt config -\> unit = fun cfg -\> match cfg with ConfigSmt -\> () and modul…

---

## [Qualified imports in OCaml are possible but why aren't they used more?](https://discuss.ocaml.org/t/qualified-imports-in-ocaml-are-possible-but-why-arent-they-used-more/3684)

<div class="topic-metadata">

**Author:** [@sid](https://discuss.ocaml.org/u/sid)\
**Replies:** 7\
**Last updated:** [January 5, 2024, 3:34am UTC](https://discuss.ocaml.org/t/qualified-imports-in-ocaml-are-possible-but-why-arent-they-used-more/3684 "2024-01-05T03:34:40Z")

</div>

I’ve noticed that idiomatic OCaml does not seem to use qualified imports in code very much. Mostly there is the use of open keyword in code or you may have something verbose like Core\_kernel.Map.empty (or shorter Map.emp…

---

## [Draft tutorials on Modules, Functors and Libraries](https://discuss.ocaml.org/t/draft-tutorials-on-modules-functors-and-libraries/13686)

<div class="topic-metadata">

**Author:** [@cuihtlauac](https://discuss.ocaml.org/u/cuihtlauac)\
**Replies:** 10\
**Last updated:** [December 24, 2023, 6:28pm UTC](https://discuss.ocaml.org/t/draft-tutorials-on-modules-functors-and-libraries/13686 "2023-12-24T18:28:40Z")

</div>

Dear OCamlers, The series on ocaml.org tutorial updates continue. This time, the ocaml.org team has three drafts related to the module system in a single pull request. We want your feedback on it: GH PR: Update Modul…

---

## [Reducing duplicate code in modules with parameterized type](https://discuss.ocaml.org/t/reducing-duplicate-code-in-modules-with-parameterized-type/13446)

<div class="topic-metadata">

**Author:** [@cpa](https://discuss.ocaml.org/u/cpa)\
**Replies:** 3\
**Last updated:** [November 18, 2023, 4:25am UTC](https://discuss.ocaml.org/t/reducing-duplicate-code-in-modules-with-parameterized-type/13446 "2023-11-18T04:25:18Z")

</div>

Hello, I found myself writing the following piece of code, and I’m wondering how can I reuse more code and not repeat re-declaring type expr = ... in both modules (since outside of this minimal example this would be a l…

---

## [Maintaining two versions of a module](https://discuss.ocaml.org/t/maintaining-two-versions-of-a-module/12707)

<div class="topic-metadata">

**Author:** [@viritrilbia](https://discuss.ocaml.org/u/viritrilbia)\
**Replies:** 7\
**Last updated:** [July 27, 2023, 10:03pm UTC](https://discuss.ocaml.org/t/maintaining-two-versions-of-a-module/12707 "2023-07-27T22:03:12Z")

</div>

Say I have a module A that is used throughout my code, and I have two possible implementations of this module, say A1 and A2. (Maybe A1 is more obviously correct, while A2 is more efficient.) By declaring A1 and A2 to …

---

## [A module value that we can't create everywhere](https://discuss.ocaml.org/t/a-module-value-that-we-cant-create-everywhere/12689)

<div class="topic-metadata">

**Author:** [@Gholad](https://discuss.ocaml.org/u/Gholad)\
**Replies:** 1\
**Last updated:** [July 25, 2023, 2:38pm UTC](https://discuss.ocaml.org/t/a-module-value-that-we-cant-create-everywhere/12689 "2023-07-25T14:38:57Z")

</div>

Hi ! I’m wondering how can i forbid the creation of a module value implementing a certain module type ? Lets say i have this module : module type Admin = sig end And an another module B which contain a function which …

---

## [When do I need to prefix constructors with the module name?](https://discuss.ocaml.org/t/when-do-i-need-to-prefix-constructors-with-the-module-name/12071)

<div class="topic-metadata">

**Author:** [@hexclover](https://discuss.ocaml.org/u/hexclover)\
**Replies:** 4\
**Last updated:** [May 2, 2023, 6:59pm UTC](https://discuss.ocaml.org/t/when-do-i-need-to-prefix-constructors-with-the-module-name/12071 "2023-05-02T18:59:16Z")

</div>

I had an understanding that, to use a constructor from an module A that is not opened, I have to prefix it with the module name. However, I’ve noticed sometimes OCaml is clever enough to find the correct constructor from…

---

## [Ocaml lsp in vs code gives "unbound module Base"](https://discuss.ocaml.org/t/ocaml-lsp-in-vs-code-gives-unbound-module-base/11936)

<div class="topic-metadata">

**Author:** [@jalanji](https://discuss.ocaml.org/u/jalanji)\
**Replies:** 16\
**Last updated:** [April 14, 2023, 11:56pm UTC](https://discuss.ocaml.org/t/ocaml-lsp-in-vs-code-gives-unbound-module-base/11936 "2023-04-14T23:56:14Z")

</div>

Hi, I have Ocaml switch 4.13.1 running on Mac. utop is working fine, can load the Base module when I do: #use "topfind";; #require "base";; open Base List.mem \["1"\] "1" ~equal:String.equal even though I followed thes…

---

## [\[Q\] Does \`Thread\` module really work?](https://discuss.ocaml.org/t/q-does-thread-module-really-work/11718)

<div class="topic-metadata">

**Author:** [@anzhi0708](https://discuss.ocaml.org/u/anzhi0708)\
**Replies:** 9\
**Last updated:** [March 20, 2023, 10:41am UTC](https://discuss.ocaml.org/t/q-does-thread-module-really-work/11718 "2023-03-20T10:41:49Z")

</div>

Hello guys. I’m both a beginner in OCaml & CS, aka a noob. I wrote this piece of code to test Thread module let () = print\_endline "Hello, World!" let rec fib\_normal (n: int): int = match n with | 0 | 1 -\> n …

---

## [How to refer to 'type t' in later module](https://discuss.ocaml.org/t/how-to-refer-to-type-t-in-later-module/11462)

<div class="topic-metadata">

**Author:** [@zfy](https://discuss.ocaml.org/u/zfy)\
**Replies:** 3\
**Last updated:** [March 2, 2023, 1:29pm UTC](https://discuss.ocaml.org/t/how-to-refer-to-type-t-in-later-module/11462 "2023-03-02T13:29:37Z")

</div>

It seems isn’t a question but I just cannot figure out. As the example below, how to refer to type ‘t’ which is defined before the module scope. many thanks type t = {count:int; value:float} module Temp = struct typ…

---

## [Swapping between different implementations of a signature](https://discuss.ocaml.org/t/swapping-between-different-implementations-of-a-signature/11351)

<div class="topic-metadata">

**Author:** [@Marchhill](https://discuss.ocaml.org/u/Marchhill)\
**Replies:** 3\
**Last updated:** [February 7, 2023, 2:43pm UTC](https://discuss.ocaml.org/t/swapping-between-different-implementations-of-a-signature/11351 "2023-02-07T14:43:50Z")

</div>

I have a library called ‘consensus’ in my project with a signature that is exported defined in the file ‘consensus.mli’. There are two files implementing this signature in ‘consensus\_impl.ml’ and ‘consensus\_chained\_impl.…

---

## [Extensible variants and functors](https://discuss.ocaml.org/t/extensible-variants-and-functors/11117)

<div class="topic-metadata">

**Author:** [@bnguyenvanyen](https://discuss.ocaml.org/u/bnguyenvanyen)\
**Replies:** 5\
**Last updated:** [January 5, 2023, 1:59pm UTC](https://discuss.ocaml.org/t/extensible-variants-and-functors/11117 "2023-01-05T13:59:12Z")

</div>

After seeing the interesting use of extensible variants in Add Type.Id by dbuenzli · Pull Request #11830 · ocaml/ocaml · GitHub, I was interested in playing with them a bit more. I thought this would be true (in the REP…

---

## [Is there a tutorial on "how to read module conventions"?](https://discuss.ocaml.org/t/is-there-a-tutorial-on-how-to-read-module-conventions/10630)

<div class="topic-metadata">

**Author:** [@triangle-man](https://discuss.ocaml.org/u/triangle-man)\
**Replies:** 3\
**Last updated:** [October 13, 2022, 3:15pm UTC](https://discuss.ocaml.org/t/is-there-a-tutorial-on-how-to-read-module-conventions/10630 "2022-10-13T15:15:25Z")

</div>

I’m struggling (as a beginner) to read the docs for some libraries. I suspect the issue is that for experienced users the type declarations are sufficient. For example, the docs for CalendarLib say that the “type of a pe…

---

## [Module strange behavior](https://discuss.ocaml.org/t/module-strange-behavior/10628)

<div class="topic-metadata">

**Author:** [@Doug\_Telford](https://discuss.ocaml.org/u/Doug_Telford)\
**Replies:** 3\
**Last updated:** [October 13, 2022, 9:00am UTC](https://discuss.ocaml.org/t/module-strange-behavior/10628 "2022-10-13T09:00:38Z")

</div>

I am using linux mint 21 and ocaml 4.14.0. My utility module has the structure: module type UtilsMType = sig … end module UtilsM : UtilsMType = struct … end My test program is: open Printf (\* open UtilsM let …

[Next page](https://discuss.ocaml.org/tag/module/96.md?match_all_tags=true&page=1&tags%5B%5D=module)
