Zulip Chat Archive
Stream: new members
Topic: List from repeated elements?
R Dong (Dec 06 2024 at 15:55):
I tried looking at the List
documentation in the manual (there is none) and the list of autocompletion from VSCode, but I can't find how to create a list from repeated elements. By which I mean something like repeat a 5
giving [a, a, a, a, a]
. How do I do this in Lean? Do I have to write the function myself?
Michael Stoll (Dec 06 2024 at 15:56):
R Dong (Dec 06 2024 at 16:07):
Thanks, I didn't look at the mathlib docs
R Dong (Dec 06 2024 at 16:07):
BTW, is Nat
and \N
two different types?
Julian Berman (Dec 06 2024 at 16:10):
(Those are really the Lean core docs, they're just built and shown as part of the Mathlib docs, presumably until the Language Reference subsumes them as a better place to look.)
Julian Berman (Dec 06 2024 at 16:10):
\N is notation defined in Mathlib for Nat
.
Michael Stoll (Dec 06 2024 at 16:11):
import Mathlib.Data.Nat.Notation
#check ℕ
Julian Berman (Dec 06 2024 at 16:12):
(wrong)
Julian Berman (Dec 06 2024 at 16:12):
Ah wait no, they're not the same. Never mind.
Michael Stoll (Dec 06 2024 at 16:12):
R Dong (Dec 06 2024 at 16:13):
example f (n : ℕ) : List ℕ := List.replicate n 42
failed to synthesize
OfNat ℕ 42
numerals are polymorphic in Lean, but the numeral `42` cannot be used in a context where the expected type is
ℕ
due to the absence of the instance above
Additional diagnostic information may be available using the `set_option diagnostics true` command.
Michael Stoll (Dec 06 2024 at 16:14):
You need to import Mathlib.Data.Nat.Notation
at the very least.
R Dong (Dec 06 2024 at 16:14):
Ok
R Dong (Dec 06 2024 at 16:15):
Hmmm, unknown module Mathlib
Michael Stoll (Dec 06 2024 at 16:16):
See here.
R Dong (Dec 06 2024 at 16:17):
I didn't run lake update
Last updated: May 02 2025 at 03:31 UTC