Zulip Chat Archive
Stream: lean4
Topic: Use local instance
Marcus Rossel (Aug 30 2022 at 11:37):
In the following setting, the HashMap a.type Nat
declaration fails because failed to synthesize instance BEq a.type
:
structure A where
type : Type
[beq : BEq a]
[hashable : Hashable a]
structure B where
a : A
map : HashMap a.type Nat
What I'm trying to express in A
is that type
is some type which is equatable and hashable. Is this the right approach? If so, how do I make use of the local instances later on?
Gabriel Ebner (Aug 30 2022 at 11:38):
You're running into two issues here.
Gabriel Ebner (Aug 30 2022 at 11:39):
1) You need to write BEq type
instead of BEq a
. [beq : BEq a]
means [beq : ∀ {a}, BEq a]
.
Gabriel Ebner (Aug 30 2022 at 11:39):
2) You need to mark A.beq
and A.hashable
as instances.
Gabriel Ebner (Aug 30 2022 at 11:39):
and 0) you need to import Std
and open Std
#mwe
Gabriel Ebner (Aug 30 2022 at 11:40):
import Std
structure A where
type : Type
[beq : BEq type]
[hashable : Hashable type]
attribute [instance] A.beq A.hashable
structure B where
a : A
map : Std.HashMap a.type Nat
Marcus Rossel (Aug 30 2022 at 11:40):
Gabriel Ebner said:
You need to write
BEq type
instead ofBEq a
Sorry, that was just bad copy paste.
Marcus Rossel (Aug 30 2022 at 11:41):
Thanks!
Last updated: Dec 20 2023 at 11:08 UTC