diff --git a/prototype/Doubt/Algorithm.swift b/prototype/Doubt/Algorithm.swift
index fdce72a1f..844e90a61 100644
--- a/prototype/Doubt/Algorithm.swift
+++ b/prototype/Doubt/Algorithm.swift
@@ -8,7 +8,7 @@ public enum Algorithm {
public typealias Term = Fix
/// The type of `Patch`es produced by `Algorithm`s.
- public typealias Patch = Doubt.Patch
+ public typealias Patch = Doubt.Patch
/// The type of `Diff`s which `Algorithm`s produce.
public typealias Diff = Free
diff --git a/prototype/Doubt/Free.swift b/prototype/Doubt/Free.swift
index fdb23df4f..35dc108b4 100644
--- a/prototype/Doubt/Free.swift
+++ b/prototype/Doubt/Free.swift
@@ -107,7 +107,7 @@ public enum Free: CustomDebugStringConvertible, CustomDocConvertible, Synt
}
-extension Free where B: PatchConvertible, B.Element == A {
+extension Free where B: PatchConvertible, B.Element == Fix {
public typealias Term = Fix
private func discardNullTerms(syntax: Syntax) -> Term? {
@@ -190,9 +190,9 @@ extension Free where A: CustomJSONConvertible {
}
}
-extension Free where A: CustomJSONConvertible, B: PatchConvertible, B.Element == A {
+extension Free where A: CustomJSONConvertible, B: PatchConvertible, B.Element == Fix {
public var JSON: Doubt.JSON {
- return JSON { $0.patch.JSON }
+ return JSON { $0.patch.JSON { $0.JSON } }
}
}
diff --git a/prototype/Doubt/Patch.swift b/prototype/Doubt/Patch.swift
index 631db0fce..057694d1b 100644
--- a/prototype/Doubt/Patch.swift
+++ b/prototype/Doubt/Patch.swift
@@ -1,10 +1,10 @@
/// A patch to some part of a `Syntax` tree.
public enum Patch: CustomDebugStringConvertible, CustomDocConvertible {
- case Replace(Fix, Fix)
- case Insert(Fix)
- case Delete(Fix)
+ case Replace(A, A)
+ case Insert(A)
+ case Delete(A)
- public var state: (before: Fix?, after: Fix?) {
+ public var state: (before: A?, after: A?) {
switch self {
case let .Replace(a, b):
return (a, b)
@@ -56,8 +56,8 @@ public enum Patch: CustomDebugStringConvertible, CustomDocConvertible {
// MARK: CustomDocConvertible
public var doc: Doc {
- return (state.before?.doc.bracket("{-", "-}") ?? .Empty)
- <> (state.after?.doc.bracket("{+", "+}") ?? .Empty)
+ return (state.before.map(Doc.init)?.bracket("{-", "-}") ?? .Empty)
+ <> (state.after.map(Doc.init)?.bracket("{+", "+}") ?? .Empty)
}
}
@@ -66,8 +66,8 @@ public enum Patch: CustomDebugStringConvertible, CustomDocConvertible {
extension Patch {
public static func equals(param: (A, A) -> Bool)(_ left: Patch, _ right: Patch) -> Bool {
- return Optional.equals(Fix.equals(param))(left.state.before, right.state.before)
- && Optional.equals(Fix.equals(param))(left.state.after, right.state.after)
+ return Optional.equals(param)(left.state.before, right.state.before)
+ && Optional.equals(param)(left.state.after, right.state.after)
}
}
@@ -77,8 +77,8 @@ extension Patch {
extension Patch {
public func hash(param: A -> Hash) -> Hash {
return Hash.Ordered([
- state.before.map { $0.hash(param) } ?? Hash.Empty,
- state.after.map { $0.hash(param) } ?? Hash.Empty
+ state.before.map(param) ?? Hash.Empty,
+ state.after.map(param) ?? Hash.Empty
])
}
}
@@ -92,17 +92,17 @@ extension Patch {
case let .Replace(a, b):
return [
"replace": [
- "before": a.JSON(ifLeaf),
- "after": b.JSON(ifLeaf),
+ "before": ifLeaf(a),
+ "after": ifLeaf(b),
]
]
case let .Insert(b):
return [
- "insert": b.JSON(ifLeaf),
+ "insert": ifLeaf(b),
]
case let .Delete(a):
return [
- "delete": a.JSON(ifLeaf)
+ "delete": ifLeaf(a)
]
}
}
@@ -111,12 +111,12 @@ extension Patch {
extension Patch where A: CustomJSONConvertible {
public var JSON: Doubt.JSON {
- return self.JSON { $0.JSON }
+ return JSON { $0.JSON }
}
}
-/// A hack to enable constrained extensions on `Free>`.
+/// A hack to enable constrained extensions on `Free>`.
public protocol PatchConvertible {
typealias Element
diff --git a/prototype/Doubt/SES.swift b/prototype/Doubt/SES.swift
index 7f9c342b8..b6c76a570 100644
--- a/prototype/Doubt/SES.swift
+++ b/prototype/Doubt/SES.swift
@@ -1,9 +1,9 @@
/// Computes the SES (shortest edit script), i.e. the shortest sequence of diffs (`Free>`) for two arrays of terms (`Fix`) which would suffice to transform `a` into `b`.
///
/// This is computed w.r.t. an `equals` function, which computes the equality of leaf nodes within terms, and a `recur` function, which produces diffs representing matched-up terms.
-public func SES(a: [Fix], _ b: [Fix], recur: (Fix, Fix) -> Free>) -> [Free>] {
+public func SES(a: [Fix], _ b: [Fix], recur: (Fix, Fix) -> Free>>) -> [Free>>] {
typealias Term = Fix
- typealias Diff = Free>
+ typealias Diff = Free>
if a.isEmpty { return b.map { Diff.Pure(Patch.Insert($0)) } }
if b.isEmpty { return a.map { Diff.Pure(Patch.Delete($0)) } }
diff --git a/prototype/DoubtTests/SESTests.swift b/prototype/DoubtTests/SESTests.swift
index 8df9cce6e..2fb313588 100644
--- a/prototype/DoubtTests/SESTests.swift
+++ b/prototype/DoubtTests/SESTests.swift
@@ -49,7 +49,7 @@ private func delete(term: Term) -> Diff {
}
private typealias Term = Fix
-private typealias Diff = Free>
+private typealias Diff = Free>>
private let a = Term.Leaf(.Literal("a", []))
private let b = Term.Leaf(.Literal("b", []))