Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are good uses of OCaml packaged modules?

Tags:

ocaml

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 or S with type t1 = ... and ... and type tn = ... (S refers to a module type).

Where can I find motivating examples or papers using this feature?

like image 971
t0yv0 Avatar asked Jul 29 '10 16:07

t0yv0


1 Answers

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

like image 54
RD1 Avatar answered Feb 04 '23 08:02

RD1