我用模块构建了一个复杂的结构,里面有一个递归。编译给了我一个我无法解决的错误(尽管我不认为这真的是由于递归)。有人可以帮忙吗?
首先,定义一个接口ZONE
和一个函子ZoneFunPrec
:
(* zone.ml *)
module type ZONE = sig
type prop
type info
type t
end
(* zoneFunPrec.ml *)
open Prop
open Zonesm
module ZoneFunPrec (Prop : PROP)(Prec: ZONESM with type prop = Prop.t) = struct
type prop = Prop.t
type info = { mark: int option; prec: Prec.t option }
type t = { prop: prop; info: info }
end
一个函子ZonesFun
和一个接口ZONES
,其元素是具有相同属性的区域列表:
(* zones.ml *)
open Prop
open Zone
module type ZONES = sig
type prop
type zone
type t
end
module ZonesFun (Prop: PROP) (Zone: ZONE with type prop = Prop.t) = struct
type prop = Prop.t
type zone = Zone.t
type t = | ZSbot | ZS of zone list
end
一个函子ZonesmFun
和一个接口,其元素是具有相同属性ZONESM
的映射 from String
into :ZONES
(* zonesm.ml *)
open Prop
open Zone
open Zones
module SMap = Map.Make(String)
module type ZONESM = sig
type prop
type zones
type t
end
module ZonesmFun (Prop: PROP)
(Zone: ZONE with type prop = Prop.t)
(Zones: ZONES with type zone = Zone.t) = struct
type prop = Prop.t
type zones = Zones.t
type t = | Bot | ZSM of Zones.t SMap.t
end
然后,我尝试构建一些模块,EEA
其接口为PROP
:
(* modules.ml *)
open E_expression_abs
open Zone
open ZoneFunPrec
open Zones
open Zonesm
module EEA = E_expression_abs
module rec ZoneEEA : ZONE = ZoneFunPrec(EEA)(ZonesmEEA)
and ZonesEEA : ZONES = ZonesFun(EEA)(ZoneEEA)
and ZonesmEEA : ZONESM = ZonesmFun(EEA)(ZoneEEA)(ZonesEEA)
在我makefile
的 中,编译顺序与我在上面列出的文件的顺序相同。然后编译器给我一个错误module rec...
:
File "domains/modules.ml", line 7, characters 45-54:
Error: Signature mismatch:
Modules do not match:
sig
type prop = ZonesmEEA.prop
type zones = ZonesmEEA.zones
type t = ZonesmEEA.t
end
is not included in
sig type prop = EEA.t type zones type t end
Type declarations do not match:
type prop = ZonesmEEA.prop
is not included in
type prop = EEA.t
显然,编译器无法知道ZonesEEA.prop
实际上是EEA.t
......