ocaml - 如何为多态对象类型定义抽象(不透明)接口?
问题描述
原因机器学习
module type T = {
type t('a); // Does not work
type b; // Works
};
module A: T = {
type t('a) = {.. b: bool} as 'a;
type b = bool;
};
module B: T = {
type t('a) = {.. c: int} as 'a;
type b = int;
};
奥卡姆
module type T = sig
type 'a t /* Doesn't work */
type b /* Works */
end
module A : T = struct type 'a t = < b :bool ;.. > as 'a
type b = bool end
module B : T = struct type 'a t = < c :int ;.. > as 'a
type b = int end
如何定义模块类型 A t('a) 使其抽象但与实现中的开放多态对象类型兼容?
解决方案
目前尚不清楚它是否真的有用,但您需要在模块类型中显式添加约束:
module type TA = sig
type 'a t constraint 'a = < b:bool; .. >
end
module A : TA = struct
type 'a t = < b :bool ;.. > as 'a
end
推荐阅读
- python - 过滤 Multilevel pandas groupby
- android - 聊天应用程序 EditText 部分不会在设计预览中呈现/隐藏
- mysql - 如何在 SQL 中构造传感器数据?
- php - 我在 codeigneter 中安装了一个 worldpay 库,但在创建订单时遇到问题
- linux - 如何检查和删除python中两个不同目录中不同的文件?
- javascript - 使用 for-loop 用不可变 js 构建一个深层对象
- javascript - 从函数外部调用变量不起作用javascript
- mysql - PyroCMS(Laravel)翻译中的where子句无法正常工作
- python - Pandas 分组然后根据日期范围 +/- x-days 计数和求和
- python - pandas 中的 scatter_matrix 返回大量文本 - 如何删除它?