From 24c66eb1ff8b6164df7b8cd7d1b0b0414d70f417 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 15 Oct 2015 15:28:21 -0400 Subject: [PATCH] Convenience constructor taking a Patch cost function. --- prototype/Doubt/Interpreter.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/prototype/Doubt/Interpreter.swift b/prototype/Doubt/Interpreter.swift index 5b547ef94..cdc3d85a8 100644 --- a/prototype/Doubt/Interpreter.swift +++ b/prototype/Doubt/Interpreter.swift @@ -16,6 +16,11 @@ public struct Interpreter { self.cost = cost } + /// Constructs an `Interpreter` parameterized by the `equal` and `comparable` tests on `Term`s, and the `cost` function for `Patch`es. + public init(equal: (Term, Term) -> Bool, comparable: (Term, Term) -> Bool, cost: Patch -> Int) { + self.init(equal: equal, comparable: comparable, cost: { $0.map(cost).reduce(0, combine: +) }) + } + /// Run the interpreter over a given pair of `Term`s, producing a `Diff` as its result. public func run(a: Term, _ b: Term) -> Diff {