受子签名约束的 OCaml 子模块
OCaml sub-module constrained by a sub-signature
我有一个受签名 Sig
约束的模块 Mod
。该模块有一个 Nested
子模块。签名有匹配的 Nested
子签名:
module type Sig = sig
val a : int
module type Nested = sig
val b : int
end
end
module Mod : Sig = struct
let a = 1
module Nested = struct
let b = 2
end
end
但是,这会产生以下错误:
Error: Signature mismatch:
Modules do not match:
sig val a : int module Nested : sig val b : int end end
is not included in
Sig
The field `Nested' is required but not provided
我错过了什么?
您的代码中声明嵌套模块的方式有误:
module type Sig = sig
val a : int
module Nested : sig val b : int end
end
module Mod : Sig = struct
let a = 1
module Nested = struct
let b = 2
end
end
查看子模块如何在以下 link 中声明:http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora131.html
它帮助我修正了你的错误。
我有一个受签名 Sig
约束的模块 Mod
。该模块有一个 Nested
子模块。签名有匹配的 Nested
子签名:
module type Sig = sig
val a : int
module type Nested = sig
val b : int
end
end
module Mod : Sig = struct
let a = 1
module Nested = struct
let b = 2
end
end
但是,这会产生以下错误:
Error: Signature mismatch:
Modules do not match:
sig val a : int module Nested : sig val b : int end end
is not included in
Sig
The field `Nested' is required but not provided
我错过了什么?
您的代码中声明嵌套模块的方式有误:
module type Sig = sig
val a : int
module Nested : sig val b : int end
end
module Mod : Sig = struct
let a = 1
module Nested = struct
let b = 2
end
end
查看子模块如何在以下 link 中声明:http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora131.html
它帮助我修正了你的错误。