OCaml 封装模块有哪些好的用途?
最近的 OCaml 3.12 引入了一流打包模块的功能 :
一流的软件包模块。
- 新的类型表达式,用于打包模块:
(module PT)
- 新的表达式,将模块打包为一流值:
(module MODEXPR : PT)
。- 新型模块表达式,将一流值解包为模块:
(val EXPR : PT)
。- PT 是
S
或S 形式的封装类型,其中类型 t1 = ... 和 ... 以及类型 tn = ...
(S
指的是模块类型)。
在哪里可以找到使用此功能的激励性示例或论文?
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
orS with type t1 = ... and ... and type tn = ...
(S
refers to a module type).
Where can I find motivating examples or papers using this feature?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信典型的激励示例之一是根据仅在运行时可用的信息在实现相同签名的不同结构之间进行选择。
例如,在哈希表和平衡二叉树之间进行选择作为 Map 的实现。
有一些信息: https://forge.ocamlcore .org/docman/view.php/77/112/leroy-cug2010.pdf
我相信 OCaml 设计受到 Claudio Russo 对 SML 的类似扩展的影响 - 请参阅“标准 ML 的一流结构” http://citeseerx. ist.psu.edu/viewdoc/download?doi=10.1.1.34.8754&rep=rep1&type=pdf
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