Open dselsam opened 3 years ago
The following works in Lean3:
class Foo (α : Type) := (x : α)
instance (α : Type) : has_coe_to_sort (Foo α) := {
S := Type,
coe := fun _, unit
}
#check @id (Foo.mk ()) () -- works
whereas the following fails in Lean4:
class Foo (α : Type) where x : α
instance : CoeSort (Foo α) Type where coe _ := α
#check @id (Foo.mk ()) () -- fails
It seems that in Lean3, if a function argument type is sort, then has_coe_to_sort
is considered.
Note that if we add the instance instance coeSortToCoe [inst : CoeSort α β] : Coe α β := { coe := inst.coe }
it will still fail because of the universe metavariable in the target type, i.e.
...
[Meta.synthInstance.generate] instance @fooCoeSort
[Meta.synthInstance.tryResolve]
[Meta.synthInstance.tryResolve] CoeSort.{1, ?u.82 + 1} (Foo Unit)
(Sort ?u.82) =?= CoeSort.{1, 2} (Foo ?m.161) Type
[Meta.isDefEq]
[Meta.isDefEq.step] CoeSort.{1, ?u.82 + 1} (Foo Unit) (Sort ?u.82) =?= CoeSort.{1, 2} (Foo ?m.161) Type
[Meta.isDefEq.step] Foo Unit =?= Foo ?m.161
[Meta.isDefEq.step] Foo Unit =?= Foo ?m.161
[Meta.isDefEq.step] Unit =?= ?m.161
[Meta.isDefEq] Unit [nonassignable] =?= ?m.161 [assignable]
[Meta.isDefEq.assign]
[Meta.isDefEq.assign] ?m.161 := Unit
[Meta.isDefEq.assign.beforeMkLambda] ?m.161 [] := Unit
[Meta.isDefEq.assign.checkTypes]
[Meta.isDefEq.step] Type =?= Type
[Meta.isDefEq.assign.final] ?m.161 := Unit
[Meta.isDefEq.step] Sort ?u.82 =?= Type
[Meta.isLevelDefEq.step] ?u.82 =?= 1
[Meta.isLevelDefEq.stuck] ?u.82 =?= 1
Function coercion is missing as well. That is, if you have x : Equiv A B
, then (x : A → B)
won't work.