为什么会有这样的结果:
module type ENTRY = sig type t end
module type LOG = functor (E : ENTRY) -> sig type t end 这是日志的有效实现
module Log :LOG = functor (LogEntry : ENTRY) ->
struct type t = LogEntry.t list end但这不是
module Log (LogEntry: ENTRY) :LOG = struct
type t = LogEntry.t list end
Error: Signature mismatch:
Modules do not match: sig type t = LogEntry.t list end is not included in LOG如果我从Log的两个定义中删除符号标签(:sugar1 ),那么它们返回相同的类型,因为它们只是语法日志
1
发布于 2013-12-03 06:33:41
错误消息令人困惑,但第一个示例通过而第二个示例失败的原因实际上非常简单。比较:
type entry = int
type log = int -> string
let log : log = fun s -> string_of_int s和
let log (s : entry) : log = string_of_int s在模块的情况下,错误消息指出模块字段不包括在函数器中,因为未应用的函数器没有字段。
ETA: functor逻辑上不能有字段:函数/functor与数据结构/模块是“不同种类的野兽”。--这使得错误消息变得混乱,听起来像是我们被要求引入一个字段,尽管它已经出现在函数的结果中。
发布于 2013-12-10 14:14:08
让我澄清一下lukstafi的答案。LOG是函数式的类型,在第一种情况下,它与Log实现本身(实际上是函数式)匹配,但在第二种情况下,它与函数式应用程序(碰巧是普通模块)的结果相匹配,因此出现了不匹配。
总而言之,这看起来像是语法上的误解。请仔细阅读section on module types in the manual。
https://stackoverflow.com/questions/20337229
复制相似问题