小编ric*_*ter的帖子

lambda表达式的自由变量列表

我刚刚为即将到来的OCaml测试做了一些功课,我遇到了一些麻烦.

考虑由以下抽象语法定义的λ项的语言(其中x是变量):

t ::= x | t t | ?x. t  
Run Code Online (Sandbox Code Playgroud)

写一个类型术语来表示λ术语.假设变量表示为字符串.

好的,男孩.

# type t = Var of string | App of (t*t) | Abs of string*t;;
type t = Var of string | App of (t * t) | Abs of (string * t)
Run Code Online (Sandbox Code Playgroud)

术语t的自由变量fv(t)由归纳定义如下:

fv(x) = {x}  
fv(t t') = fv(t) ? fv(t')  
fv(?x. t) = fv(t) \ {x}
Run Code Online (Sandbox Code Playgroud)

当然可以.

# let rec fv term = match term with
Var x -> [x]
  | App (t, t') …
Run Code Online (Sandbox Code Playgroud)

ocaml lambda-calculus free-variable

6
推荐指数
1
解决办法
2121
查看次数

标签 统计

free-variable ×1

lambda-calculus ×1

ocaml ×1