I'm trying to implement as much of System F (polymorphic lambda calculus) as I can in Idris. I'm now faced with a problem that I want to demonstrate with an example:
data Foo = Bar Nat
Eq Foo where
(Bar _) == (Bar _) = True
data Baz: Foo -> Type where
Quux: (n: Nat) -> Baz (Bar n)
Eq (Baz f) where
(Quux a) == (Quux b) = ?todo
As you can see, any two Foo
values are equal. I would now like to be able to use this fact while defining equality on Baz f
: Quux a
has type Baz (Foo a)
, Quux b
has type Baz (Foo b)
, and Foo a
and Foo b
are equal, so my intuition is that this should work. But the compiler refuses it, saying there's a type mismatch between Baz (Foo a)
and Baz (Foo b)
.
Is there a way to make this work? This issue is stopping me from implementing alpha equivalence.