Basic Types
Lean has rich, precise types. This level focuses on the everyday types you will use in every program.
Core Primitive Types
lean
1#check Nat2#check Int3#check Bool4#check StringLists and Options
Lists are ordered collections of values. Option represents a value that might be missing.
lean
1#check List Nat2#check Option String34#eval ([1, 2, 3] : List Nat)5#eval (none : Option String)6#eval (some "Lean" : Option String)Exercise: Safe Division
Define a function that returns none when dividing by zero andsome otherwise. Then test it with #eval.
lean
1def safeDiv (x y : Nat) : Option Nat :=2 if y = 0 then none else some (x / y)34#eval safeDiv 10 25#eval safeDiv 10 0ℹ
Option is Lean's way to avoid nulls. It forces you to handle missing data explicitly.Key Takeaway
Types are a feature. The more precise your types, the more help Lean can give you.