mirror of
https://github.com/github/semantic.git
synced 2024-12-26 16:33:03 +03:00
Documentation for hylo
.
This commit is contained in:
parent
b425d69c36
commit
397af0d02d
@ -36,6 +36,13 @@ public enum Syntax<Recur, A>: CustomDebugStringConvertible {
|
||||
|
||||
// MARK: - Hylomorphism
|
||||
|
||||
/// 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`).
|
||||
///
|
||||
/// Hylomorphisms are used to construct diffs corresponding to equal terms; see also `CofreeType.zip`.
|
||||
///
|
||||
/// `hylo` can be used with arbitrary functors which can eliminate to and introduce with `Syntax` values.
|
||||
public func hylo<A, B, Leaf>(down: Syntax<B, Leaf> -> B, _ up: A -> Syntax<A, Leaf>) -> A -> B {
|
||||
return up >>> { $0.map(hylo(down, up)) } >>> down
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user