From b0cb77ae74156bafe3450a66d0398879f78c7547 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 14 Oct 2015 18:42:20 -0400 Subject: [PATCH 1/9] Define catamorphisms over TermTypes. --- prototype/Doubt/TermType.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/prototype/Doubt/TermType.swift b/prototype/Doubt/TermType.swift index 1b02855c8..efec72b2c 100644 --- a/prototype/Doubt/TermType.swift +++ b/prototype/Doubt/TermType.swift @@ -6,6 +6,13 @@ public protocol TermType { } +extension TermType { + public func cata(transform: Syntax -> Result) -> Result { + return self |> ({ $0.out } >>> { $0.map { $0.cata(transform) } } >>> transform) + } +} + + extension Fix: TermType {} extension Cofree: TermType { @@ -13,3 +20,6 @@ extension Cofree: TermType { return unwrap } } + + +import Prelude From b4a95647474238705679433b4e72395e643d7ba1 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 14 Oct 2015 18:47:20 -0400 Subject: [PATCH 2/9] TermType has a size property. --- prototype/Doubt/TermType.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/prototype/Doubt/TermType.swift b/prototype/Doubt/TermType.swift index efec72b2c..ca29409f8 100644 --- a/prototype/Doubt/TermType.swift +++ b/prototype/Doubt/TermType.swift @@ -10,6 +10,21 @@ extension TermType { public func cata(transform: Syntax -> Result) -> Result { return self |> ({ $0.out } >>> { $0.map { $0.cata(transform) } } >>> transform) } + + + /// The size of the receiver. + public var size: Int { + return cata { + switch $0 { + case .Leaf: + return 1 + case let .Indexed(i): + return i.reduce(1, combine: +) + case let .Keyed(k): + return k.values.reduce(1, combine: +) + } + } + } } From 32c55fd5ffba75fd68693bb23028c0107600c676 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 14 Oct 2015 18:48:15 -0400 Subject: [PATCH 3/9] Add a section for PatchConvertible. --- prototype/Doubt/Patch.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prototype/Doubt/Patch.swift b/prototype/Doubt/Patch.swift index ac9c15fb7..169c4eeaa 100644 --- a/prototype/Doubt/Patch.swift +++ b/prototype/Doubt/Patch.swift @@ -105,6 +105,8 @@ extension Patch where A: CustomJSONConvertible { } +// MARK: - PatchConvertible + /// A hack to enable constrained extensions on `Free>`. public protocol PatchConvertible { typealias Element From 230394bde23a886c4d637915bc5f09bd2c77474a Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 14 Oct 2015 18:51:07 -0400 Subject: [PATCH 4/9] Charge diffs a cost proportional to their size. This can no longer be done in SES, as it requires knowledge that the elements of the arrays are of TermType. --- prototype/Doubt/Algorithm.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/prototype/Doubt/Algorithm.swift b/prototype/Doubt/Algorithm.swift index 1c171fc67..6118812ce 100644 --- a/prototype/Doubt/Algorithm.swift +++ b/prototype/Doubt/Algorithm.swift @@ -52,6 +52,18 @@ public enum Algorithm { let recurOrReplace = { recur($0, $1) ?? .Pure(.Replace($0, $1)) } + func cost(diff: Diff) -> Int { + return diff.map { abs(($0.state.before?.size ?? 0) - ($0.state.after?.size ?? 0)) }.iterate { syntax in + switch syntax { + case .Leaf: + return 0 + case let .Indexed(costs): + return costs.reduce(0, combine: +) + case let .Keyed(costs): + return costs.values.reduce(0, combine: +) + } + } + } switch self { case let .Pure(b): return b From 7c099bac6ff42d08c138a9faee5bb875d384790e Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 14 Oct 2015 18:51:18 -0400 Subject: [PATCH 5/9] Parameterize SES by the cost function. --- prototype/Doubt/Algorithm.swift | 2 +- prototype/Doubt/SES.swift | 15 +-------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/prototype/Doubt/Algorithm.swift b/prototype/Doubt/Algorithm.swift index 6118812ce..fd8ac7cfd 100644 --- a/prototype/Doubt/Algorithm.swift +++ b/prototype/Doubt/Algorithm.swift @@ -94,7 +94,7 @@ public enum Algorithm { return f(Dictionary(elements: deleted + inserted + patched)).evaluate(equals, recur: recur) case let .Roll(.ByIndex(a, b, f)): - return f(SES(a, b, recur: recur)).evaluate(equals, recur: recur) + return f(SES(a, b, cost: cost, recur: recur)).evaluate(equals, recur: recur) } } } diff --git a/prototype/Doubt/SES.swift b/prototype/Doubt/SES.swift index 93404de5a..1b2f2777f 100644 --- a/prototype/Doubt/SES.swift +++ b/prototype/Doubt/SES.swift @@ -1,25 +1,12 @@ /// Computes the SES (shortest edit script), i.e. the shortest sequence of diffs (`Free>`) for two arrays of `Term`s 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: [Term], _ b: [Term], recur: (Term, Term) -> Free>?) -> [Free>] { +public func SES(a: [Term], _ b: [Term], cost: Free> -> Int, recur: (Term, Term) -> Free>?) -> [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)) } } - func cost(diff: Diff) -> Int { - return diff.map(const(1)).iterate { syntax in - switch syntax { - case .Leaf: - return 0 - case let .Indexed(costs): - return costs.reduce(0, combine: +) - case let .Keyed(costs): - return costs.values.reduce(0, combine: +) - } - } - } - func cons(diff: Diff, rest: Memo>) -> Stream<(Diff, Int)> { return .Cons((diff, cost(diff) + costOfStream(rest)), rest) } From e582f289721909be4c1ce7e8885c39c91be23a77 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 14 Oct 2015 18:51:52 -0400 Subject: [PATCH 6/9] Charge a constant cost for the tests. --- prototype/DoubtTests/SESTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype/DoubtTests/SESTests.swift b/prototype/DoubtTests/SESTests.swift index 641c366b5..a1a57dee7 100644 --- a/prototype/DoubtTests/SESTests.swift +++ b/prototype/DoubtTests/SESTests.swift @@ -57,7 +57,7 @@ private let c = Term.Leaf("c") private let d = Term.Leaf("d") private func SES(a: [Term], _ b: [Term]) -> [Diff] { - return SES(a, b) { $0 == $1 ? Diff($1) : nil } + return SES(a, b, cost: const(1)) { $0 == $1 ? Diff($1) : nil } } private func == (a: [Diff], b: [Diff]) -> Bool { From b93a605b377a6ee42f77dd9cbb4a5472fae9d035 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 14 Oct 2015 21:07:30 -0400 Subject: [PATCH 7/9] Document `cata`. --- prototype/Doubt/TermType.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/prototype/Doubt/TermType.swift b/prototype/Doubt/TermType.swift index ca29409f8..4df5bb7fd 100644 --- a/prototype/Doubt/TermType.swift +++ b/prototype/Doubt/TermType.swift @@ -7,6 +7,9 @@ public protocol TermType { 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(transform: Syntax -> Result) -> Result { return self |> ({ $0.out } >>> { $0.map { $0.cata(transform) } } >>> transform) } From f55ceade22a9474c660dfaa833c46d8ad4a71d40 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 14 Oct 2015 21:10:09 -0400 Subject: [PATCH 8/9] Replace the fixtures with newer, even more exciting ones. --- prototype/doubt-json/Fixtures/a.json | 2497 +++++++++++++++++++++----- prototype/doubt-json/Fixtures/b.json | 1659 +++++++++++++++-- 2 files changed, 3522 insertions(+), 634 deletions(-) diff --git a/prototype/doubt-json/Fixtures/a.json b/prototype/doubt-json/Fixtures/a.json index 136ab3fec..ee3b48acb 100644 --- a/prototype/doubt-json/Fixtures/a.json +++ b/prototype/doubt-json/Fixtures/a.json @@ -1,478 +1,2073 @@ -[ - [{ - "literal": { - "source": "Algorithm", - "categories": [ +[{ + "insert": { + "extract": 29, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ - ] + ] + }, + "source": { + "extract": 1, + "unwrap": "Algorithm" + } } - }, - [ - [{ - "literal": { - "source": "Recursive", - "categories": [ - - ] - } - }, - [ - - ] - ], - [{ - "literal": { - "source": "ByKey", - "categories": [ - - ] - } - }, - [ - - ] - ], { - "insert": [{ - "literal": { - "source": "ByIndex", - "categories": [ + }, { + "extract": 25, + "unwrap": [{ + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ ] - } - }, - [ - - ] - ] - }, { - "literal": { - "source": "mark", - "categories": [ - - ] - } - }, - [{ - "literal": { - "source": "map(_:)", - "categories": [ - - ] - } - }, - [ - - ] - ] - ] - ], { - "insert": [{ - "literal": { - "source": "FreeAlgorithm", - "categories": [ - - ] - } - }, - [ - [{ - "literal": { - "source": "Pure", - "categories": [ - - ] - } - }, - [ - - ] - ], - [{ - "literal": { - "source": "Roll", - "categories": [ - - ] - } - }, - [ - - ] - ], - [{ - "literal": { - "source": "analysis(ifPure:ifRoll:)", - "categories": [ - - ] - } - }, - [ - - ] - ], { - "literal": { - "source": "mark", - "categories": [ - - ] - } - }, - [{ - "literal": { - "source": "map(_:)", - "categories": [ - - ] - } - }, - [ - - ] - ], { - "literal": { - "source": "mark", - "categories": [ - - ] - } - }, - [{ - "literal": { - "source": "flatMap(_:)", - "categories": [ - - ] - } - }, - [ - - ] - ], - [{ - "literal": { - "source": "evaluate(_:recur:)", - "categories": [ - - ] - } - }, - [ - - ] - ] - ] - ] - }, { - "replace": { - "before": { - "literal": { - "source": "mark", - "categories": [ - - ] - } - }, - "after": [{ - "literal": { - "source": "FreeAlgorithm", - "categories": [ - - ] - } - }, - [ - [{ - "literal": { - "source": "evaluate(_:)", - "categories": [ - - ] - } }, - [ - - ] - ] - ] - ] - } - }, { - "delete": [{ - "literal": { - "source": "Algorithm", - "categories": [ + "source": { + "extract": 1, + "unwrap": "Recursive" + } + } + }, { + "extract": 1, + "unwrap": [ ] - } - }, - [ - [{ - "literal": { - "source": "evaluate(_:)", - "categories": [ + }] + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ ] + }, + "source": { + "extract": 1, + "unwrap": "ByKey" } - }, - [ - [{ - "literal": { - "source": "copy(_:)", - "categories": [ + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 6, + "unwrap": { + "insert": { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ ] + }, + "source": { + "extract": 1, + "unwrap": "ByIndex" } - }, - [ + } + }, { + "extract": 1, + "unwrap": [ ] - ] - ] - ] - ] - ] - }, { - "delete": [{ - "literal": { - "source": "FreeAlgorithm", - "categories": [ - - ] - } - }, - [ - [{ - "literal": { - "source": "Pure", - "categories": [ - - ] - } - }, - [ - - ] - ], - [{ - "literal": { - "source": "Roll", - "categories": [ - - ] - } - }, - [ - - ] - ], - [{ - "literal": { - "source": "analysis(ifPure:ifRoll:)", - "categories": [ - - ] - } - }, - [ - - ] - ], { - "literal": { - "source": "mark", - "categories": [ - - ] + }] } - }, - [{ - "literal": { - "source": "map(_:)", - "categories": [ - - ] - } - }, - [ - - ] - ], { - "literal": { - "source": "mark", - "categories": [ + } + }, { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ ] + }, + "source": { + "extract": 1, + "unwrap": "mark" } - }, - [{ - "literal": { - "source": "flatMap(_:)", - "categories": [ - - ] - } - }, - [ - - ] - ], - [{ - "literal": { - "source": "evaluate(_:)", - "categories": [ - - ] - } - }, - [ - - ] - ] - ] - ] - }, { - "delete": [{ - "literal": { - "source": "FreeAlgorithm", - "categories": [ - - ] } - }, - [ - [{ - "literal": { - "source": "evaluate()", - "categories": [ + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ ] + }, + "source": { + "extract": 1, + "unwrap": "map(_:)" } - }, - [ - - ] - ] - ] - ] - }, - [{ - "literal": { - "source": "FreeConvertible", - "categories": [ - - ] - } - }, - [ - [{ - "literal": { - "source": "init(free:)", - "categories": [ - - ] } - }, - [ - - ] - ], { - "literal": { - "source": "free", - "categories": [ + }, { + "extract": 1, + "unwrap": [ ] - } - } - ] - ], - [{ - "literal": { - "source": "Free", - "categories": [ - - ] - } - }, - [ - [{ - "literal": { - "source": "init(free:)", - "categories": [ - - ] - } - }, - [ - - ] - ], { - "literal": { - "source": "free", - "categories": [ - - ] - } - } - ] - ], - [{ - "literal": { - "source": "FreeAlgorithm", - "categories": [ - - ] - } - }, - [ - [{ - "literal": { - "source": "init(_:_:)", - "categories": [ - - ] - } - }, - [ - - ] - ], { - "insert": [{ - "literal": { - "source": "evaluate(_:)", - "categories": [ - - ] - } - }, - [ - - ] - ] - } - ] - ], { - "insert": [{ - "literal": { - "source": "FreeAlgorithm", - "categories": [ - - ] - } - }, - [ - [{ - "literal": { - "source": "evaluate()", - "categories": [ - - ] - } - }, - [ - - ] - ] - ] - ] + }] + }] + }] } -] +}, { + "insert": { + "extract": 42, + "unwrap": { + "insert": { + "extract": 41, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + }, { + "extract": 37, + "unwrap": [{ + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Pure" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Roll" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "analysis(ifPure:ifRoll:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "map(_:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "flatMap(_:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:recur:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + } + } + } +}, { + "insert": { + "extract": 15, + "unwrap": { + "replace": { + "extract": 14, + "unwrap": { + "before": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + }, + "after": { + "extract": 10, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + }, { + "extract": 6, + "unwrap": [{ + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + } + } + } + } + } +}, { + "insert": { + "extract": 16, + "unwrap": { + "delete": { + "extract": 15, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Algorithm" + } + } + }, { + "extract": 11, + "unwrap": [{ + "extract": 10, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + }, { + "extract": 6, + "unwrap": [{ + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "copy(_:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + }] + }] + } + } + } +}, { + "insert": { + "extract": 42, + "unwrap": { + "delete": { + "extract": 41, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + }, { + "extract": 37, + "unwrap": [{ + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Pure" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Roll" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "analysis(ifPure:ifRoll:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "map(_:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "flatMap(_:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + } + } + } +}, { + "replace": { + "before": { + "extract": 35, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Algorithm" + } + } + } + } + }, { + "extract": 30, + "unwrap": [{ + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Recursive" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "ByKey" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 7, + "unwrap": { + "insert": { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "ByIndex" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + } + }, { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "map(_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + }, + "after": { + "extract": 11, + "unwrap": { + "delete": { + "extract": 10, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + }, { + "extract": 6, + "unwrap": [{ + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate()" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + } + } + } + } +}, { + "delete": { + "extract": 51, + "unwrap": { + "insert": { + "extract": 50, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + } + }, { + "extract": 45, + "unwrap": [{ + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Pure" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Roll" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "analysis(ifPure:ifRoll:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "map(_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "flatMap(_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:recur:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + } + } + } +}, { + "delete": { + "extract": 18, + "unwrap": { + "replace": { + "extract": 17, + "unwrap": { + "before": { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, + "after": { + "extract": 12, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + } + }, { + "extract": 7, + "unwrap": [{ + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + } + } + } + } + } +}, { + "replace": { + "before": { + "extract": 19, + "unwrap": { + "delete": { + "extract": 18, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Algorithm" + } + } + } + } + }, { + "extract": 13, + "unwrap": [{ + "extract": 12, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + } + } + }, { + "extract": 7, + "unwrap": [{ + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "copy(_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + }] + }] + } + } + }, + "after": { + "extract": 13, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeConvertible" + } + } + }, { + "extract": 9, + "unwrap": [{ + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "init(free:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "free" + } + } + }] + }] + } + } +}, { + "replace": { + "before": { + "extract": 51, + "unwrap": { + "delete": { + "extract": 50, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + } + }, { + "extract": 45, + "unwrap": [{ + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Pure" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Roll" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "analysis(ifPure:ifRoll:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "map(_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "flatMap(_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + } + } + }, + "after": { + "extract": 13, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Free" + } + } + }, { + "extract": 9, + "unwrap": [{ + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "init(free:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "free" + } + } + }] + }] + } + } +}, { + "replace": { + "before": { + "extract": 13, + "unwrap": { + "delete": { + "extract": 12, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + } + }, { + "extract": 7, + "unwrap": [{ + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate()" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + } + } + }, + "after": { + "extract": 16, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + }, { + "extract": 12, + "unwrap": [{ + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "init(_:_:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 6, + "unwrap": { + "insert": { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + } + }] + }] + } + } +}, { + "delete": { + "extract": 16, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeConvertible" + } + } + } + } + }, { + "extract": 11, + "unwrap": [{ + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "init(free:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "free" + } + } + } + } + }] + }] + } +}, { + "delete": { + "extract": 16, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Free" + } + } + } + } + }, { + "extract": 11, + "unwrap": [{ + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "init(free:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "free" + } + } + } + } + }] + }] + } +}, { + "replace": { + "before": { + "extract": 19, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + } + }, { + "extract": 14, + "unwrap": [{ + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "init(_:_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, { + "extract": 7, + "unwrap": { + "insert": { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + } + }] + }] + }, + "after": { + "extract": 11, + "unwrap": { + "insert": { + "extract": 10, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + }, { + "extract": 6, + "unwrap": [{ + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate()" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + } + } + } + } +}, { + "delete": { + "extract": 13, + "unwrap": { + "insert": { + "extract": 12, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + } + }, { + "extract": 7, + "unwrap": [{ + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate()" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }] + }] + } + } + } +}] diff --git a/prototype/doubt-json/Fixtures/b.json b/prototype/doubt-json/Fixtures/b.json index d72eceb71..8444a4db9 100644 --- a/prototype/doubt-json/Fixtures/b.json +++ b/prototype/doubt-json/Fixtures/b.json @@ -1,52 +1,214 @@ [ [{ - "source": "Algorithm", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Algorithm" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "Algorithm" + } + } }, [ [{ - "source": "Recursive", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Recursive" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "Recursive" + } + } }, [ ] ], [{ - "source": "ByKey", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "ByKey" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "ByKey" + } + } }, [ ] ], { "insert": [{ - "source": "ByIndex", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "ByIndex" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "ByIndex" + } + } }, [ ] ] }, { - "source": "mark", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "mark" + } + } }, [{ - "source": "map(_:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "map(_:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "map(_:)" + } + } }, [ @@ -55,77 +217,365 @@ ] ], { "insert": [{ - "source": "FreeAlgorithm", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } }, - [ - [{ - "source": "Pure", - "categories": [ + [{ + "delete": { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ - ] + ] + }, + "source": { + "extract": 1, + "unwrap": "Pure" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + }, + [{ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ + + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Roll" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "Pure" + } + } }, [ ] ], [{ - "source": "Roll", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] - }, - [ + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ - ] - ], - [{ - "source": "analysis(ifPure:ifRoll:)", - "categories": [ - - ] + ] + }, + "source": { + "extract": 1, + "unwrap": "analysis(ifPure:ifRoll:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "Roll" + } + } }, [ ] ], { - "source": "mark", - "categories": [ + "replace": { + "before": { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ - ] + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, + "after": { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "analysis(ifPure:ifRoll:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + } + }, { + "replace": { + "before": { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "map(_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, + "after": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, { + "replace": { + "before": { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, + "after": { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "map(_:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + } + }, { + "insert": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } }, [{ - "source": "map(_:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] - }, - [ + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ - ] - ], { - "source": "mark", - "categories": [ - - ] - }, - [{ - "source": "flatMap(_:)", - "categories": [ - - ] + ] + }, + "source": { + "extract": 1, + "unwrap": "flatMap(_:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "flatMap(_:)" + } + } }, [ ] ], [{ - "source": "evaluate(_:recur:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:recur:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "evaluate(_:recur:)" + } + } }, [ @@ -135,52 +585,214 @@ ] }, { "replace": { - "before": { - "source": "mark", - "categories": [ - - ] - }, "after": [{ - "source": "FreeAlgorithm", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } }, [ [{ - "source": "evaluate(_:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } }, [ ] ] ] - ] + ], + "before": { + "categories": { + "insert": { + "extract": 1, + "unwrap": [ + + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "mark" + } + } + } } }, { "delete": [{ - "source": "Algorithm", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Algorithm" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "Algorithm" + } + } }, [ [{ - "source": "evaluate(_:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } }, [ [{ - "source": "copy(_:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "copy(_:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "copy(_:)" + } + } }, [ @@ -192,77 +804,365 @@ ] }, { "delete": [{ - "source": "FreeAlgorithm", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } }, - [ - [{ - "source": "Pure", - "categories": [ + [{ + "delete": { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ - ] + ] + }, + "source": { + "extract": 1, + "unwrap": "Pure" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + }, + [{ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ + + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "Roll" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "Pure" + } + } }, [ ] ], [{ - "source": "Roll", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] - }, - [ + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ - ] - ], - [{ - "source": "analysis(ifPure:ifRoll:)", - "categories": [ - - ] + ] + }, + "source": { + "extract": 1, + "unwrap": "analysis(ifPure:ifRoll:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "Roll" + } + } }, [ ] ], { - "source": "mark", - "categories": [ + "replace": { + "before": { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ - ] + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, + "after": { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "analysis(ifPure:ifRoll:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + } + }, { + "replace": { + "before": { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "map(_:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + }, + "after": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, { + "replace": { + "before": { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } + } + }, + "after": { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "map(_:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + } + }, { + "insert": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "mark" + } + } + } }, [{ - "source": "map(_:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] - }, - [ + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ - ] - ], { - "source": "mark", - "categories": [ - - ] - }, - [{ - "source": "flatMap(_:)", - "categories": [ - - ] + ] + }, + "source": { + "extract": 1, + "unwrap": "flatMap(_:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "flatMap(_:)" + } + } }, [ ] ], [{ - "source": "evaluate(_:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } }, [ @@ -272,17 +1172,71 @@ ] }, { "delete": [{ - "source": "FreeAlgorithm", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } }, [ [{ - "source": "evaluate()", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate()" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "evaluate()" + } + } }, [ @@ -292,75 +1246,360 @@ ] }, [{ - "source": "FreeConvertible", - "categories": [ - - ] - }, - [ - [{ - "source": "init(free:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ ] - }, - [ + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ - ] - ], { - "source": "free", - "categories": [ - - ] + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeConvertible" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "FreeConvertible" + } } - ] + }, + [{ + "delete": { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "init(free:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + }, { + "replace": { + "before": { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "free" + } + } + } + } + }, + "after": { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "init(free:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + } + }, { + "insert": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "free" + } + } + } + }] ], [{ - "source": "Free", - "categories": [ - - ] - }, - [ - [{ - "source": "init(free:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ ] - }, - [ + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ - ] - ], { - "source": "free", - "categories": [ - - ] + ] + }, + "source": { + "extract": 1, + "unwrap": "Free" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "Free" + } } - ] + }, + [{ + "delete": { + "extract": 6, + "unwrap": [{ + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "init(free:)" + } + } + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + }, { + "replace": { + "before": { + "extract": 4, + "unwrap": { + "literal": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "free" + } + } + } + } + }, + "after": { + "extract": 5, + "unwrap": [{ + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "init(free:)" + } + } + }, { + "extract": 1, + "unwrap": [ + + ] + }] + } + } + }, { + "insert": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "free" + } + } + } + }] ], [{ - "source": "FreeAlgorithm", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } }, [ [{ - "source": "init(_:_:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "init(_:_:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "init(_:_:)" + } + } }, [ ] ], { "insert": [{ - "source": "evaluate(_:)", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "evaluate(_:)" + } + } }, [ @@ -370,17 +1609,71 @@ ] ], { "insert": [{ - "source": "FreeAlgorithm", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "FreeAlgorithm" + } + } }, [ [{ - "source": "evaluate()", - "categories": [ + "categories": { + "insert": { + "extract": 1, + "unwrap": [ - ] + ] + } + }, + "literal": { + "delete": { + "extract": 3, + "unwrap": { + "categories": { + "extract": 1, + "unwrap": [ + + ] + }, + "source": { + "extract": 1, + "unwrap": "evaluate()" + } + } + } + }, + "source": { + "insert": { + "extract": 1, + "unwrap": "evaluate()" + } + } }, [ From e2e55ef041a54ee017ee555bbdb66838a512fc72 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 15 Oct 2015 13:45:30 -0400 Subject: [PATCH 9/9] Document the purpose of `size`. --- prototype/Doubt/TermType.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/prototype/Doubt/TermType.swift b/prototype/Doubt/TermType.swift index 316bda408..a686c311a 100644 --- a/prototype/Doubt/TermType.swift +++ b/prototype/Doubt/TermType.swift @@ -15,7 +15,9 @@ extension TermType { } - /// The size of the receiver. + /// The count of nodes in the receiver. + /// + /// This is used to compute the cost of patches, such that a patch inserting a very large tree will be charged approximately the same as a very large tree consisting of many small patches. public var size: Int { return cata { switch $0 {