OCaml封装模块有什么用途?

t0y*_*yv0 7 ocaml

最近OCaml的3.12引入了一个特征的第一级封装模块:

一流的包模块.

  • 用于打包模块的新类型表达式: (module PT)
  • 新类型的表达式,将模块打包为一等值:(module MODEXPR : PT).
  • 新类型的模块表达式,将第一类值解压缩为模块:(val EXPR : PT).
  • PT是表单的包类型SS with type t1 = ... and ... and type tn = ...(S指模块类型).

我在哪里可以找到使用此功能的激励示例或论文?

RD1*_*RD1 6

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

  • 据我所知,使用caml-light作为后端的SML实现的莫斯科ML是第一个实现一流模块的.莫斯科ML文档的相应部分引用了分发中的文件mosml/examples/modules/{sieve.sml,array.sml,choice.sml,matrix.sml}. (2认同)