This PR adds the new transparency setting `@[instance_reducible]`. We
used to check whether a declaration had `instance` reducibility by using
the `isInstance` predicate. However, this was not a robust solution
because:
- We have scoped instances, and `isInstance` returns `true` only if the
scope is active.
- We have auxiliary declarations used to construct instances manually,
such as:
```lean
def lt_wfRel : WellFoundedRelation Nat
```
`isInstance` also returns `false` for this kind of declaration.
In both cases, the declaration may be (or may have been) used to
construct an instance, but `isInstance`
returns `false`. Thus, we claim it is a mistake to check the
reducibility status using `isInstance`.
`isInstance` indicates whether a declaration is available for the type
class resolution mechanism,
not its transparency status.
**We are decoupling whether a declaration is available for type class
resolution from its transparency status.**
**Remak**: We need a update stage0 to complete this feature.
---------
Co-authored-by: Sebastian Ullrich <sebasti@nullri.ch>
47 lines
2.7 KiB
Text
47 lines
2.7 KiB
Text
FooAC.mk {α : Type} [toFooComm : FooComm α] [toMul : Mul.{0} α]
|
||
(add_assoc :
|
||
∀ (a b c : α),
|
||
@Eq.{1} α
|
||
(@HAdd.hAdd.{0, 0, 0} α α α (@instHAdd.{0} α (@Foo.toAdd α (@FooComm.toFoo α toFooComm)))
|
||
(@HAdd.hAdd.{0, 0, 0} α α α (@instHAdd.{0} α (@Foo.toAdd α (@FooComm.toFoo α toFooComm))) a b) c)
|
||
(@HAdd.hAdd.{0, 0, 0} α α α (@instHAdd.{0} α (@Foo.toAdd α (@FooComm.toFoo α toFooComm))) a
|
||
(@HAdd.hAdd.{0, 0, 0} α α α (@instHAdd.{0} α (@Foo.toAdd α (@FooComm.toFoo α toFooComm))) b c)))
|
||
(mul_assoc :
|
||
∀ (a b c : α),
|
||
@Eq.{1} α
|
||
(@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) (@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) a b) c)
|
||
(@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) a (@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) b c)))
|
||
(mul_comm :
|
||
∀ (a b : α),
|
||
@Eq.{1} α (@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) a b)
|
||
(@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) b a)) :
|
||
FooAC α
|
||
@[instance_reducible] def FooAC.toFooAssoc : {α : Type} → [self : FooAC α] → FooAssoc α :=
|
||
fun (α : Type) (self : FooAC α) =>
|
||
@FooAssoc.mk α (@FooComm.toFoo α (@FooAC.toFooComm α self)) (@FooAC.toMul α self) (@FooAC.add_assoc α self)
|
||
(@FooAC.mul_assoc α self)
|
||
FooAC'.mk {α : Type} [toFooComm : FooComm α] [toMul : Mul.{0} α]
|
||
(add_assoc :
|
||
∀ (a b c : α),
|
||
@Eq.{1} α
|
||
(@HAdd.hAdd.{0, 0, 0} α α α (@instHAdd.{0} α (@Foo.toAdd α (@FooComm.toFoo α toFooComm)))
|
||
(@HAdd.hAdd.{0, 0, 0} α α α (@instHAdd.{0} α (@Foo.toAdd α (@FooComm.toFoo α toFooComm))) a b) c)
|
||
(@HAdd.hAdd.{0, 0, 0} α α α (@instHAdd.{0} α (@Foo.toAdd α (@FooComm.toFoo α toFooComm))) a
|
||
(@HAdd.hAdd.{0, 0, 0} α α α (@instHAdd.{0} α (@Foo.toAdd α (@FooComm.toFoo α toFooComm))) b c)))
|
||
(mul_assoc :
|
||
∀ (a b c : α),
|
||
@Eq.{1} α
|
||
(@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) (@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) a b) c)
|
||
(@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) a (@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) b c)))
|
||
(one : α)
|
||
(mul_comm :
|
||
∀ (a b : α),
|
||
@Eq.{1} α (@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) a b)
|
||
(@HMul.hMul.{0, 0, 0} α α α (@instHMul.{0} α toMul) b a)) :
|
||
FooAC' α
|
||
@[instance_reducible] def FooAC'.toFooAssoc' : {α : Type} → [self : FooAC' α] → FooAssoc' α :=
|
||
fun (α : Type) (self : FooAC' α) =>
|
||
@FooAssoc'.mk α
|
||
(@FooAssoc.mk α (@FooComm.toFoo α (@FooAC'.toFooComm α self)) (@FooAC'.toMul α self) (@FooAC'.add_assoc α self)
|
||
(@FooAC'.mul_assoc α self))
|
||
(@FooAC'.one α self)
|