Zulip Chat Archive
Stream: new members
Topic: method ident space sensitivity
Xiyu Zhai (Mar 04 2024 at 22:26):
I do not understand the following
-- incorrect
-- errors
-- type mismatch
-- List.all as
-- has type
-- (Nat → Bool) → Bool : Type
-- but is expected to have type
-- Bool : TypeLean 4
def method_without_space(as: List Nat): Bool :=
as.all(fun a => true)
-- correct
def method_with_space(as: List Nat): Bool :=
as.all (fun a => true)
Xiyu Zhai (Mar 04 2024 at 22:26):
Why a space is needed after as.all
Simon Daniel (Mar 04 2024 at 22:43):
to apply a function you write the function name and then the arguments seperated by spaces
Xiyu Zhai (Mar 04 2024 at 22:43):
I see
Xiyu Zhai (Mar 04 2024 at 22:43):
So if not spaced, what will the compiler see it as? Maybe this is not an interesting question
Simon Daniel (Mar 04 2024 at 22:46):
i found this book very useful as a referenceFunctional Programming Book
Simon Daniel (Mar 04 2024 at 22:47):
Xiyu Zhai said:
So if not spaced, what will the compiler see it as? Maybe this is not an interesting question
I also get the message: unexpected token '('; expected command, so i guess its simply not valid to omit the space
Xiyu Zhai (Mar 04 2024 at 22:49):
Oh, I didn't notice that
It seems that type error and syntax error get mixed up and I only saw the type error.
Xiyu Zhai (Mar 04 2024 at 22:50):
type mismatch
List.all allocations
has type
(BareMetalMemoryAllocation → Bool) → Bool : Type
but is expected to have type
Prop : TypeLean 4
unexpected token '('; expected commandLean 4
Xiyu Zhai (Mar 04 2024 at 22:50):
I would suggest it's better to have a original/derived error system. Only show those errors that are original.
Xiyu Zhai (Mar 04 2024 at 22:51):
In CPP, the error system is notorious because it's too hard to find the original one.
Simon Daniel (Mar 04 2024 at 23:05):
seeing only the type error would be indeed confusing
if youre using VSCode the Lean Info view shows 2 seperate messages in this case
Xiyu Zhai (Mar 04 2024 at 23:06):
Indeed I’m using Vscode
Xiyu Zhai (Mar 04 2024 at 23:07):
But I only see the type error if I’m not hovering my mouse over the ‘(‘
Simon Daniel (Mar 04 2024 at 23:11):
btw i think it just ignores the part after '(' for the type error, since "as.all" has type (Nat → Bool) → Bool
Last updated: May 02 2025 at 03:31 UTC