Zulip Chat Archive
Stream: new members
Topic: Error for List \a exercises?
Leona (Aug 19 2025 at 21:07):
I am working through "Dependent Types in Lean" and having some technical trouble with the midchapter exercises for List types. When I try to copy the example code into VS Code, it returns errors on all the theorems, even when marked as "sorry".
For example, the following is marked as an error, saying it expects type "sorry" for rfl:
theorem nil_append (as : List α) : append nil as = as :=
rfl
What's up with this?
Ruben Van de Velde (Aug 19 2025 at 21:09):
I get
Function expected at
append
but this term has type
?m.2
Note: Expected a function because this term is being applied to the argument
nil
which indicates you forgot imports in your code
Aaron Liu (Aug 19 2025 at 21:11):
Can you link to "Dependent Type in Lean"?
Leona (Aug 19 2025 at 21:12):
https://leanprover.github.io/theorem_proving_in_lean4/Inductive-Types/#other-recursive-data-types
Aaron Liu (Aug 19 2025 at 21:13):
oh it's #tpil
Leona (Aug 19 2025 at 21:13):
Sorry, "Theorem Proving in Lean"
Leona (Aug 19 2025 at 21:13):
yes, my bad
Aaron Liu (Aug 19 2025 at 21:14):
I clicked on "show hidden lines" and it gave me
namespace Hidden
inductive List (α : Type u) where
| nil : List α
| cons : α → List α → List α
namespace List
def append (as bs : List α) : List α :=
match as with
| nil => bs
| cons a as => cons a (append as bs)
theorem nil_append (as : List α) : append nil as = as :=
rfl
theorem cons_append (a : α) (as bs : List α)
: append (cons a as) bs = cons a (append as bs) :=
rfl
theorem append_nil (as : List α) :
append as nil = as :=
sorry
theorem append_assoc (as bs cs : List α) :
append (append as bs) cs = append as (append bs cs) :=
sorry
end List
end Hidden
Leona (Aug 19 2025 at 21:15):
yes i copied that into my ide, still got the errors
Aaron Liu (Aug 19 2025 at 21:15):
the "copy" gives me
namespace Hidden
inductive List (α : Type u) where
| nil : List α
| cons : α → List α → List α
namespace List
def append (as bs : List α) : List α :=
match as with
| nil => bs
| cons a as => cons a (append as bs)
theorem nil_append (as : List α) : append nil as = as :=
rfl
theorem cons_append (a : α) (as bs : List α)
: append (cons a as) bs = cons a (append as bs) :=
rfl
namespace Hidden
inductive List (α : Type u) where
| nil : List α
| cons : α → List α → List α
namespace List
def append (as bs : List α) : List α :=
match as with
| nil => bs
| cons a as => cons a (append as bs)
theorem nil_append (as : List α) : append nil as = as :=
rfl
theorem cons_append (a : α) (as bs : List α)
: append (cons a as) bs = cons a (append as bs) :=
rfl
theorem append_nil (as : List α) :
append as nil = as :=
sorry
theorem append_assoc (as bs cs : List α) :
append (append as bs) cs = append as (append bs cs) :=
sorry
end List
end Hidden
Aaron Liu (Aug 19 2025 at 21:15):
it seems there's a problem with "copy"
Leona (Aug 19 2025 at 21:16):
ahh, hmm
strange!
Leona (Aug 19 2025 at 21:18):
Aaron Liu said:
I clicked on "show hidden lines" and it gave me
namespace Hidden inductive List (α : Type u) where | nil : List α | cons : α → List α → List α namespace List def append (as bs : List α) : List α := match as with | nil => bs | cons a as => cons a (append as bs) theorem nil_append (as : List α) : append nil as = as := rfl theorem cons_append (a : α) (as bs : List α) : append (cons a as) bs = cons a (append as bs) := rfl theorem append_nil (as : List α) : append as nil = as := sorry theorem append_assoc (as bs cs : List α) : append (append as bs) cs = append as (append bs cs) := sorry end List end Hidden
even copying this still throws up the errors!
Aaron Liu (Aug 19 2025 at 21:18):
It works fine in the web editor
Aaron Liu (Aug 19 2025 at 21:19):
what's the error you are experiencing?
Leona (Aug 19 2025 at 21:19):
Application type mismatch: In the application
append nil
the argument
nil
has type
List ?m.15230 : Type ?u.15229
but is expected to have type
Type : Type 1
Aaron Liu (Aug 19 2025 at 21:20):
what's your definition of append?
Leona (Aug 19 2025 at 21:21):
ahhh, just supplied the argument \a before nil and it checks!
Leona (Aug 19 2025 at 21:22):
The exercise had the type for append wrong
Last updated: Dec 20 2025 at 21:32 UTC