OCaml:在 .mli 文件中描述模块
OCaml: describe modules in .mli file
我正在使用 Core.Std 在 .ml
文件中生成一个集合和一个映射:
type temp = int with sexp, compare
type label = Symbol.symbol with sexp, compare
module Temp = struct
type t = temp with sexp, compare
end
module TempComp = Comparable.Make(Temp)
module TempSet = TempComp.Set
module TempMap = TempComp.Map
module Label = struct
type t = label with sexp, compare
end
module LabelComp = Comparable.Make(Label)
module LabelMap = LabelComp.Map
我应该如何在我的 .mli
文件中描述 TempSet, TempMap, LabelMap
?
我输入:
module TempMap : Map.S with type t = temp
但是我得到一个错误:
In this `with' constraint, the new definition of t
does not match its original definition in the constrained signature:
Type declarations do not match:
type t = t
is not included in
type 'a t = (Key.t, 'a, Key.comparator_witness) Map.t
我该如何解决这个错误?
'a t
类型是从temp
(一个key)到'a
(任意数据)的映射类型。你想说的是,'a t
是来自具体类型 temp
的键的映射,正确的做法是:
module TempMap : Map.S with type Key.t = temp
然而,尽管这是一种正确的做事方式,但并不简单,因为它需要您深入研究地图的签名。常见的方式就是说:
type temp
module Temp : Comparable with type t = temp
并允许您的界面用户使用 Temp.Map
、Temp.Set
等。此外,请考虑使用更丰富的界面 Identifiable
,该界面还将包括哈希表、哈希集和许多其他有用的和预期的东西。
我正在使用 Core.Std 在 .ml
文件中生成一个集合和一个映射:
type temp = int with sexp, compare
type label = Symbol.symbol with sexp, compare
module Temp = struct
type t = temp with sexp, compare
end
module TempComp = Comparable.Make(Temp)
module TempSet = TempComp.Set
module TempMap = TempComp.Map
module Label = struct
type t = label with sexp, compare
end
module LabelComp = Comparable.Make(Label)
module LabelMap = LabelComp.Map
我应该如何在我的 .mli
文件中描述 TempSet, TempMap, LabelMap
?
我输入:
module TempMap : Map.S with type t = temp
但是我得到一个错误:
In this `with' constraint, the new definition of t does not match its original definition in the constrained signature: Type declarations do not match: type t = t is not included in type 'a t = (Key.t, 'a, Key.comparator_witness) Map.t
我该如何解决这个错误?
'a t
类型是从temp
(一个key)到'a
(任意数据)的映射类型。你想说的是,'a t
是来自具体类型 temp
的键的映射,正确的做法是:
module TempMap : Map.S with type Key.t = temp
然而,尽管这是一种正确的做事方式,但并不简单,因为它需要您深入研究地图的签名。常见的方式就是说:
type temp
module Temp : Comparable with type t = temp
并允许您的界面用户使用 Temp.Map
、Temp.Set
等。此外,请考虑使用更丰富的界面 Identifiable
,该界面还将包括哈希表、哈希集和许多其他有用的和预期的东西。