Documentation

Init.System.IO

def IO.RealWorld :
Type

Like https://hackage.haskell.org/package/ghc-Prim-0.5.2.0/docs/GHC-Prim.html#t:RealWorld. Makes sure we never reorder IO operations.

TODO: mark opaque

Equations
def EIO (ε : Type) :
TypeType
Equations
instance instMonadEIO {ε : Type} :
Monad (EIO ε)
Equations
instance instMonadFinallyEIO {ε : Type} :
Equations
instance instMonadExceptOfEIO {ε : Type} :
Equations
instance instOrElseEIO {ε : Type} {α : Type} :
OrElse (EIO ε α)
Equations
  • instOrElseEIO = { orElse := MonadExcept.orElse }
instance instInhabitedEIO {ε : Type} {α : Type} [inst : Inhabited ε] :
Inhabited (EIO ε α)
Equations
def BaseIO :
TypeType

An EIO monad that cannot throw exceptions.

Equations
@[inline]
def BaseIO.toEIO {α : Type} {ε : Type} (act : BaseIO α) :
EIO ε α
Equations
instance instMonadLiftBaseIOEIO {ε : Type} :
Equations
  • instMonadLiftBaseIOEIO = { monadLift := fun {α} => BaseIO.toEIO }
@[inline]
def EIO.toBaseIO {ε : Type} {α : Type} (act : EIO ε α) :
BaseIO (Except ε α)
Equations
@[inline]
def EIO.catchExceptions {ε : Type} {α : Type} (act : EIO ε α) (h : εBaseIO α) :
Equations
@[inline]
abbrev IO :
TypeType
Equations
@[inline]
def BaseIO.toIO {α : Type} (act : BaseIO α) :
IO α
Equations
@[inline]
def EIO.toIO {ε : Type} {α : Type} (f : εIO.Error) (act : EIO ε α) :
IO α
Equations
@[inline]
def EIO.toIO' {ε : Type} {α : Type} (act : EIO ε α) :
IO (Except ε α)
Equations
@[inline]
def IO.toEIO {ε : Type} {α : Type} (f : IO.Errorε) (act : IO α) :
EIO ε α
Equations
@[inline]
unsafe def unsafeBaseIO {α : Type} (fn : BaseIO α) :
α
Equations
@[inline]
unsafe def unsafeEIO {ε : Type} {α : Type} (fn : EIO ε α) :
Except ε α
Equations
@[inline]
unsafe def unsafeIO {α : Type} (fn : IO α) :
Equations
@[extern lean_io_timeit]
opaque timeit {α : Type} (msg : String) (fn : IO α) :
IO α
@[extern lean_io_allocprof]
opaque allocprof {α : Type} (msg : String) (fn : IO α) :
IO α
@[extern lean_io_initializing]

Programs can execute IO actions during initialization that occurs before the main function is executed. The attribute [init ] specifies which IO action is executed to set the value of an opaque constant.

The action initializing returns true iff it is invoked during initialization.

@[extern lean_io_as_task]
opaque BaseIO.asTask {α : Type} (act : BaseIO α) (prio : optParam Task.Priority Task.Priority.default) :

Run act in a separate Task. This is similar to Haskell's unsafeInterleaveIO, except that the Task is started eagerly as usual. Thus pure accesses to the Task do not influence the impure act computation. Unlike with pure tasks created by Task.spawn, tasks created by this function will be run even if the last reference to the task is dropped. The act should manually check for cancellation via IO.checkCanceled if it wants to react to that.

@[extern lean_io_map_task]
opaque BaseIO.mapTask {α : Type u_1} {β : Type} (f : αBaseIO β) (t : Task α) (prio : optParam Task.Priority Task.Priority.default) :

See BaseIO.asTask.

@[extern lean_io_bind_task]
opaque BaseIO.bindTask {α : Type u_1} {β : Type} (t : Task α) (f : αBaseIO (Task β)) (prio : optParam Task.Priority Task.Priority.default) :

See BaseIO.asTask.

def BaseIO.mapTasks {α : Type u_1} {β : Type} (f : List αBaseIO β) (tasks : List (Task α)) (prio : optParam Task.Priority Task.Priority.default) :
Equations
def BaseIO.mapTasks.go {α : Type u_1} {β : Type} (f : List αBaseIO β) (prio : optParam Task.Priority Task.Priority.default) :
List (Task α)List αBaseIO (Task β)
Equations
@[inline]
def EIO.asTask {ε : Type} {α : Type} (act : EIO ε α) (prio : optParam Task.Priority Task.Priority.default) :
BaseIO (Task (Except ε α))

EIO specialization of BaseIO.asTask.

Equations
@[inline]
def EIO.mapTask {α : Type u_1} {ε : Type} {β : Type} (f : αEIO ε β) (t : Task α) (prio : optParam Task.Priority Task.Priority.default) :
BaseIO (Task (Except ε β))

EIO specialization of BaseIO.mapTask.

Equations
@[inline]
def EIO.bindTask {α : Type u_1} {ε : Type} {β : Type} (t : Task α) (f : αEIO ε (Task (Except ε β))) (prio : optParam Task.Priority Task.Priority.default) :
BaseIO (Task (Except ε β))

EIO specialization of BaseIO.bindTask.

Equations
@[inline]
def EIO.mapTasks {α : Type u_1} {ε : Type} {β : Type} (f : List αEIO ε β) (tasks : List (Task α)) (prio : optParam Task.Priority Task.Priority.default) :
BaseIO (Task (Except ε β))

EIO specialization of BaseIO.mapTasks.

Equations
def IO.ofExcept {ε : Type u_1} {α : Type} [inst : ToString ε] (e : Except ε α) :
IO α
Equations
def IO.lazyPure {α : Type} (fn : Unitα) :
IO α
Equations
@[extern lean_io_mono_ms_now]

Monotonically increasing time since an unspecified past point in milliseconds. No relation to wall clock time.

@[extern lean_io_mono_nanos_now]

Monotonically increasing time since an unspecified past point in nanoseconds. No relation to wall clock time.

@[extern lean_io_get_random_bytes]
opaque IO.getRandomBytes (nBytes : USize) :

Read bytes from a system entropy source. Not guaranteed to be cryptographically secure. If nBytes = 0, return immediately with an empty buffer.

Equations
@[inline]
def IO.asTask {α : Type} (act : IO α) (prio : optParam Task.Priority Task.Priority.default) :

IO specialization of EIO.asTask.

Equations
@[inline]
def IO.mapTask {α : Type u_1} {β : Type} (f : αIO β) (t : Task α) (prio : optParam Task.Priority Task.Priority.default) :

IO specialization of EIO.mapTask.

Equations
@[inline]
def IO.bindTask {α : Type u_1} {β : Type} (t : Task α) (f : αIO (Task (Except IO.Error β))) (prio : optParam Task.Priority Task.Priority.default) :

IO specialization of EIO.bindTask.

Equations
@[inline]
def IO.mapTasks {α : Type u_1} {β : Type} (f : List αIO β) (tasks : List (Task α)) (prio : optParam Task.Priority Task.Priority.default) :

IO specialization of EIO.mapTasks.

Equations
@[extern lean_io_check_canceled]

Check if the task's cancellation flag has been set by calling IO.cancel or dropping the last reference to the task.

@[extern lean_io_cancel]
opaque IO.cancel {α : Type u_1} :

Request cooperative cancellation of the task. The task must explicitly call IO.checkCanceled to react to the cancellation.

@[extern lean_io_has_finished]
opaque IO.hasFinished {α : Type u_1} :

Check if the task has finished execution, at which point calling Task.get will return immediately.

@[extern lean_io_wait]
opaque IO.wait {α : Type} (t : Task α) :

Wait for the task to finish, then return its result.

@[extern lean_io_wait_any]
opaque IO.waitAny {α : Type} (tasks : List (Task α)) (h : autoParam (List.length tasks > 0) _auto✝) :

Wait until any of the tasks in the given list has finished, then return its result.

@[extern lean_io_get_num_heartbeats]

Helper method for implementing "deterministic" timeouts. It is the number of "small" memory allocations performed by the current execution thread.

inductive IO.FS.Mode :
Type
Instances For
    opaque IO.FS.Handle :
    Type
    structure IO.FS.Stream :
    Type
    • flush : IO Unit
    • Read up to the given number of bytes from the stream. If the returned array is empty, an end-of-file marker has been reached. Note that EOF does not actually close a stream, so further reads may block and return more data.

      read : USizeIO ByteArray
    • write : ByteArrayIO Unit
    • Read text up to (including) the next line break from the stream. If the returned string is empty, an end-of-file marker has been reached. Note that EOF does not actually close a stream, so further reads may block and return more data.

      getLine : IO String
    • putStr : StringIO Unit

    A pure-Lean abstraction of POSIX streams. We use Streams for the standard streams stdin/stdout/stderr so we can capture output of #eval commands into memory.

    Instances For
      Equations
      • IO.FS.instInhabitedStream = { default := { flush := default, read := default, write := default, getLine := default, putStr := default } }
      @[extern lean_get_stdin]
      @[extern lean_get_stdout]
      @[extern lean_get_stderr]
      @[extern lean_get_set_stdin]

      Replaces the stdin stream of the current thread and returns its previous value.

      @[extern lean_get_set_stdout]

      Replaces the stdout stream of the current thread and returns its previous value.

      @[extern lean_get_set_stderr]

      Replaces the stderr stream of the current thread and returns its previous value.

      @[specialize #[]]
      partial def IO.iterate {α : Type} {β : Type} (a : α) (f : αIO (α β)) :
      IO β
      @[extern lean_io_prim_handle_mk]
      @[extern lean_io_prim_handle_flush]
      @[extern lean_io_prim_handle_read]

      Read up to the given number of bytes from the handle. If the returned array is empty, an end-of-file marker has been reached. Note that EOF does not actually close a handle, so further reads may block and return more data.

      @[extern lean_io_prim_handle_write]
      @[extern lean_io_prim_handle_get_line]

      Read text up to (including) the next line break from the handle. If the returned string is empty, an end-of-file marker has been reached. Note that EOF does not actually close a handle, so further reads may block and return more data.

      @[extern lean_io_prim_handle_put_str]
      @[extern lean_io_realpath]
      @[extern lean_io_remove_file]
      @[extern lean_io_remove_dir]

      Remove given directory. Fails if not empty; see also IO.FS.removeDirAll.

      @[extern lean_io_create_dir]
      @[extern lean_io_getenv]
      opaque IO.getEnv (var : String) :
      @[extern lean_io_app_path]
      @[extern lean_io_current_dir]
      @[inline]
      def IO.FS.withFile {α : Type} (fn : System.FilePath) (mode : IO.FS.Mode) (f : IO.FS.HandleIO α) :
      IO α
      Equations
      Equations
      def IO.FS.writeFile (fname : System.FilePath) (content : String) :
      Equations
      structure IO.FS.DirEntry :
      Type
      Instances For
        Equations
        inductive IO.FS.FileType :
        Type
        Instances For
          structure IO.FS.SystemTime :
          Type
          Instances For
            Equations
            structure IO.FS.Metadata :
            Type
            Instances For
              @[extern lean_io_read_dir]
              @[extern lean_io_metadata]

              Return all filesystem entries of a preorder traversal of all directories satisfying enter, starting at p. Symbolic links are visited as well by default.

              Equations
              def IO.withStdin {m : TypeType u_1} {α : Type} [inst : Monad m] [inst : MonadFinally m] [inst : MonadLiftT BaseIO m] (h : IO.FS.Stream) (x : m α) :
              m α
              Equations
              def IO.withStdout {m : TypeType u_1} {α : Type} [inst : Monad m] [inst : MonadFinally m] [inst : MonadLiftT BaseIO m] (h : IO.FS.Stream) (x : m α) :
              m α
              Equations
              def IO.withStderr {m : TypeType u_1} {α : Type} [inst : Monad m] [inst : MonadFinally m] [inst : MonadLiftT BaseIO m] (h : IO.FS.Stream) (x : m α) :
              m α
              Equations
              def IO.print {α : Type u_1} [inst : ToString α] (s : α) :
              Equations
              def IO.println {α : Type u_1} [inst : ToString α] (s : α) :
              Equations
              def IO.eprint {α : Type u_1} [inst : ToString α] (s : α) :
              Equations
              def IO.eprintln {α : Type u_1} [inst : ToString α] (s : α) :
              Equations
              Equations
              • One or more equations did not get rendered due to their size.

              Create given path and all missing parents as directories.

              Fully remove given directory by deleting all contained files and directories in an unspecified order. Fails if any contained entry cannot be deleted or was newly created during execution.

              inductive IO.Process.Stdio :
              Type
              Instances For
                structure IO.Process.StdioConfig :
                Type
                Instances For
                  Instances For
                    Instances For
                      @[extern lean_io_process_spawn]
                      opaque IO.Process.spawn (args : IO.Process.SpawnArgs) :
                      IO (IO.Process.Child args.toStdioConfig)
                      @[extern lean_io_process_child_wait]
                      @[extern lean_io_process_child_take_stdin]
                      opaque IO.Process.Child.takeStdin {cfg : IO.Process.StdioConfig} :
                      IO.Process.Child cfgIO (IO.Process.Stdio.toHandleType cfg.stdin × IO.Process.Child { stdin := IO.Process.Stdio.null, stdout := cfg.stdout, stderr := cfg.stderr })

                      Extract the stdin field from a Child object, allowing them to be freed independently. This operation is necessary for closing the child process' stdin while still holding on to a process handle, e.g. for Child.wait. A file handle is closed when all references to it are dropped, which without this operation includes the Child object.

                      structure IO.Process.Output :
                      Type
                      Instances For

                        Run process to completion and capture output.

                        Equations
                        • One or more equations did not get rendered due to their size.

                        Run process to completion and return stdout on success.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        @[extern lean_io_exit]
                        opaque IO.Process.exit {α : Type} :
                        UInt8IO α
                        structure IO.AccessRight :
                        Type
                        Instances For
                          Equations
                          structure IO.FileRight :
                          Type
                          Instances For
                            Equations
                            • One or more equations did not get rendered due to their size.
                            @[extern lean_chmod]
                            opaque IO.Prim.setAccessRights (filename : System.FilePath) (mode : UInt32) :
                            @[inline]
                            abbrev IO.Ref (α : Type) :
                            Type

                            References

                            Equations
                            def IO.mkRef {α : Type} (a : α) :
                            Equations
                            @[export lean_stream_of_handle]
                            Equations
                            structure IO.FS.Stream.Buffer :
                            Type
                            Instances For
                              Equations
                              • One or more equations did not get rendered due to their size.
                              def IO.FS.withIsolatedStreams {m : TypeType u_1} {α : Type} [inst : Monad m] [inst : MonadFinally m] [inst : MonadLiftT BaseIO m] (x : m α) (isolateStderr : optParam Bool true) :
                              m (String × α)

                              Run action with stdin emptied and stdout+stderr captured into a String.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              class Lean.Eval (α : Type u) :
                              Type u

                              Typeclass used for presenting the output of an #eval command.

                              Instances
                                instance Lean.instEval {α : Type u_1} [inst : ToString α] :
                                Equations
                                instance Lean.instEval_1 {α : Type u_1} [inst : Repr α] :
                                Equations
                                Equations
                                instance Lean.instEvalIO {α : Type} [inst : Lean.Eval α] :
                                Equations
                                instance Lean.instEvalBaseIO {α : Type} [inst : Lean.Eval α] :
                                Equations
                                Equations
                                • One or more equations did not get rendered due to their size.