Converts s
to a string using its ToString α
instance, and prints it to the current standard
output (as determined by IO.getStdout
).
15.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
.
Converts s
to a string using its ToString α
instance, and prints it with a trailing newline to
the current standard output (as determined by IO.getStdout
).
Converts s
to a string using its ToString α
instance, and prints it to the current standard
error (as determined by IO.getStderr
).
Converts s
to a string using its ToString α
instance, and prints it with a trailing newline to
the current standard error (as determined by IO.getStderr
).
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.