6.3. Console Output
Lean includes convenience functions for writing to standard output and standard error.
All make use of ToString
instances, and the varieties whose names end in -ln
add a newline after the output.
These convenience functions only expose a part of the functionality available using the standard I/O streams.
In particular, to read a line from standard input, use a combination of IO.getStdin
and IO.FS.Stream.getLine
.
Printing
This program demonstrates all four convenience functions for console I/O.
def main : IO Unit := do
IO.print "This is the "
IO.print "Lean"
IO.println " language reference."
IO.println "Thank you for reading it!"
IO.eprint "Please report any "
IO.eprint "errors"
IO.eprintln " so they can be corrected."
It outputs the following to the standard output:
stdout
This is the Lean language reference.
Thank you for reading it!
and the following to the standard error:
stderr
Please report any errors so they can be corrected.