我对仿函数有一点问题(它是结果类型).下面,我有一个使用Ordered类型的Set仿函数.我实际使用的set.ml自带的OCaml的一些指导,但我似乎做的一切ahhem权.我创建了一个带有整数的Ordered模块,并将其应用于Set仿函数,以获取此代码示例IntSet的最后一个模块.
当我尝试插入一个整数时,下一行失败了.我收到以下类型错误:
Error: This expression has type int but is here used with type
SetInt.elt = Set(OrdInt).elt
Run Code Online (Sandbox Code Playgroud)
别误会我的意思,这里的类型系统是正确的.顶级报告的类型SetInt.elt是Set(OrdInt).elt,但是当我使用ocaml提供的相同操作设置Set时,'same'行是,SetInt.elt = OrderedInt.t.好像我应该得到SetInt.elt = Ordered.t.
这很简单,我可能只是错过了一些愚蠢的细节!哎呀!
请注意:我已经简化了成员/插入函数,因为这个问题与类型有关.
module type Ordered =
sig
type t
val lt : t -> t -> bool
val eq : t -> t -> bool
val leq : t -> t -> bool
end
module type S =
sig
type elt
type t
exception Already_Exists
val …Run Code Online (Sandbox Code Playgroud)