1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 02:44:36 +03:00

Document coiterate as an anamorphism.

This commit is contained in:
Rob Rix 2015-10-22 12:55:06 -04:00
parent f145bb4293
commit 6bcbccfe08

View File

@ -21,7 +21,7 @@ public enum Cofree<A, B> {
/// Constructs a cofree by coiteration.
///
/// The initial seed is used as the annotation of the returned value. The continuation of the structure is unpacked by applying `annotate` to the seed and mapping the resulting syntaxs values recursively. In this manner, the structure is unfolded bottom-up, starting with `seed` and ending at the leaves.
/// This is an _anamorphism_ (from the Greek ana, upwards; compare anabolism), a generalization of unfolds over regular trees (and datatypes isomorphic to them). The initial seed is used as the annotation of the returned value. The continuation of the structure is unpacked by applying `annotate` to the seed and mapping the resulting syntaxs values recursively. In this manner, the structure is unfolded bottom-up, starting with `seed` and ending at the leaves.
///
/// As this is the dual of `Free.iterate`, its unsurprising that we have a similar guarantee: coiteration is linear in the size of the constructed tree.
public static func coiterate(annotate: B -> Syntax<B, A>)(_ seed: B) -> Cofree {