I am following the lean 4 tutorial and see a main function as follows:
-- Defines a function that takes a name and produces a greeting.
def getGreeting (name : String) := s!"Hello, {name}! Isn't Lean great?"
-- The `main` function is the entry point of your program.
-- Its type is `IO Unit` because it can perform `IO` operations (side effects).
def main : IO Unit :=
-- Define a list of names
let names := ["Sebastian", "Leo", "Daniel"]
-- Map each name to a greeting
let greetings := names.map getGreeting
-- Print the list of greetings
for greeting in greetings do
IO.println greeting
I am not sure how to run the main
function. It's not in the FAQ. I tried to call it from the command line (Ubuntu 20.04):
lean 1_whats.lean
It gives no result. The VS code IDE (with lean4 support installed following the prompt) does not seem to show anything in All Messages
. I tried to add a separate line with just main
, which causes an error on the preceding for
line
invalid 'do' notation, expected type is not available
Obviously, this is really a beginner question.
How to run the main function in lean 4?