Zulip Chat Archive
Stream: new members
Topic: dependent elimination failed
Vivek Rajesh Joshi (Jun 19 2024 at 05:50):
I'm defining a new function to erase all occurences of an element in a list. Why does it not work with a DecidableEq
instance?
def list_eraseAll [DecidableEq α] : List α → α → List α
| [], _ => []
| a::as, b => match a = b with
| true => list_eraseAll as b
| false => a :: list_eraseAll as b
error:
dependent elimination failed, type mismatch when solving alternative with type
motive (true = true)
but expected
motive x✝
Damiano Testa (Jun 19 2024 at 05:55):
Try using ==
instead of =
(=
is Prop-valued, while ==
is Bool-valued)
Vivek Rajesh Joshi (Jun 19 2024 at 05:57):
It works, but what goes wrong with the Prop-valued =
?
Chris Bailey (Jun 19 2024 at 05:58):
It's not an inductive type with two constructors 'false' and 'true'.
Vivek Rajesh Joshi (Jun 19 2024 at 05:58):
Ahh okay, got it
Chris Bailey (Jun 19 2024 at 06:01):
You can use the DecidableEq instance in its prop form with an if-then-else:
def list_eraseAll [DecidableEq α] : List α → α → List α
| [], _ => []
| a::as, b =>
if a = b
then list_eraseAll as b
else a :: list_eraseAll as b
Vivek Rajesh Joshi (Jun 19 2024 at 06:02):
I see, thanks!
Last updated: May 02 2025 at 03:31 UTC