# mathlibdocumentation

core / system.io

constant io_core  :
Type → Type → Type

def io_rand_nat  :
std_gen

Equations
@[instance]

@[instance]

@[instance]

@[instance]

@[instance]

@[instance]

@[instance]

@[instance]

@[instance]
def io_core_is_monad (e : Type) :

Equations
@[instance]

Equations
@[instance]

Equations
def io (α : Type) :
Type

Equations
def io.iterate {e α : Type} (a : α) (f : α → (option α)) :
α

Equations
• f = a f
def io.forever {e : Type} (a : unit) :

Equations
def io.catch {e₁ e₂ α : Type} (a : io_core e₁ α) (b : e₁ → io_core e₂ α) :
io_core e₂ α

Equations
• b = e₂ α a b
def io.finally {α e : Type} (a : α) (cleanup : unit) :
α

Equations
def io.fail {α : Type} (s : string) :
io α

Equations
def io.put_str  :

Equations
def io.put_str_ln (s : string) :

Equations
def io.get_line  :

Equations

Equations
def io.print {α : Type u_1} (s : α) :

Equations
• = s
def io.print_ln {α : Type u_1} (s : α) :

Equations
def io.handle  :
Type

Equations
def io.mk_file_handle (s : string) (m : io.mode) (bin : bool := ff) :

Equations
• bin =
def io.stdin  :

Equations
def io.stderr  :

Equations
def io.stdout  :

Equations
meta def io.serialize  :

meta def io.deserialize  :

def io.env.get (env_var : string) :

Equations

get the current working directory

Equations
def io.env.set_cwd (cwd : string) :

set the current working directory

Equations
def io.net.socket  :
Type

Equations
def io.net.listen  :

Equations

Equations

Equations
def io.net.recv  :

Equations
def io.net.send  :

Equations
def io.net.close  :

Equations
def io.fs.is_eof  :

Equations
def io.fs.flush  :

Equations
def io.fs.close  :

Equations

Equations
def io.fs.write  :

Equations
def io.fs.get_char (h : io.handle) :

Equations

Equations
def io.fs.put_char (h : io.handle) (c : char) :

Equations
def io.fs.put_str (h : io.handle) (s : string) :

Equations
def io.fs.put_str_ln (h : io.handle) (s : string) :

Equations

Equations
def io.fs.read_file (s : string) (bin : bool := ff) :

Equations

Equations

Equations
def io.fs.remove  :

Equations
def io.fs.rename  :
string

Equations
def io.fs.mkdir (path : string) (recursive : bool := ff) :

Equations
def io.fs.rmdir  :

Equations
def io.proc.child  :
Type

Equations

Equations

Equations

Equations

Equations

Equations
def io.proc.sleep (n : ) :

Equations
def io.set_rand_gen  :

Equations
def io.rand (lo : := std_range.fst) (hi : := std_range.snd) :

Equations
meta constant format.print_using  :
format

meta def format.print (fmt : format) :

meta def pp_using {α : Type} (a : α) (o : options) :

meta def pp {α : Type} (a : α) :

def io.cmd (args : io.process.spawn_args) :

Run the external process specified by args.

The process will run to completion with its output captured by a pipe, and read into string which is then returned.

Equations
meta constant tactic.unsafe_run_io {α : Type} :
io α

This is the "back door" into the io monad, allowing IO computation to be performed during tactic execution. For this to be safe, the IO computation should be ideally free of side effects and independent of its environment. This primitive is used to invoke external tools (e.g., SAT and SMT solvers) from a tactic.

IMPORTANT: this primitive can be used to implement unsafe_perform_io {α : Type} : io α → option α or unsafe_perform_io {α : Type} [inhabited α] : io α → α. This can be accomplished by executing the resulting tactic using an empty tactic_state (we have tactic_state.mk_empty). If unsafe_perform_io is defined, and used to perform side-effects, users need to take the following precautions:

• Use @[noinline] attribute in any function to invokes tactic.unsafe_perform_io. Reason: if the call is inlined, the IO may be performed more than once.

• Set set_option compiler.cse false before any function that invokes tactic.unsafe_perform_io. This option disables common subexpression elimination. Common subexpression elimination might combine two side effects that were meant to be separate.

TODO[Leo]: add [noinline] attribute and option compiler.cse.

meta constant io.run_tactic {α : Type} (a : tactic α) :
io α

Execute the given tactic with a tactic_state object that contains:

• The current environment in the virtual machine.
• The current set of options in the virtual machine.
• Empty metavariable and local contexts.
• One single goal of the form ⊢ true. This action is mainly useful for writing tactics that inspect the environment.