I am starting in Coq and discovered that I have to provide a proof of decidable equality to use List.remove. e.g.
Require Import Coq.Lists.List.
Import List.ListNotations.
Inductive T : Set := A | B | C.
Lemma eq_dec : forall a b : T, {a = b} + {a <> b}.
Proof.
destruct a, b; try (left; reflexivity); try (right; congruence).
Qed.
Definition f (xs : list T) : list T := List.remove eq_dec A xs.
This now type-checks, but I don't understand how to use it.
Theorem foo : f [ A; B; C ] = [ B; C ].
Proof. reflexivity.
gives me
Error: Unable to unify "[B; C]" with "f [A; B; C]".
How does this decidable equality work and what is some good source I could read about it?
Edit 1
I just learned about the decide equality tactic, which
solves a goal of the form
forall x y:R, {x=y}+{~x=y}, where R is an inductive type such that its constructors do not take proofs or functions as arguments, nor objects in dependent types.
So eq_dec can rewriten:
Lemma eq_dec : forall a b : T, {a = b} + {a <> b}.
Proof. decide equality. Defined.
Edit 2
I just learned about the Scheme Equality for T command, which
Tries to generate a Boolean equality and a proof of the decidability of the usual equality. If identi involves some other inductive types, their equality has to be defined first.
So T_beq : T -> T -> bool and T_eq_dec : forall x y : T, {x = y} + {x <> y} can be automatically generated.