开发者

What are good uses of OCaml packaged modules?

开发者 https://www.devze.com 2023-01-09 16:20 出处:网络
The recent OCaml 3.12 introduces a feature of first-class packaged modules: First-class packages开发者_运维百科 modules.

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号