Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Types 带有模块的Ocaml未绑定类型构造函数_Types_Constructor_Module_Ocaml - Fatal编程技术网

Types 带有模块的Ocaml未绑定类型构造函数

Types 带有模块的Ocaml未绑定类型构造函数,types,constructor,module,ocaml,Types,Constructor,Module,Ocaml,我正在做这件事,我很确定当我写它的时候,错误不会出现。现在它确实存在,我不知道为什么以及如何解决它,我已经寻找了很久,但什么也没有。 它在最后一行给出了未绑定类型构造函数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

我正在做这件事,我很确定当我写它的时候,错误不会出现。现在它确实存在,我不知道为什么以及如何解决它,我已经寻找了很久,但什么也没有。 它在最后一行给出了未绑定类型构造函数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
中再次提供它们。谢谢,它很有效,但很奇怪。现在不工作而以前工作有什么好的理由吗?即使没有listenev,它也编译了。在这之前,我肯定你可能会把这个定义直接放到签名中(我会编辑我的答案)。