请原谅我滥用术语的可能性,我对OCaml仍然不太满意。
我们有一个带有以下(删节)签名的仿函数:
module type FUNCTORA = sig
type input
type output
type key
type inter
val my_function : input list -> (key * output) list Deferred.t
end
接下来,我们这样实现它。 MYAPP与上述类型相同。
module MyFunctor (App : MyAPP) : FUNCTORA = struct
type input = App.input
type output = App.output
type key = App.key
type inter App.value
let my_function lst = ...
end
在尝试编译实现时,我们收到此错误:
Error: Signature mismatch:
...
Values do not match:
val my_function :
App.input list ->
(App.key * App.output) list Async_kernel.Deferred.t
is not included in
val my_function :
input list -> (key * output) list Async.Std.Deferred.t
即使我们将它们设置为相同的类型,它也不会考虑包含App.input等的输入。我们如何才能进行类型检查呢?
答案 0 :(得分:0)
If I make the following changes:
MyAPP => FUNCTORA (* Since you say they are the same *)
type inter App.value => type inter = App.inter (* Syntax/name error *)
Deferred.t => option (* To limit dependence on other modules *)
Then your code compiles for me.
Possibly the problem is with Deferred.t
. There are two distinct looking types in the error message.