首先是代码:
module type ENV_CORE =
sig
type variable
type 'a environment
exception Unbound_variable
val empty : unit -> variable
val bind : 'a -> 'a environment -> 'a environment
val unbind : variable -> 'a -> 'a environment -> 'a environment
val is_bound : variable -> 'a environment -> bool
val lookup : variable -> 'a environment -> bool
val fold : (variable -> 'a -> 'b -> 'b) -> 'a environment -> 'b -> 'b
end;;
module EnvCoreList : ENV_CORE =
struct
type variable = string list
type 'a environment = variable * variable -> 'a
exception Unbound_variable
let empty () = []
let bind elt l = elt::l
let rec unbind elt l =
match l with
|[] -> raise Unbound_variable
|a::r -> if (elt = a)
then r
else a::(unbind elt r)
let rec is_bound elt l =
match l with
|[] -> raise Unbound_variable
|a::r -> if (elt = a)
then true
else is_bound elt r
let rec lookup elt l =
match l with
|[] -> false
|a::r -> if (elt = a)
then true
else lookup elt r
let rec fold f rho gamma =
match rho with
|[] -> gamma
|a::r -> f a (fold f r gamma)
end;;
当我编译它时,我收到以下错误:
Error: Signature mismatch:
Modules do not match:
sig
type variable = string list
type 'a environment = variable * variable -> 'a
exception Unbound_variable
val empty : unit -> 'a list
val bind : 'a -> 'a list -> 'a list
val unbind : 'a -> 'a list -> 'a list
val is_bound : 'a -> 'a list -> bool
val lookup : 'a -> 'a list -> bool
val fold : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
end
is not included in
ENV_CORE
Values do not match:
val bind : 'a -> 'a list -> 'a list
is not included in
val bind : 'a -> 'a environment -> 'a environment
我不明白更具体的类型如何不包含在更一般的类型中? 我找不到任何类似的问题,也无法解决这个问题。 感谢名单
答案 0 :(得分:0)
类型'a list
和'a environment
之间没有明显的关系。我不明白为什么你会考虑比另一个更一般。
在我看来,您应该在实现中更改environment
的定义,或者应该重写bind
,以便它适用于您为environment
指定的类型。