我对 OCaml 中的以下仿函数问题非常困扰。我粘贴一些代码只是为了让您理解。基本上
我在以下位置定义了这两个模块pctl.ml
:
module type ProbPA = sig
include Hashtbl.HashedType
val next: t -> (t * float) list
val print: t -> float -> unit
end
module type M = sig
type s
val set_error: float -> unit
val check: s -> formula -> bool
val check_path: s -> path_formula -> float
val check_suite: s -> suite -> unit
end
和以下函子:
module Make(P: ProbPA): (M with type s = P.t) = struct
type s = P.t
(* implementation *)
end
然后为了实际使用这些模块,我直接在一个名为的文件中定义了一个新模块prism.ml
:
type state = value array
type t = state
type value =
| VBOOL of bool
| VINT of int
| VFLOAT of float
| VUNSET
(* all the functions required *)
从第三个来源( )我使用了带有模块formulas.ml
的函子:Prism
module PrismPctl = Pctl.Make(Prism)
open PrismPctl
最后从main.ml
open Formulas.PrismPctl
(* code to prepare the object *)
PrismPctl.check_suite s.sys_state suite (* error here *)
并编译给出以下错误
错误:此表达式的类型为 Prism.state = Prism.value 数组,但表达式应为 Formulas.PrismPctl.s 类型
据我所知,名称有一种不好的别名,它们是相同的(因为value array
类型定义为t
并且M with type s = P.t
在仿函数中使用)但类型检查器不认为它们相同。
我真的不明白问题出在哪里,有人可以帮助我吗?
提前致谢