tags:

views:

67

answers:

1

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?

+3  A: 

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: http://www.annexia.org/tmp/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

RD1
As far as I remember, Moscow ML, an SML implementation using caml-light as back-end, was the first to implement first-class modules. The appropriate section of Moscow ML's documentation refers to files mosml/examples/modules/{sieve.sml,array.sml,choice.sml,matrix.sml} from the distribution for examples.
Pascal Cuoq
@Pascal Nice reference for the examples. That's the extension by Claudio that I mentioned.
RD1