gpt4 book ai didi

compiler-errors - ocaml中的环境- `type a'信封上的语法错误

转载 作者:行者123 更新时间:2023-12-02 10:49:21 25 4
gpt4 key购买 nike

我需要在ocaml中声明和使用环境。在我的学习书中,我找到以下代码:

type a' env =  (string * 'a)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 ;;

type evT = Unbound | FunVal of evFun | RecFunVal of string*evFun
and evFun = string * exp * (evT env);;

但是,当我运行代码时,出现以下错误:
Type exp defined.
#Toplevel input:
>type a' env = (string * 'a)list;;
> ^^^
Syntax error.

为什么会出现此错误?我很想了解我在做什么错。

最佳答案

type a' env应该是type 'a env'a是类型变量,名称前带有撇号。在等号的右侧也再次提到它。 a'只是一个先前未定义的标识符,但在该位置上在语法上也显然无效。

关于compiler-errors - ocaml中的环境- `type a'信封上的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48531735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com