考虑以下无类型 lambda 演算的玩具表示:
Require Import String.
Open Scope string_scope.
Inductive term : Set :=
| Var : string -> term
| Abs : string -> term -> term
| App : term -> term -> term.
Fixpoint print (term : term) :=
match term return string with
| Var id => id
| Abs id term => "\" ++ id ++ " " ++ print term
| App term1 term2 => print_inner term1 ++ " " ++ print_inner term2
end
with print_inner (term : term) :=
match term return string with
| Var id => id
| term => "(" ++ print term ++ ")"
end.
类型检查print
失败并出现以下错误:
Recursive definition of print_inner is ill-formed.
[...]
Recursive call to print has principal argument equal to "term" instead of "t".
什么是最易读/符合人体工程学/最有效的实现方式?