@@ -11,6 +11,7 @@ structure Label : Type 1 where
11
11
[classesEnum : FinEnum ClassId]
12
12
[classesRepr : Repr ClassId]
13
13
[classesBEq : BEq ClassId]
14
+ [classesDecidableEq : DecidableEq ClassId]
14
15
15
16
MultiMethodId : Type := Empty
16
17
/-- Type of multiMethod arguments excluding `self` arguments. -/
@@ -24,6 +25,7 @@ structure Label : Type 1 where
24
25
[multiMethodsFinite : FinEnum MultiMethodId]
25
26
[multiMethodsRepr : Repr MultiMethodId]
26
27
[multiMethodsBEq : BEq MultiMethodId]
28
+ [multiMethodsLawfulBEq : LawfulBEq MultiMethodId]
27
29
28
30
instance Label.hasTypeRep : TypeRep Label where
29
31
rep := Rep.atomic "AVM.Ecosystem.Label"
@@ -127,6 +129,47 @@ inductive MemberId (lab : Ecosystem.Label) where
127
129
128
130
namespace MemberId
129
131
132
+ instance instBEq {lab : Ecosystem.Label} : BEq (MemberId lab) where
133
+ beq a b :=
134
+ have := lab.classesDecidableEq
135
+ match a, b with
136
+ | .multiMethodId m1, .multiMethodId m2 =>
137
+ have := lab.multiMethodsBEq
138
+ m1 == m2
139
+ | .multiMethodId _ , _ => false
140
+ | _, .multiMethodId _ => false
141
+ | .classMember (classId := c1) m1, classMember (classId := c2) m2 =>
142
+ if h : c1 = c2
143
+ then m1 == h ▸ m2
144
+ else false
145
+
146
+ instance instReflBEq {lab : Ecosystem.Label} : ReflBEq (MemberId lab) where
147
+ rfl := by
148
+ have := lab.multiMethodsLawfulBEq
149
+ intro a; cases a
150
+ unfold BEq.beq instBEq; simp
151
+ case classMember classId classMem =>
152
+ unfold BEq.beq instBEq;
153
+ have i : ReflBEq classId.MemberId := @Class.Label.MemberId.instReflBEq classId.label
154
+ simp
155
+
156
+ -- TODO simplify
157
+ instance instLawfulBEq {lab : Ecosystem.Label} : LawfulBEq lab.MemberId where
158
+ eq_of_beq := by
159
+ intro a b e
160
+ have i := lab.multiMethodsLawfulBEq
161
+ unfold BEq.beq instBEq at e; simp at e; split at e; simp
162
+ apply i.eq_of_beq
163
+ assumption
164
+ contradiction
165
+ contradiction
166
+ split at e
167
+ case h_4.isTrue _ _ _ _ h =>
168
+ subst h;
169
+ have x := Class.Label.MemberId.instLawfulBEq.eq_of_beq e
170
+ subst x; simp
171
+ contradiction
172
+
130
173
abbrev SignatureId (lab : Ecosystem.Label) : MemberId lab → Type
131
174
| .classMember m => m.SignatureId
132
175
| _ => Empty
@@ -139,14 +182,6 @@ abbrev Args {lab : Ecosystem.Label} (memberId : MemberId lab) : SomeType :=
139
182
abbrev Signatures {lab : Ecosystem.Label} (m : MemberId lab) (args : m.Args.type) : Type :=
140
183
m.SignatureId → Signature args
141
184
142
- instance hasBEq (lab : Ecosystem.Label) : BEq (Ecosystem.Label.MemberId lab) where
143
- beq a b :=
144
- match a, b with
145
- | multiMethodId c1, multiMethodId c2 => lab.multiMethodsBEq.beq c1 c2
146
- | multiMethodId _, _ => false
147
- | _, multiMethodId _ => false
148
- | classMember c1, classMember c2 => c1 === c2
149
-
150
185
def numObjectArgs {lab : Ecosystem.Label} (memberId : MemberId lab) : Nat :=
151
186
match memberId with
152
187
| multiMethodId f => f.numObjectArgs
0 commit comments