1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 00:42:33 +03:00

Matuschak denormalization of ==.

This commit is contained in:
Rob Rix 2015-07-18 15:46:34 -04:00
parent 5e0f00edce
commit bed4b7bca9
5 changed files with 60 additions and 58 deletions

View File

@ -20,6 +20,7 @@
D4AAE5481B5AE2D0004E581F /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53D1B5AE2D0004E581F /* String.swift */; };
D4AAE5491B5AE2D0004E581F /* StringLiteralConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53E1B5AE2D0004E581F /* StringLiteralConvertible.swift */; };
D4AAE54A1B5AE2D0004E581F /* Syntax.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53F1B5AE2D0004E581F /* Syntax.swift */; };
D4AAE54C1B5AE42D004E581F /* Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE54B1B5AE42D004E581F /* Equatable.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -49,6 +50,7 @@
D4AAE53D1B5AE2D0004E581F /* String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
D4AAE53E1B5AE2D0004E581F /* StringLiteralConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringLiteralConvertible.swift; sourceTree = "<group>"; };
D4AAE53F1B5AE2D0004E581F /* Syntax.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Syntax.swift; sourceTree = "<group>"; };
D4AAE54B1B5AE42D004E581F /* Equatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Equatable.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -102,6 +104,7 @@
D4AAE53D1B5AE2D0004E581F /* String.swift */,
D4AAE53E1B5AE2D0004E581F /* StringLiteralConvertible.swift */,
D4AAE53F1B5AE2D0004E581F /* Syntax.swift */,
D4AAE54B1B5AE42D004E581F /* Equatable.swift */,
D4AAE5001B5AE22E004E581F /* Supporting Files */,
);
path = Doubt;
@ -237,6 +240,7 @@
D4AAE5481B5AE2D0004E581F /* String.swift in Sources */,
D4AAE5411B5AE2D0004E581F /* Diff.swift in Sources */,
D4AAE5401B5AE2D0004E581F /* Array.swift in Sources */,
D4AAE54C1B5AE42D004E581F /* Equatable.swift in Sources */,
D4AAE54A1B5AE2D0004E581F /* Syntax.swift in Sources */,
D4AAE5421B5AE2D0004E581F /* Doc.swift in Sources */,
D4AAE5461B5AE2D0004E581F /* Parse.swift in Sources */,

View File

@ -24,17 +24,6 @@ enum Diff: CustomDocConvertible, Equatable {
}
}
func == (left: Diff, right: Diff) -> Bool {
switch (left, right) {
case let (.Patch(a1, b1), .Patch(a2, b2)):
return a1 == a2 && b1 == b2
case let (.Copy(a), .Copy(b)):
return a() == b()
default:
return false
}
}
func diff(a: Syntax<Fix>, _ b: Syntax<Fix>) -> Diff {
switch (a, b) {

View File

@ -43,25 +43,6 @@ enum Doc<Payload>: AlgebraicType, CustomStringConvertible {
}
}
func == <F: Equatable> (left: Doc<F>, right: Doc<F>) -> Bool {
switch (left, right) {
case (.Empty, .Empty):
return true
case let (.Text(a), .Text(b)):
return a == b
case let (.Horizontal(a), .Horizontal(b)):
return a == b
case let (.Vertical(a), .Vertical(b)):
return a == b
case let (.Wrap(a1, b1, c1), .Wrap(a2, b2, c2)):
return a1 == a2 && b1 == b2 && c1 == c2
case let (.Join(s1, e1), .Join(s2, e2)):
return s1 == s2 && e1 == e2
default:
return false
}
}
struct Pretty: CustomStringConvertible, Equatable, FixpointType {
init<T>(_ value: T) {
@ -101,10 +82,6 @@ struct Pretty: CustomStringConvertible, Equatable, FixpointType {
}
}
func == (left: Pretty, right: Pretty) -> Bool {
return true
}
protocol CustomDocConvertible: CustomStringConvertible {
var doc: Doc<Pretty> { get }

56
Doubt/Equatable.swift Normal file
View File

@ -0,0 +1,56 @@
func == (left: Fix, right: Fix) -> Bool {
return left.out == right.out
}
func == <F: Equatable> (left: Syntax<F>, right: Syntax<F>) -> Bool {
switch (left, right) {
case let (.Apply(a, aa), .Apply(b, bb)):
return a == b && aa == bb
case let (.Abstract(p1, b1), .Abstract(p2, b2)):
return p1 == p2 && b1 == b2
case let (.Assign(n1, v1), .Assign(n2, v2)):
return n1 == n2 && v1 == v2
case let (.Variable(n1), .Variable(n2)):
return n1 == n2
case let (.Literal(l1), .Literal(l2)):
return l1 == l2
case let (.Group(n1, v1), .Group(n2, v2)):
return n1 == n2 && v1 == v2
default:
return false
}
}
func == (left: Diff, right: Diff) -> Bool {
switch (left, right) {
case let (.Patch(a1, b1), .Patch(a2, b2)):
return a1 == a2 && b1 == b2
case let (.Copy(a), .Copy(b)):
return a() == b()
default:
return false
}
}
func == <F: Equatable> (left: Doc<F>, right: Doc<F>) -> Bool {
switch (left, right) {
case (.Empty, .Empty):
return true
case let (.Text(a), .Text(b)):
return a == b
case let (.Horizontal(a), .Horizontal(b)):
return a == b
case let (.Vertical(a), .Vertical(b)):
return a == b
case let (.Wrap(a1, b1, c1), .Wrap(a2, b2, c2)):
return a1 == a2 && b1 == b2 && c1 == c2
case let (.Join(s1, e1), .Join(s2, e2)):
return s1 == s2 && e1 == e2
default:
return false
}
}
func == (left: Pretty, right: Pretty) -> Bool {
return true
}

View File

@ -25,11 +25,6 @@ struct Fix: CustomDebugStringConvertible, CustomDocConvertible, CustomStringConv
}
}
func == (left: Fix, right: Fix) -> Bool {
return left.out == right.out
}
enum Syntax<Payload>: AlgebraicType, CustomDebugStringConvertible, CustomDocConvertible {
case Apply(Payload, [Payload])
case Abstract([Payload], Payload)
@ -106,25 +101,6 @@ enum Syntax<Payload>: AlgebraicType, CustomDebugStringConvertible, CustomDocConv
}
}
func == <F: Equatable> (left: Syntax<F>, right: Syntax<F>) -> Bool {
switch (left, right) {
case let (.Apply(a, aa), .Apply(b, bb)):
return a == b && aa == bb
case let (.Abstract(p1, b1), .Abstract(p2, b2)):
return p1 == p2 && b1 == b2
case let (.Assign(n1, v1), .Assign(n2, v2)):
return n1 == n2 && v1 == v2
case let (.Variable(n1), .Variable(n2)):
return n1 == n2
case let (.Literal(l1), .Literal(l2)):
return l1 == l2
case let (.Group(n1, v1), .Group(n2, v2)):
return n1 == n2 && v1 == v2
default:
return false
}
}
func cata<T>(f: Syntax<T> -> T)(_ term: Fix) -> T {
return (Fix.out >>> { $0.map(cata(f)) } >>> f)(term)