From f8cd049280a6e11c4f1d5246947dc61d322b2d31 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 15 Oct 2015 15:39:55 -0400 Subject: [PATCH] Add a function from categorization functions to comparable functions. --- prototype/Doubt/Interpreter.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/prototype/Doubt/Interpreter.swift b/prototype/Doubt/Interpreter.swift index c60cc8b53..128d9c373 100644 --- a/prototype/Doubt/Interpreter.swift +++ b/prototype/Doubt/Interpreter.swift @@ -16,6 +16,14 @@ public struct Interpreter { self.cost = cost } + + /// Computes a term comparable function from a categorizing function. + public static func comparable(categorize: Term -> Set)(_ a: Term, _ b: Term) -> Bool { + let c0 = categorize(a) + let c1 = categorize(b) + return c0 == c1 || !categorize(a).intersect(categorize(b)).isEmpty + } + /// Computes a diff cost function from a patch cost function. public static func cost(cost: Patch -> Int)(_ diff: Diff) -> Int { return diff.map(cost).reduce(0, combine: +)