Types 链接2个文件中由函子生成的2个模块

Types 链接2个文件中由函子生成的2个模块,types,module,ocaml,functor,Types,Module,Ocaml,Functor,我定义了以下几个模块: (* zone.ml *) module ZoneFun (Prop : PROP) = (struct ... end: ZONE) (* zones.ml *) module ZonesFun (Zone : ZONE) = (struct ... end: ZONES) 其中PROP是模块类型和一些其他模块的接口 (* calculate.ml *) open Type open Zone open Zones module ZoneType = ZoneFu

我定义了以下几个模块:

(* zone.ml *)
module ZoneFun (Prop : PROP) = (struct ... end: ZONE)

(* zones.ml *)
module ZonesFun (Zone : ZONE) = (struct ... end: ZONES)
其中
PROP
是模块
类型
和一些其他模块的接口

(* calculate.ml *)
open Type
open Zone
open Zones

module ZoneType = ZoneFun(Type)
module ZonesType = ZonesFun(ZoneType)

let tries (x: ZonesType.t) : unit =
  Printf.printf "haha"

(* abs.ml *)
open Type
open Zone
open Zones
open Calculate

module ZoneType = ZoneFun(Type)
module ZonesType = ZonesFun(ZoneType)

module Abs = struct
  ...
  let abc (x: ZonesType.t) : unit =
    Calculate.tries x
  ...
end
然后编译在
abs.ml
中的
Calculate.tries x
行上给了我一个错误:

Error: This expression has type ZonesType.t = Zones.ZonesFun(ZoneType).t
       but an expression was expected of type
         Calculate.ZonesType.t = Zones.ZonesFun(Calculate.ZoneType).t

我如何告诉编译器
Calculate.ZonesType.t
实际上与
abs.ml
ZonesType.t
相同?

问题是您定义了两次模块ZoneType和ZonesType。您应该删除第二个声明,因为它隐藏了第一个声明。 在文件abs.ml中,删除两行
模块区域…


Ocaml允许您多次使用相同的名称,但在这种情况下,新的声明将隐藏以前的声明。

问题在于您定义了两次模块ZoneType和ZoneType。您应该删除第二个声明,因为它隐藏了第一个声明。 在文件abs.ml中,删除两行
模块区域…


Ocaml允许您多次使用相同的名称,但在这种情况下,新声明将隐藏以前的声明。

您可以删除类型批注并让Ocaml推断正确的类型。您可以删除类型批注并让Ocaml推断正确的类型。对不起,实际上在
abs.ml
中,我还有很多其他函数需要注释
ZoneType
ZonesType
,因此我必须在
abs.ml
中有两行
模块区域…
。是的,我理解,但这些模块已经在calculate中创建,所以
open calculate
就是您所需要的。对不起,实际上在
abs.ml
中,我还有许多其他函数需要注释
ZoneType
ZonesType
,因此我必须在
abs.ml
中有两行
模块区域…
。是的,我理解,但这些模块已经在calculate中创建,所以
open calculate
就是您所需要的。