1
1
mirror of https://github.com/github/semantic.git synced 2025-01-02 12:23:08 +03:00

Add a function computing the FreeAlgorithm for two terms.

This commit is contained in:
Rob Rix 2015-10-05 12:33:59 -04:00
parent 81e80eae50
commit 00ae25a932

View File

@ -94,3 +94,14 @@ extension FreeAlgorithm where A: Equatable {
return evaluate(==)
}
}
func diff<A>(a: Fix<A>, _ b: Fix<A>) -> FreeAlgorithm<A, Free<A, Patch<A>>> {
switch (a.out, b.out) {
case let (.Keyed(a), .Keyed(b)):
return .Roll(.ByKey(a, b, Syntax.Keyed >>> Free.Roll >>> FreeAlgorithm.Pure))
default:
return .Roll(.Recursive(a, b, FreeAlgorithm.Pure))
}
}