In Lean, each file implicitly declares a module with the same name as the file (without the .lean
extension). For example, a file named intro.lean
implicitly declares a module named intro
.
You can also explicitly declare modules within a file:
module MyModule where
-- Module contents here
Modules can be imported using relative or absolute paths:
import Basic.Numbers -- absolute import
import .Numbers -- relative import
import «Numbers» -- import using Unicode characters
Lean supports literate programming through its .lean
files. While not as extensive as Agda’s literate
programming options, you can include markdown-style comments in your Lean files:
/-
# This is a markdown-style comment
It can span multiple lines and include *formatting*.
-/
def example := 42
Lean has some common naming practices, though they’re more guidelines than strict rules:
add_numbers
, total_count
)NaturalNumber
, BinaryTree
)Data.List
, Logic.Propositional
)Pi
, ExcludedMiddle
)∀
, λ
,
→
)Remember that in Lean, clarity and readability are paramount. Choose names that accurately describe the purpose or behavior of the identifier. Consistency within a project or library is more important than strictly adhering to any particular convention.
Here’s a list of resources for learning Lean:
Lean’s official documentation: A great guide to get started with Lean 4.
Theorem Proving in Lean: An introduction to theorem proving using Lean.
Mathematics in Lean: A tutorial on formalizing mathematics in Lean.
Functional Programming in Lean: A guide to functional programming concepts in Lean.
Lean for the Curious Mathematician: An introduction to Lean for mathematicians.
Lean Zulip Chat: A community chat for Lean users and developers.
Lean Together: Materials from the Lean Together workshops.
Lean 4 Examples: A collection of example Lean 4 projects.
The Natural Number Game: An interactive tutorial for learning Lean through number theory.
Formal Abstractions: A YouTube channel with Lean tutorials and demonstrations.