The recent OCaml 3.12 introduces a feature of first-class packaged modules:
First-class packages modules.
- New kind of type expression, for packaged modules:
(module PT)
- New kind of expression, to pack a module as a first-class value:
(module MODEXPR : PT)
.- New kind of module expression, to unpack a first-class value as a module:
(val EXPR : PT)
.- PT is a package type of the form
S
orS with type t1 = ... and ... and type tn = ...
(S
refers to a module type).
Where can I find motivating examples or papers using this feature?
I believe one of the canonical motivating examples is choosing between different structures implementing the same signature at based on information only available at runtime.
E.g., choosing between a hashtable and a balanced binary tree as an implementation of a Map.
There's some info at: https://forge.ocamlcore.org/docman/view.php/77/112/leroy-cug2010.pdf
I believe the OCaml design was influenced by a similar extension for SML by Claudio Russo - see e.g. "First-Class Structures for Standard ML" http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.34.8754&rep=rep1&type=pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With