Co-authored-by: Ohad Kammar <ohad.kammar@gmail.com>
YE3EAD3XYKXRHEJN4VLBVBQM2EISKFHAESPOZ6S4QMLA6YZEVDQQC
data LinkedListEquiv : (a, b : LinkedList t) -> Type where
BothEmpty : LinkedListEquiv Nil Nil
EquivHeadAndTail : Equivalence t => {a, b : t} -> {x, y : LinkedList t}
data LinkedListEquiv : Equivalence t => (a, b : LinkedList t) -> Type where
BothEmpty : (e : Equivalence t) => LinkedListEquiv @{e} Nil Nil
EquivHeadAndTail : (e : Equivalence t) => {a, b : t} -> {x, y : LinkedList t}
decEquiv Nil Nil = Yes $ BothEmpty
decEquiv Nil (_ :: _) = No $ absurd
decEquiv (_ :: _) Nil = No $ absurd
decEquiv (h1 :: t1) (h2 :: t2) = case (decEquiv h1 h2, decEquiv t1 t2) of
decLinkedListEquiv : (e : Equivalence t) => (a, b : LinkedList t) -> Dec (LinkedListEquiv @{e} a b)
decLinkedListEquiv Nil Nil = Yes $ BothEmpty
decLinkedListEquiv Nil (_ :: _) = No $ absurd
decLinkedListEquiv (_ :: _) Nil = No $ absurd
decLinkedListEquiv @{e} (h1 :: t1) (h2 :: t2) = assert_total $
case (decEquiv @{e} h1 h2, decLinkedListEquiv t1 t2) of
(Yes prf1, No ctra2) => No $ fromNotEquivTail ctra2
(No ctra1, _) => No $ fromNotEquivHead ctra1
_ => ?impossibleCase -- TODO: Upstream bug
(Yes prf1, No ctra2) => No $ fromNotEquivTail @{e} ctra2
(No ctra1, _) => No $ fromNotEquivHead @{e} ctra1
public export
(Equivalence t) => Equivalence (LinkedList t) where
Equiv = LinkedListEquiv
decEquiv = decLinkedListEquiv
data OptionalEquiv : (a, b : Optional t) -> Type where
BothNothing : OptionalEquiv Nothing Nothing
BothSame : Equivalence t => {a, b : t} -> (ok : Equiv a b) -> OptionalEquiv (Some a) (Some b)
data OptionalEquiv : Equivalence t => (a, b : Optional t) -> Type where
BothNothing : (e : Equivalence t) => OptionalEquiv @{e} Nothing Nothing
BothSame : (e : Equivalence t) => {a, b : t} -> (ok : Equiv a b)
-> OptionalEquiv @{e} (Some a) (Some b)