Zulip Chat Archive
Stream: new members
Topic: failed to synthesize BEq
Benjamin (Dec 12 2024 at 21:59):
I'm trying to run the following code:
def Sequence := List Int
def is_empty (a : Sequence) : Bool := a == []
I get an error saying "failed to synthesize BEq Sequence". This is strange, because the error goes away if I replace Sequence by its definition. How can I fix this?
Kyle Miller (Dec 12 2024 at 22:01):
Unless you want Sequence
to have its own typeclass instances, you can do abbrev Sequence := List Int
to make the definition become transparent for the purpose of typeclass inference.
Benjamin (Dec 12 2024 at 22:03):
Thanks. And if I wanted Sequence to have its own type class instances, what would I do?
Eric Wieser (Dec 12 2024 at 22:31):
You would define your own type class instance for BEq
Kyle Miller (Dec 12 2024 at 22:36):
Option 1: "delta deriving"
def Sequence := List Int
deriving BEq
def is_empty (a : Sequence) : Bool := a == []
Option 2: manually unfolding
def Sequence := List Int
instance : BEq Sequence := inferInstanceAs <| BEq (List Int)
def is_empty (a : Sequence) : Bool := a == []
The first is preferable, but it can be useful to know how to do the second.
Last updated: May 02 2025 at 03:31 UTC