Zulip Chat Archive
Stream: lean4
Topic: Empty string refl
Scott Viteri (May 06 2021 at 16:38):
Lean3: theorem hi : "".data = [] := by refl
Lean4: example : "".data = [] := by ?
Kevin Buzzard (May 06 2021 at 17:09):
example : "".data = [] := rfl -- fails
#eval "".data == [] -- true
#reduce "".data == [] -- aargh
#reduce "".data -- "".1
Andrew Kent (May 06 2021 at 17:20):
Interestingly String
and Array
seem to behave differently in this regard:
example : #[].data = ([] : List Char) := by rfl -- works
Both are defined in Prelude.lean
and have custom efficient C/C++ implementations backing them. Perhaps this difference is related to the comment by Array
's definition stating "The Compiler has special support for arrays." and the lack of such a comment for String
...? :shrug:
Daniel Selsam (May 06 2021 at 17:50):
This works:
example : (String.mk []).data = ([] : List Char) := rfl
I think the issue is just that WHNF
sees a String
literal and doesn't realize it is morally an application of constructor String.mk
and so can project.
Daniel Selsam (May 06 2021 at 17:52):
It seems fixable by adding a String-literal case to https://github.com/leanprover/lean4/blob/master/src/Lean/MonadEnv.lean#L58-L62
Last updated: Dec 20 2023 at 11:08 UTC