mirror of
https://github.com/github/semantic.git
synced 2024-12-26 16:33:03 +03:00
coiterate → ana
This commit is contained in:
parent
f5ae79ebaa
commit
9b310b8c78
@ -125,8 +125,8 @@ extension CofreeType {
|
||||
/// 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 syntax’s 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`, it’s unsurprising that we have a similar guarantee: coiteration is linear in the size of the constructed tree.
|
||||
public static func coiterate(unfold: Annotation -> Syntax<Annotation, Leaf>)(_ seed: Annotation) -> Self {
|
||||
return (Introduce(seed) <<< { $0.map(coiterate(unfold)) } <<< unfold) <| seed
|
||||
public static func ana(unfold: Annotation -> Syntax<Annotation, Leaf>)(_ seed: Annotation) -> Self {
|
||||
return (Introduce(seed) <<< { $0.map(ana(unfold)) } <<< unfold) <| seed
|
||||
}
|
||||
|
||||
/// `Zip` two `CofreeType` values into a single `Cofree`, pairing their annotations.
|
||||
|
@ -112,8 +112,8 @@ extension Free {
|
||||
/// Anamorphism over `Free`.
|
||||
///
|
||||
/// Unfolds a tree bottom-up by recursively applying `transform` to a series of values starting with `seed`. Since `Syntax.Leaf` does not recur, this will halt when it has produced leaves for every branch.
|
||||
public static func coiterate(unfold: Annotation -> Syntax<Annotation, Leaf>)(_ seed: Annotation) -> Free {
|
||||
return (Introduce(seed) <<< { $0.map(coiterate(unfold)) } <<< unfold) <| seed
|
||||
public static func ana(unfold: Annotation -> Syntax<Annotation, Leaf>)(_ seed: Annotation) -> Free {
|
||||
return (Introduce(seed) <<< { $0.map(ana(unfold)) } <<< unfold) <| seed
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ public enum Syntax<Recur, A>: CustomDebugStringConvertible {
|
||||
|
||||
/// Hylomorphism through `Syntax`.
|
||||
///
|
||||
/// A hylomorphism (from the Aristotelian philosophy that form and matter are one) is a function of type `A → B` whose call-tree is linear in the size of the nodes produced by `up`. Conceptually, it’s the composition of a catamorphism (see also `TermType.cata`, `Free.iterate`) and an anamorphism (see also `Free.ana`, `CofreeType.coiterate`), but is implemented by [Stream fusion](http://lambda-the-ultimate.org/node/2192) and as such enjoys O(n) time complexity, O(1) size complexity, and small constant factors for both (modulo inadvisable implementations of `up` and `down`).
|
||||
/// A hylomorphism (from the Aristotelian philosophy that form and matter are one) is a function of type `A → B` whose call-tree is linear in the size of the nodes produced by `up`. Conceptually, it’s the composition of a catamorphism (see also `TermType.cata`, `Free.iterate`) and an anamorphism (see also `ana`), but is implemented by [Stream fusion](http://lambda-the-ultimate.org/node/2192) and as such enjoys O(n) time complexity, O(1) size complexity, and small constant factors for both (modulo inadvisable implementations of `up` and `down`).
|
||||
///
|
||||
/// Hylomorphisms are used to construct diffs corresponding to equal terms; see also `CofreeType.zip`.
|
||||
///
|
||||
@ -49,7 +49,7 @@ public func hylo<A, B, Leaf>(down: Syntax<B, Leaf> -> B, _ up: A -> Syntax<A, Le
|
||||
|
||||
/// Reiteration through `Syntax`.
|
||||
///
|
||||
/// This is a form of hylomorphism (from the Aristotelian philosophy that form and matter are one). As such, it returns a function of type `A → B` whose call-tree is linear in the size of the nodes produced by `up`. Conceptually, it’s the composition of a catamorphism (see also `TermType.cata`, `Free.iterate`) and an anamorphism (see also `Free.ana`, `CofreeType.coiterate`), but is implemented by [Stream fusion](http://lambda-the-ultimate.org/node/2192) and as such enjoys O(n) time complexity, O(1) size complexity, and small constant factors for both (modulo inadvisable implementations of `up` and `down`).
|
||||
/// This is a form of hylomorphism (from the Aristotelian philosophy that form and matter are one). As such, it returns a function of type `A → B` whose call-tree is linear in the size of the nodes produced by `up`. Conceptually, it’s the composition of a catamorphism (see also `TermType.cata`, `Free.iterate`) and an anamorphism (see also `ana`), but is implemented by [Stream fusion](http://lambda-the-ultimate.org/node/2192) and as such enjoys O(n) time complexity, O(1) size complexity, and small constant factors for both (modulo inadvisable implementations of `up` and `down`).
|
||||
///
|
||||
/// Hylomorphisms are used to construct diffs corresponding to equal terms; see also `CofreeType.zip`.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user