forked from gracelang/minigrace
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathequalityBundle.grace
41 lines (35 loc) · 1.22 KB
/
equalityBundle.grace
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
dialect "none"
import "intrinsic" as intrinsic
import "basicTypesBundle" as basicTypesBundle
use intrinsic.annotations
use basicTypesBundle.open
trait open {
trait equality {
method == (other) is required
method hash is required // should obey invariant (a == b) => (a.hash == b.hash)
method ≠ (other) { (self == other).not }
method :: (obj) { binding.key (self) value (obj) }
method matches (other) { self == other }
}
trait identityEquality {
use equality
method == (other) { self.isMe(other) }
method hash { self.myIdentityHash }
}
class binding⟦K, T⟧ {
method asString { "the binding factory" }
class key(k)value(v) {
use equality
def key is public = k
def value is public = v
method asString { "{key}::{value}" }
method asDebugString { "{key.asDebugString}::{value.asDebugString}" }
method hash { intrinsic.hashCombine (key.hash, value.hash) }
method == (other) {
match (other)
case { o:Binding -> (key == o.key) && (value == o.value) }
else { false }
}
}
}
}