[英]Ocaml unbound type constructor with module
我正在努力,我很确定在编写该错误时不会显示该错误。 现在可以了,我不知道为什么以及如何解决它,我已经搜索了很长时间,但一无所获。 最后一行给出了Unbound类型的构造函数env,谢谢大家的反馈
module type ENV =
sig
type 't env
val emptyenv : 't -> 't env
val bind : 't env * string * 't -> 't env
val bindlist : 't env * (string list) * ('t list)-> 't env
val applyenv : 't env * string -> 't
exception WrongBindlist
end
module Funenv:ENV =
struct
type 't env = string -> 't
exception WrongBindlist
let emptyenv(x) = function (y: string) -> x
(* x: valore default *)
let applyenv(x,y) = x y
let bind(r, l, e) =
function lu -> if lu = l then e else applyenv(r,lu)
let rec bindlist(r, il, el) = match (il,el) with
| ([],[]) -> r
| i::il1, e::el1 -> bindlist (bind(r, i, e), il1, el1)
| _ -> raise WrongBindlist
end
module Listenv:ENV =
struct
type 't env = (string * 't) list
exception WrongBindlist
let emptyenv(x) = [("", x)]
let rec applyenv(x,y) = match x with
| [(_, e)] -> e
| (i1, e1) :: x1 -> if y = i1 then e1
else applyenv(x1, y)
| [] -> failwith("wrong env")
let bind(r, l, e) = (l, e) :: r
let rec bindlist(r, il, el) = match (il, el) with
| ([],[]) -> r
| i::il1, e::el1 -> bindlist (bind(r, i, e), il1, el1)
| _ -> raise WrongBindlist
end
type ide = string
type exp = Eint of int
| Ebool of bool
type eval = Int of int
| Bool of bool
| Unbound
| Funval of efun
and efun = exp * eval env
谁做你希望env
能在这个最后一行? env
不是范围内的某种类型构造函数,而是属于ENV
模块的类型构造函数。
您可以在这些模块之一中定义exp
和efun
,也可以使用Listenv.env
为例。
使用以下代码进行编译:
type eval = Int of int
| Bool of bool
| Unbound
| Funval of efun
and efun = exp * eval Listenv.env
可能是您正在做的另一种解决方案是将该定义直接放在签名中:
module type ENV =
sig
type 't env
val emptyenv : 't -> 't env
val bind : 't env * string * 't -> 't env
val bindlist : 't env * string list * 't list -> 't env
val applyenv : 't env * string -> 't
type ide = string
type exp = Eint of int | Ebool of bool
type eval = Int of int | Bool of bool | Unbound | Funval of efun
and efun = exp * eval env
exception WrongBindlist
end
但是,然后您必须在Listenv
和Funenv
再次提供它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.