1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 16:33:03 +03:00

Rename the TermType.LeafType associated type to Leaf.

This commit is contained in:
Rob Rix 2015-10-22 10:17:51 -04:00
parent 7eed54dcdc
commit 03aa95caf9
5 changed files with 12 additions and 12 deletions

View File

@ -8,7 +8,7 @@ public enum Algorithm<Term: TermType, Result> {
public typealias Patch = Doubt.Patch<Term>
/// The type of `Diff`s which `Algorithm`s produce.
public typealias Diff = Free<Term.LeafType, Patch>
public typealias Diff = Free<Term.Leaf, Patch>
/// The injection of a value of type `Result` into an `Operation`.
///

View File

@ -13,8 +13,8 @@ public enum Free<Leaf, Value>: CustomDebugStringConvertible, SyntaxConvertible {
indirect case Roll(Syntax<Free, Leaf>)
/// Recursively copies a `Term: TermType where Term.LeafType == Leaf` into a `Free<Leaf, Value>`, essentially mapping `Term.unwrap` onto `Free.Roll`.
public init<Term: TermType where Term.LeafType == Leaf>(_ term: Term) {
/// Recursively copies a `Term: TermType where Term.Leaf == Leaf` into a `Free<Leaf, Value>`, essentially mapping `Term.unwrap` onto `Free.Roll`.
public init<Term: TermType where Term.Leaf == Leaf>(_ term: Term) {
self = .Roll(term.unwrap.map(Free.init))
}
@ -188,7 +188,7 @@ public func == <Leaf: Equatable, Value: Equatable> (left: Free<Leaf, Value>, rig
return Free.equals(ifPure: ==, ifRoll: ==)(left, right)
}
public func == <Term: TermType where Term.LeafType: Equatable> (left: Free<Term.LeafType, Patch<Term>>, right: Free<Term.LeafType, Patch<Term>>) -> Bool {
public func == <Term: TermType where Term.Leaf: Equatable> (left: Free<Term.Leaf, Patch<Term>>, right: Free<Term.Leaf, Patch<Term>>) -> Bool {
return Free.equals(ifPure: Patch.equals(Term.equals(==)), ifRoll: ==)(left, right)
}

View File

@ -1,7 +1,7 @@
/// An interpreter of `Algorithm`s.
public struct Interpreter<Term: TermType> {
/// The type of diffs constructed by `Interpreter`s.
public typealias Diff = Free<Term.LeafType, Patch<Term>>
public typealias Diff = Free<Term.Leaf, Patch<Term>>
/// Constructs an `Interpreter` parameterized by the `equal` and `comparable` tests on `Term`s, and the `cost` function for `Diff`s.
///
@ -92,7 +92,7 @@ public struct Interpreter<Term: TermType> {
// MARK: - Constrained constructors
extension Interpreter where Term.LeafType: Equatable {
extension Interpreter where Term.Leaf: Equatable {
public init(comparable: (Term, Term) -> Bool, cost: Diff -> Int) {
self.init(equal: Term.equals(==), comparable: comparable, cost: cost)
}

View File

@ -130,7 +130,7 @@ extension Patch where A: CustomJSONConvertible {
// MARK: - PatchType
/// A hack to enable constrained extensions on `Free<A, Patch<Term: TermType where LeafType == A>`.
/// A hack to enable constrained extensions on `Free<Leaf, Patch<Term: TermType where Term.Leaf == Leaf>`.
public protocol PatchType {
typealias Element

View File

@ -1,8 +1,8 @@
/// The type of terms.
public protocol TermType {
typealias LeafType
typealias Leaf
var unwrap: Syntax<Self, LeafType> { get }
var unwrap: Syntax<Self, Leaf> { get }
}
@ -10,14 +10,14 @@ extension TermType {
/// Catamorphism over `TermType`s.
///
/// Folds the tree encoded by the receiver into a single value by recurring top-down through the tree, applying `transform` to leaves, then to branches, and so forth.
public func cata<Result>(transform: Syntax<Result, LeafType> -> Result) -> Result {
public func cata<Result>(transform: Syntax<Result, Leaf> -> Result) -> Result {
return self |> ({ $0.unwrap } >>> { $0.map { $0.cata(transform) } } >>> transform)
}
/// Paramorphism over `TermType`s.
///
/// Folds the tree encoded by the receiver into a single value by recurring top-down through the tree, applying `transform` to leaves, then to branches, and so forth. Each recursive instance is made available in the `Syntax` alongside the result value at that node.
public func para<Result>(transform: Syntax<(Self, Result), LeafType> -> Result) -> Result {
public func para<Result>(transform: Syntax<(Self, Result), Leaf> -> Result) -> Result {
return self |> ({ $0.unwrap } >>> { $0.map { ($0, $0.para(transform)) } } >>> transform)
}
@ -46,7 +46,7 @@ extension Cofree: TermType {}
// MARK: - Equality
extension TermType {
public static func equals(leaf: (LeafType, LeafType) -> Bool)(_ a: Self, _ b: Self) -> Bool {
public static func equals(leaf: (Leaf, Leaf) -> Bool)(_ a: Self, _ b: Self) -> Bool {
return Syntax.equals(ifLeaf: leaf, ifRecur: equals(leaf))(a.unwrap, b.unwrap)
}
}