递归类型


递归类型 (正體)

在计算机编程语言中,递归类型是一种特殊的数据类型,它表示自身内部可能包含其它的同样类型的值。

一个列子是链表类型,在Haskell中:

data List a = Nil | Cons a (List a)

这表示a的链表s可以是一个空表或一个cons单元包含了一个'a'(链表的“头”)和另一个链表(“尾”)。

递归不允许在Miranda语言中和Haskell的同义类型中出现,所以以下的Haskell类型是非法的:

type Bad = (Int, Bad)
type Evil = Bool -> Evil

相反地,表面上是相等的代数数据类型却是可以的:

data Good = Pair Int Good
data Fine = Fun (Bool->Fine)

本文全部或部分内容来自以GFDL授权发布的《自由线上电脑词典》(FOLDOC)。







stock | retire | vm
Why are we here?
All text is available under the terms of the GNU Free Documentation License
This page is cache of Wikipedia. History