Zulip Chat Archive
Stream: lean4
Topic: How do I import a file?
Victor Maia (Sep 02 2022 at 19:36):
how do I import a file in the same dir? I'm trying import Base, but it says nat_exp.lean:1:0: error: unknown package 'Base', even though there is a file named Base.lean on the same directory, which type-checks just fine
Kevin Buzzard (Sep 02 2022 at 19:39):
I don't know much about Lean 4 but I do know that in the maths library they are always doing import Mathlib.Logic.Basic
etc. If you're in a package then try aopending the package name?
Victor Maia (Sep 02 2022 at 19:41):
I'm not in a package I guess, I just created a directory and added 2 Lean files, and attempted to import one into another. I guess I'm missing something about how packages work
Victor Maia (Sep 02 2022 at 19:44):
also, import .Base
results in nat_exp.lean:1:7: error: expected identifier
Kevin Buzzard (Sep 02 2022 at 19:45):
Again I don't know much about Lean 4, but in Lean 3 you can't just create random files and expect imports to work. A Lean 3 project is set up with some infrastructure which tells the system where to look when trying to import files. Aah! See https://leanprover.github.io/lean4/doc/quickstart.html , section "Create a Lean Project". This is for Lean 4 and it also says that imports won't work unless you make a new package or project or whatever these things are called in Lean 4 (they seem to be called both?)
Adam Topaz (Sep 02 2022 at 19:47):
I think the preferred way to make a new project is using lake new Foo
(perhaps with some additional flags).
Victor Maia (Sep 02 2022 at 19:53):
i used lake new Foo
, and then attempted lean Main.lean
inside it, and I got Main.lean:1:0: error: unknown package 'Foo'
Adam Topaz (Sep 02 2022 at 19:55):
what are you trying to do? Build the package? Run the executable?
Victor Maia (Sep 02 2022 at 19:56):
I just want to type-check a file Main.lean
which imports another file Base.lean
. That's all. I don't want packages nor anything fancy
Adam Topaz (Sep 02 2022 at 19:56):
Anyway, this is all accomplished with lake. lake build
will typecheck (and build) everything
Victor Maia (Sep 02 2022 at 19:57):
I want to type-check just a single file though. I have a Base.lean
file which a bunch of definitions, and File_0.lean
, File_1.lean
, File_2.lean
etc. etc., which import Base.lean
. I want to type-check each file independently, to benchmark. But using lean File_0.lean
tells me Base
isn't a package.
Adam Topaz (Sep 02 2022 at 20:00):
I see. Unfortunately, I don't know how to accomplish that in Lean4.
Adam Topaz (Sep 02 2022 at 20:00):
Someone who knows will surely come along and help out soon.
Victor Maia (Sep 02 2022 at 20:08):
It is okay. Thanks for your patience!
James Gallicchio (Sep 02 2022 at 20:37):
Does lean Base.lean File_1.lean
work?
James Gallicchio (Sep 02 2022 at 20:38):
I think lake
figures out which files to pass to lean
, but you can do that manually
Juan Pablo Romero (Sep 02 2022 at 23:25):
you have to declare it as library in lakefile.lean
:
-- file: lakefile.lean
lean_lib Base
-- file: Main.lean
import Base
Chris Lovett (Sep 03 2022 at 02:25):
You will get real time type checking while you edit if you use VS Code. There's some lean4 sample with a demo video showing how easy it is to set this up on gitpod. Or if you want to use your local machine see Quick Tour of lean4 in VS Code.
Sebastian Ullrich (Sep 03 2022 at 09:16):
Victor Maia said:
I want to type-check just a single file though. I have a
Base.lean
file which a bunch of definitions, andFile_0.lean
,File_1.lean
,File_2.lean
etc. etc., which importBase.lean
. I want to type-check each file independently, to benchmark. But usinglean File_0.lean
tells meBase
isn't a package.
Once you have lake build
working, you can run individual files using lake env lean File_0.lean
.
Last updated: Dec 20 2023 at 11:08 UTC