最近OCaml的3.12引入了一个特征的第一级封装模块:
一流的包模块.
- 用于打包模块的新类型表达式:
(module PT)- 新类型的表达式,将模块打包为一等值:
(module MODEXPR : PT).- 新类型的模块表达式,将第一类值解压缩为模块:
(val EXPR : PT).- PT是表单的包类型
S或S with type t1 = ... and ... and type tn = ...(S指模块类型).
我在哪里可以找到使用此功能的激励示例或论文?
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