Zulip Chat Archive
Stream: Is there code for X?
Topic: Decidable List equal empty.
Wrenna Robson (Nov 22 2024 at 12:27):
Do we not have this?
import Mathlib
namespace List
instance {l : List α} : Decidable (l = []) := decidable_of_iff _ List.length_eq_zero
end List
Wrenna Robson (Nov 22 2024 at 12:27):
It seems like an obvious thing to have but I can't find it!
Yakov Pechersky (Nov 22 2024 at 12:35):
Unfortunately this likely clashes with other Decidable when DecidableEq
Yakov Pechersky (Nov 22 2024 at 12:37):
In what situation do you need this? It's probably fine to have Decidable (l = []) as a TC assumption. Are you trying to avoid writing this instance argument?
Eric Wieser (Nov 22 2024 at 13:23):
I assume the motivation here is that DecidableEq α
does not hold; can you avoid this by using if let [] := l then _ else _
instead of if l = [] then _ else _
?
Wrenna Robson (Nov 22 2024 at 15:26):
I actually found a way round it for now
Violeta Hernández (Dec 09 2024 at 06:08):
Seems weird to need this, surely you can just match on l
instead?
Kyle Miller (Dec 09 2024 at 17:56):
docs#List.isEmpty is one of the main ways to avoid this. You can write if l.isEmpty then _ else _
.
Kyle Miller (Dec 09 2024 at 17:58):
The expression version of Eric's suggestion is if l matches [] then _ else _
. It can be nicer since it doesn't need to be the top-level of the if
condition, but l.isEmpty
wins out if you're counting characters.
Wrenna Robson (Dec 09 2024 at 18:24):
Aye. I basically think sometimes we use "l = []" in theorems when we should use that
Eric Wieser (Dec 11 2024 at 22:38):
One is a bool and the other a Prop, so we should generally use the one that doesn't cause a superfluous coercion
Last updated: May 02 2025 at 03:31 UTC