第185行: |
第185行: |
| A coinductive data definition is one that specifies the operations that may be performed on a piece of data; typically, self-referential coinductive definitions are used for data structures of infinite size. | | A coinductive data definition is one that specifies the operations that may be performed on a piece of data; typically, self-referential coinductive definitions are used for data structures of infinite size. |
| | | |
− | 协归纳数据定义是一种规定了可以对一段数据进行操作的定义;;通常,自引用的协归纳定义用于无限大小的数据结构。
| + | |
| + | 协归纳数据定义规定了可以对一段数据进行怎样的操作;通常,自引用的协归纳定义可以用于定义无限大小的数据结构。 |
| | | |
| A coinductive definition of infinite [[stream (computer science)|streams]] of strings, given informally, might look like this: | | A coinductive definition of infinite [[stream (computer science)|streams]] of strings, given informally, might look like this: |
第191行: |
第192行: |
| A coinductive definition of infinite streams of strings, given informally, might look like this: | | A coinductive definition of infinite streams of strings, given informally, might look like this: |
| | | |
− | 非正式给出的无限串流的共归纳定义可能是这样的。
| + | 用共归纳定义法来定义无限大小的字符串流,一个可能的例子是这样的: |
| | | |
| A stream of strings is an object s such that: | | A stream of strings is an object s such that: |
第198行: |
第199行: |
| | | |
| 字符串流是s这样的对象: | | 字符串流是s这样的对象: |
− | 头是字符串,而尾是字符串流。 | + | 头部<code>head</code>是字符串,且 |
| + | 尾部<code>tail</code>是字符串流。 |
| | | |
| This is very similar to an inductive definition of lists of strings; the difference is that this definition specifies how to access the contents of the data structure—namely, via the [[accessor]] functions <code>head</code> and <code>tail</code>—and what those contents may be, whereas the inductive definition specifies how to create the structure and what it may be created from. | | This is very similar to an inductive definition of lists of strings; the difference is that this definition specifies how to access the contents of the data structure—namely, via the [[accessor]] functions <code>head</code> and <code>tail</code>—and what those contents may be, whereas the inductive definition specifies how to create the structure and what it may be created from. |
| | | |
− | 这与字符串列表的归纳定义非常相似;不同的是,这个定义指定了如何访问数据结构的内容,即通过访问函数 的头和尾以及这些内容可能是什么,而归纳定义则指定了如何创建结构以及它可能是由什么创建的。
| + | 这与字符串列表的归纳定义非常相似;不同的是,这个定义指定了如何访问数据结构的内容,即通过访问函数的头<code>head</code>和尾<code>tail</code>以及这些内容可能是什么,而归纳定义则指定了如何创建结构以及它可能是由什么创建的。 |
| + | |
| | | |
| Corecursion is related to coinduction, and can be used to compute particular instances of (possibly) infinite objects. As a programming technique, it is used most often in the context of [[lazy evaluation|lazy]] programming languages, and can be preferable to recursion when the desired size or precision of a program's output is unknown. In such cases the program requires both a definition for an infinitely large (or infinitely precise) result, and a mechanism for taking a finite portion of that result. The problem of computing the first n [[prime numbers]] is one that can be solved with a corecursive program (e.g. [[Fold (higher-order function)#Examples|here]]). | | Corecursion is related to coinduction, and can be used to compute particular instances of (possibly) infinite objects. As a programming technique, it is used most often in the context of [[lazy evaluation|lazy]] programming languages, and can be preferable to recursion when the desired size or precision of a program's output is unknown. In such cases the program requires both a definition for an infinitely large (or infinitely precise) result, and a mechanism for taking a finite portion of that result. The problem of computing the first n [[prime numbers]] is one that can be solved with a corecursive program (e.g. [[Fold (higher-order function)#Examples|here]]). |
第208行: |
第211行: |
| Corecursion is related to coinduction, and can be used to compute particular instances of (possibly) infinite objects. As a programming technique, it is used most often in the context of lazy programming languages, and can be preferable to recursion when the desired size or precision of a program's output is unknown. In such cases the program requires both a definition for an infinitely large (or infinitely precise) result, and a mechanism for taking a finite portion of that result. The problem of computing the first n prime numbers is one that can be solved with a corecursive program (e.g. here). | | Corecursion is related to coinduction, and can be used to compute particular instances of (possibly) infinite objects. As a programming technique, it is used most often in the context of lazy programming languages, and can be preferable to recursion when the desired size or precision of a program's output is unknown. In such cases the program requires both a definition for an infinitely large (or infinitely precise) result, and a mechanism for taking a finite portion of that result. The problem of computing the first n prime numbers is one that can be solved with a corecursive program (e.g. here). |
| | | |
− | Corecursion与共归纳相关,可以用来计算(可能)无限对象的特定实例。作为一种编程技术,它最常被用于惰性编程语言中,当程序输出的期望大小或精度未知时,它可以优于递归。在这种情况下,程序既需要一个无限大(或无限精确)结果的定义,又需要一个取该结果有限部分的机制。计算前n个质数的问题是一个可以用一个核心递归程序来解决的问题(例如这里)。
| + | 共递归与协归纳相关,可以用来计算无限规模的对象。作为一种编程技术,它最常被用于 '''<font color="#f668800">惰性编程语言 lazy programming language</font>'''中,当程序输出的大小或精度未知时,使用共递归会比递归更合适。在这种情况下,程序既需要一个无限大(或无限精确)结果的定义,又需要一个取该结果有限部分的机制。计算出前n个质数的问题,就是能用一个核心递归程序来解决的问题。 |
| | | |
| ==Types of recursion== | | ==Types of recursion== |