Questions tagged [first-class-modules]

Use this tag for questions relating to passing modules around as values, and more specifically to the feature in [ocaml] of packing a module and module signature together as a value.

Firs-class modules are, analogous to , modules passed around as values. In the term refers specifically to the concept of packing a module together with a module signature into a value. That is, modules aren't implicitly first-class, but can be converted to a value, and must later be unpacked before being used.

Resources

10 questions
10
votes
4 answers

What (exactly) are "First Class" modules?

I often read some programming languages have "First Class" support for modules (OCaml, Scala, TypeScript[?]) and recently stumbled upon an answer on SO citing modules as first class citizens among the distinguishing features of Scala. I thought I…
Ashkan Kh. Nazary
  • 21,844
  • 13
  • 44
  • 68
8
votes
1 answer

The type constructor "..." would escape its scope when using first class modules

Given a simple factory: module type Factory = sig type t val create : unit -> t end module FactoryImpl : Factory = struct type t = string let create: unit -> t = fun () -> "aaa" end let factory: (module Factory) = (module FactoryImpl) let…
mbergal
  • 635
  • 6
  • 13
2
votes
1 answer

Include module signature and value of this module type in a function signature

I just want to have a simple function that is generic over Hashtbls so I wrote this: let iter_htbl (type a) (module H : Hashtbl.S with type key = a) htbl = H.iter (fun _key _v -> ()) htbl Which gives me the following error: 53 | H.iter (fun…
Lhooq
  • 4,281
  • 1
  • 18
  • 37
2
votes
1 answer

How to create a set of elements without knowing the type of the element?

I'm running into problems around recursive/mutually referential module definitions trying to use Caml's Map/Set stuff. I really want ones that just work on types, not modules. I feel like it should be possible to do this with first-class modules,…
Edward Peters
  • 3,623
  • 2
  • 16
  • 39
2
votes
1 answer

Unpacking a first-class module constrained by a type variable

I'm trying to write a function that basically looks like this: module type M = sig type t val doStuff : t -> unit end let f : 'a. 'a -> (module M with type t = 'a) -> unit = fun value (module MSomething) -> MSomething.doStuff value That…
glennsl
  • 28,186
  • 12
  • 57
  • 75
1
vote
1 answer

How to unpack 'module type' packed to 'type' back to 'module type'?

We can pack module to value and unpack it back to module (modules as first-class citizens). Also, we can pack module type to type, but... Is it possible to unpack module type from type? If it is - How? If it is not - Why? The following sketch shows…
Valentyn Zakharenko
  • 2,710
  • 1
  • 21
  • 47
1
vote
3 answers

How to return the instance of first-class module's nested type from a function?

Context: I am trying to implement something like OOP observable pattern in OCaml with using first-class modules. I have a project with a list of modules and want to extend them with observation without changing. To minimize code duplication I…
0
votes
1 answer

Passing a variable from class module to userform

Hej, I am trying to design a code, where a number of commandbuttons call the same userform. I have created the class module and got it to work so that they all call the userform, but I need the name of the button passed on from the class module into…
0
votes
1 answer

The signature for this packaged module couldn't be inferred in recursive function

I'm still trying to figure out how to split code when using mirage and it's myriad of first class modules. I've put everything I need in a big ugly Context module, to avoid having to pass ten modules to all my functions, one is pain enough. I have a…
Ulrar
  • 895
  • 8
  • 17
0
votes
1 answer

Pass modules to other modules

I'm trying to use Irmin with MirageOS, and I'm struggling with all those modules. I took a look at the Canopy sources to try and figure out how Irmin is supposed to be used, and I have this : let start console clock resolver conduit = let (module…
Ulrar
  • 895
  • 8
  • 17