Types and Programming Languages中介绍了项(term)和值(value),这有别于符号表中变量和值的映射关系。
(1)先通过BNF引入“项”这个语法概念,
The first line (t ::=) declares that we are defining the set of terms, and that we are going to use the letter t to range over terms.——P24
(2)然后,给语法增加求值规则,定义什么是“范式”,
A term t is in normal form if no evaluation rule applies to it.——P38
(3)“值”是被预先定义好的,因为有可能某些范式不被定义为值,
The second defines a subset of terms, called values, that are possible final results of evaluation.——P34
A closed term is stuck if it is in normal form but not a value.——P41
(4)不是值的范式,可用于表示运行时错误,
In fact, normal forms that are not values play a critical role in our analysis of run-time errors.——P38
“Stuckness” gives us a simple notion of run-time error for our simple machine.——P42
按这个思路,类型实际上是值的一种“性质”。
预先给一些值指定类型,相当于指定了“公理”,而求值规则相当于“推导规则”,
这样建立起了一套形式推演系统。
判断某个项是否具有某种类型,就相当于在项上做形式证明。