系统F:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
第10行: | 第10行: | ||
这里的 α 是[[类型变量]]。 |
这里的 α 是[[类型变量]]。 |
||
在 [[Curry-Howard |
在 [[Curry-Howard同构]]下,系统 F 对应于[[二阶逻辑]]。 |
||
系统 F,和甚至更加有表达力的 lambda 演算一起,可被看作 [[lambda 立方]]的一部分。 |
系统 F,和甚至更加有表达力的 lambda 演算一起,可被看作 [[lambda 立方]]的一部分。 |
2007年3月27日 (二) 06:00的版本
模板参数错误!(代码36)
|
系统 F,也叫做多态 lambda 演算或二阶 lambda 演算,是有类型 lambda 演算。它由逻辑学家 Jean-Yves Girard 和计算机科学家 John C. Reynolds 独立发现的。系统 F 形式化了编程语言中的参数多态的概念。
正如同 lambda 演算有取值于(rang over)函数的变量,和来自它们的粘合子(binder);二阶 lambda 演算取值自类型,和来自它们的粘合子。
作为一个例子,恒等函数有形如 A→ A 的任何类型的事实可以在系统 F 中被形式化为判断
这里的 α 是类型变量。
在 Curry-Howard同构下,系统 F 对应于二阶逻辑。
系统 F,和甚至更加有表达力的 lambda 演算一起,可被看作 lambda 立方的一部分。
逻辑和谓词
The Boolean type is defined as: , where α is a type variable. This produces the following two definitions for the boolean values TRUE and FALSE:
- TRUE :=
- FALSE :=
Then, with these two λ-terms, we can define some logic operators:
- AND :=
- OR :=
- NOT :=
There really is no need for a IFTHENELSE function as one can just use raw Boolean typed terms as decision functions. However, if one is requested:
- IFTHENELSE :=
will do. A predicate is a function which returns a boolean value. The most fundamental predicate is ISZERO which returns TRUE if and only if its argument is the Church numeral 0:
- ISZERO := λ n. n (λ x. FALSE) TRUE
系统 F 结构
System F allows recursive constructions to be embedded in a natural manner, related to that in Martin-Löf's type theory. Abstract structures (S) are created using constructors. These are functions typed as:
- .
Recursivity is manifested when itself appears within one of the types . If you have of these constructors, you can define the type of as:
For instance, the natural numbers can be defined as an inductive datatype with constructors
The System F type corresponding to this structure is . The terms of this type comprise a typed version of the Church numerals, the first few of which are:
- 0 :=
- 1 :=
- 2 :=
- 3 :=
If we reverse the order of the curried arguments (i.e., ), then the Church numeral for is a function that takes a function f as argument and returns the power of f. That is to say, a Church numeral is a higher-order function -- it takes a single-argument function f, and returns another single-argument function.
用在编程语言中
The version of System F used in this article is as an explicitly-typed, or Church-style, calculus. The typing information contained in λ-terms makes type-checking straightforward. Joe Wells (1994) settled an "embarrassing open problem" by proving that type checking is undecidable for a Curry-style variant of System F, that is, one that lacks explicit typing annotations. [1] [2]
Wells' result implies that type inference for System F is impossible. A restriction of System F known as "Hindley-Milner", or simply "HM", does have an easy type inference algorithm and is used for many strongly typed functional programming languages such as Haskell and ML.
引用
- Girard, Lafont and Taylor, 1997. Proofs and Types. Cambridge University Press.
- J. B. Wells. "Typability and type checking in the second-order lambda-calculus are equivalent and undecidable." In Proceedings of the 9th Annual IEEE Symposium on Logic in Computer Science (LICS), pages 176-185, 1994. [3]
外部链接
- Summary of System F by Franck Binard.