Equations
Equations
Equations
Equations
- instOrElseEIO = { orElse := MonadExcept.orElse }
Equations
Equations
Equations
Runs a BaseIO
action, which cannot throw an exception, in any other EIO
monad.
This function is usually used implicitly via automatic monadic lifting rather being than called explicitly.
Equations
- act.toEIO s = match act s with | EStateM.Result.ok a s => EStateM.Result.ok a s
Instances For
Equations
- instMonadLiftBaseIOEIO = { monadLift := fun {α : Type} => BaseIO.toEIO }
Converts an EIO ε
action that might throw an exception of type ε
into an exception-free BaseIO
action that returns an Except
value.
Equations
- act.toBaseIO s = match act s with | EStateM.Result.ok a s => EStateM.Result.ok (Except.ok a) s | EStateM.Result.error ex s => EStateM.Result.ok (Except.error ex) s
Instances For
Handles any exception that might be thrown by an EIO ε
action, transforming it into an
exception-free BaseIO
action.
Equations
- act.catchExceptions h s = match act s with | EStateM.Result.ok a s => EStateM.Result.ok a s | EStateM.Result.error ex s => h ex s
Instances For
Converts an Except ε
action into an EIO ε
action.
If the Except ε
action throws an exception, then the resulting EIO ε
action throws the same
exception. Otherwise, the value is returned.
Equations
- EIO.ofExcept (Except.ok a) = pure a
- EIO.ofExcept (Except.error e_2) = throw e_2
Instances For
Executes arbitrary side effects in a pure context. This a dangerous operation that can easily undermine important assumptions about the meaning of Lean programs, and it should only be used with great care and a thorough understanding of compiler internals, and even then only to implement observationally pure operations.
This function is not a good way to convert a BaseIO α
into an α
. Instead, use
do
-notation.
Because the resulting value is treated as a side-effect-free term, the compiler may re-order, duplicate, or delete calls to this function. The side effect may even be hoisted into a constant, causing the side effect to occur at initialization time, even if it would otherwise never be called.
Equations
- unsafeBaseIO fn = match EStateM.run fn () with | EStateM.Result.ok a a_1 => a
Instances For
Executes arbitrary side effects in a pure context, with exceptions indicated via Except
. This a
dangerous operation that can easily undermine important assumptions about the meaning of Lean
programs, and it should only be used with great care and a thorough understanding of compiler
internals, and even then only to implement observationally pure operations.
This function is not a good way to convert an EIO α
or IO α
into an α
. Instead, use
do
-notation.
Because the resulting value is treated as a side-effect-free term, the compiler may re-order, duplicate, or delete calls to this function. The side effect may even be hoisted into a constant, causing the side effect to occur at initialization time, even if it would otherwise never be called.
Equations
- unsafeEIO fn = unsafeBaseIO fn.toBaseIO
Instances For
Returns true
if and only if it is invoked during initialization.
Programs can execute IO
actions during an initialization phase that occurs before the main
function is executed. The attribute @[init <action>]
specifies which IO action is executed to set
the value of an opaque constant.
Runs act
in a separate Task
, with priority prio
.
Running the resulting BaseIO
action causes the task to be started eagerly. Pure accesses to the
Task
do not influence the impure act
.
Unlike pure tasks created by Task.spawn
, tasks created by this function will run even if the last
reference to the task is dropped. The act
should explicitly check for cancellation via
IO.checkCanceled
if it should be terminated or otherwise react to the last reference being
dropped.
Creates a new task that waits for t
to complete and then runs the BaseIO
action f
on its
result. This new task has priority prio
.
Running the resulting BaseIO
action causes the task to be started eagerly. Unlike pure tasks
created by Task.spawn
, tasks created by this function will run even if the last reference to the
task is dropped. The act
should explicitly check for cancellation via IO.checkCanceled
if it
should be terminated or otherwise react to the last reference being dropped.
Creates a new task that waits for t
to complete, runs the IO
action f
on its result, and then
continues as the resulting task. This new task has priority prio
.
Running the resulting BaseIO
action causes this new task to be started eagerly. Unlike pure tasks
created by Task.spawn
, tasks created by this function will run even if the last reference to the
task is dropped. The act
should explicitly check for cancellation via IO.checkCanceled
if it
should be terminated or otherwise react to the last reference being dropped.
Creates a new task that waits for t
to complete and then runs the IO
action f
on its result.
This new task has priority prio
.
This is a version of BaseIO.mapTask
that ignores the result value.
Running the resulting BaseIO
action causes the task to be started eagerly. Unlike pure tasks
created by Task.spawn
, tasks created by this function will run even if the last reference to the
task is dropped. The act
should explicitly check for cancellation via IO.checkCanceled
if it
should be terminated or otherwise react to the last reference being dropped.
Equations
- BaseIO.chainTask t f prio sync = discard (BaseIO.mapTask f t prio sync)
Instances For
Creates a new task that waits for all the tasks in the list tasks
to complete, and then runs the
IO
action f
on their results. This new task has priority prio
.
Running the resulting BaseIO
action causes the task to be started eagerly. Unlike pure tasks
created by Task.spawn
, tasks created by this function will run even if the last reference to the
task is dropped. The act
should explicitly check for cancellation via IO.checkCanceled
if it
should be terminated or otherwise react to the last reference being dropped.
Equations
- BaseIO.mapTasks f tasks prio sync = BaseIO.mapTasks.go f prio sync tasks []
Instances For
Equations
- BaseIO.mapTasks.go f prio sync [] x✝ = if sync = true then do let __do_lift ← f x✝.reverse pure { get := __do_lift } else (f x✝.reverse).asTask prio
- BaseIO.mapTasks.go f prio sync [t] x✝ = BaseIO.mapTask (fun (a : α) => f (a :: x✝).reverse) t prio sync
- BaseIO.mapTasks.go f prio sync (t :: ts) x✝ = BaseIO.bindTask t (fun (a : α) => BaseIO.mapTasks.go f prio sync ts (a :: x✝)) prio sync
Instances For
Runs act
in a separate Task
, with priority prio
. Because EIO ε
actions may throw an exception
of type ε
, the result of the task is an Except ε α
.
Running the resulting IO
action causes the task to be started eagerly. Pure accesses to the Task
do not influence the impure act
.
Unlike pure tasks created by Task.spawn
, tasks created by this function will run even if the last
reference to the task is dropped. The act
should explicitly check for cancellation via
IO.checkCanceled
if it should be terminated or otherwise react to the last reference being
dropped.
Instances For
Creates a new task that waits for t
to complete and then runs the IO
action f
on its result.
This new task has priority prio
.
Running the resulting BaseIO
action causes the task to be started eagerly. Unlike pure tasks
created by Task.spawn
, tasks created by this function will run even if the last reference to the
task is dropped. The act
should explicitly check for cancellation via IO.checkCanceled
if it
should be terminated or otherwise react to the last reference being dropped. Because EIO ε
actions
may throw an exception of type ε
, the result of the task is an Except ε α
.
Equations
- EIO.mapTask f t prio sync = BaseIO.mapTask (fun (a : α) => (f a).toBaseIO) t prio sync
Instances For
Creates a new task that waits for t
to complete, runs the EIO ε
action f
on its result, and
then continues as the resulting task. This new task has priority prio
.
Running the resulting BaseIO
action causes this new task to be started eagerly. Unlike pure tasks
created by Task.spawn
, tasks created by this function will run even if the last reference to the
task is dropped. The act
should explicitly check for cancellation via IO.checkCanceled
if it
should be terminated or otherwise react to the last reference being dropped. Because EIO ε
actions
may throw an exception of type ε
, the result of the task is an Except ε α
.
Equations
- EIO.bindTask t f prio sync = BaseIO.bindTask t (fun (a : α) => (f a).catchExceptions fun (e : ε) => pure { get := Except.error e }) prio sync
Instances For
Creates a new task that waits for t
to complete and then runs the EIO ε
action f
on its result.
This new task has priority prio
.
This is a version of EIO.mapTask
that ignores the result value.
Running the resulting EIO ε
action causes the task to be started eagerly. Unlike pure tasks
created by Task.spawn
, tasks created by this function will run even if the last reference to the
task is dropped. The act
should explicitly check for cancellation via IO.checkCanceled
if it
should be terminated or otherwise react to the last reference being dropped.
Equations
- EIO.chainTask t f prio sync = discard (liftM (EIO.mapTask f t prio sync))
Instances For
Creates a new task that waits for all the tasks in the list tasks
to complete, and then runs the
EIO ε
action f
on their results. This new task has priority prio
.
Running the resulting BaseIO
action causes the task to be started eagerly. Unlike pure tasks
created by Task.spawn
, tasks created by this function will run even if the last reference to the
task is dropped. The act
should explicitly check for cancellation via IO.checkCanceled
if it
should be terminated or otherwise react to the last reference being dropped.
Equations
- EIO.mapTasks f tasks prio sync = BaseIO.mapTasks (fun (as : List α) => (f as).toBaseIO) tasks prio sync
Instances For
Converts an Except ε
action into an IO
action.
If the Except ε
action throws an exception, then the exception type's ToString
instance is used
to convert it into an IO.Error
, which is thrown. Otherwise, the value is returned.
Equations
- IO.ofExcept (Except.ok a) = pure a
- IO.ofExcept (Except.error e_2) = throw (IO.userError (toString e_2))
Instances For
Creates an IO action that will invoke fn
if and when it is executed, returning the result.
Equations
- IO.lazyPure fn = pure (fn ())
Instances For
Monotonically increasing time since an unspecified past point in milliseconds. There is no relation to wall clock time.
Monotonically increasing time since an unspecified past point in nanoseconds. There is no relation to wall clock time.
Reads bytes from a system entropy source. It is not guaranteed to be cryptographically secure.
If nBytes
is 0
, returns immediately with an empty buffer.
Runs act
in a separate Task
, with priority prio
. Because IO
actions may throw an exception
of type IO.Error
, the result of the task is an Except IO.Error α
.
Running the resulting BaseIO
action causes the task to be started eagerly. Pure accesses to the
Task
do not influence the impure act
. Because IO
actions may throw an exception of type
IO.Error
, the result of the task is an Except IO.Error α
.
Unlike pure tasks created by Task.spawn
, tasks created by this function will run even if the last
reference to the task is dropped. The act
should explicitly check for cancellation via
IO.checkCanceled
if it should be terminated or otherwise react to the last reference being
dropped.
Equations
- act.asTask prio = EIO.asTask act prio
Instances For
Creates a new task that waits for t
to complete and then runs the IO
action f
on its result.
This new task has priority prio
.
Running the resulting BaseIO
action causes the task to be started eagerly. Unlike pure tasks
created by Task.spawn
, tasks created by this function will run even if the last reference to the
task is dropped. The act
should explicitly check for cancellation via IO.checkCanceled
if it
should be terminated or otherwise react to the last reference being dropped. Because IO
actions
may throw an exception of type IO.Error
, the result of the task is an Except IO.Error α
.
Equations
- IO.mapTask f t prio sync = EIO.mapTask f t prio sync
Instances For
Creates a new task that waits for t
to complete, runs the IO
action f
on its result, and then
continues as the resulting task. This new task has priority prio
.
Running the resulting BaseIO
action causes this new task to be started eagerly. Unlike pure tasks
created by Task.spawn
, tasks created by this function will run even if the last reference to the
task is dropped. The act
should explicitly check for cancellation via IO.checkCanceled
if it
should be terminated or otherwise react to the last reference being dropped. Because IO
actions
may throw an exception of type IO.Error
, the result of the task is an Except IO.Error α
.
Equations
- IO.bindTask t f prio sync = EIO.bindTask t f prio sync
Instances For
Creates a new task that waits for t
to complete and then runs the IO
action f
on its result.
This new task has priority prio
.
This is a version of IO.mapTask
that ignores the result value.
Running the resulting IO
action causes the task to be started eagerly. Unlike pure tasks created
by Task.spawn
, tasks created by this function will run even if the last reference to the task is
dropped. The act should explicitly check for cancellation via IO.checkCanceled
if it should be
terminated or otherwise react to the last reference being dropped.
Equations
- IO.chainTask t f prio sync = EIO.chainTask t f prio sync
Instances For
IO
specialization of EIO.mapTasks
.
Equations
- IO.mapTasks f tasks prio sync = EIO.mapTasks f tasks prio sync
Instances For
Checks whether the current task's cancellation flag has been set by calling IO.cancel
or by
dropping the last reference to the task.
The current state of a Task
in the Lean runtime's task manager.
- waiting : TaskState
The
Task
is waiting to be run.It can be waiting for dependencies to complete or sitting in the task manager queue waiting for a thread to run on.
- running : TaskState
The
Task
is actively running on a thread or, in the case of aPromise
, waiting for a call toIO.Promise.resolve
. - finished : TaskState
Instances For
Equations
- IO.instInhabitedTaskState = { default := IO.TaskState.waiting }
Equations
- IO.instReprTaskState = { reprPrec := IO.reprTaskState✝ }
Equations
- IO.instOrdTaskState = { compare := IO.ordTaskState✝ }
Converts a task state to a string.
Equations
- IO.TaskState.waiting.toString = "waiting"
- IO.TaskState.running.toString = "running"
- IO.TaskState.finished.toString = "finished"
Instances For
Equations
- IO.instToStringTaskState = { toString := IO.TaskState.toString }
Checks whether the task has finished execution, at which point calling Task.get
will return
immediately.
Equations
- IO.hasFinished task = do let __do_lift ← IO.getTaskState task pure (match __do_lift with | IO.TaskState.finished => true | x => false)
Instances For
Returns the number of heartbeats that have occurred during the current thread's execution. The heartbeat count is the number of “small” memory allocations performed in a thread.
Heartbeats used to implement timeouts that are more deterministic across different hardware.
Sets the heartbeat counter of the current thread to the given amount. This can be used to avoid counting heartbeats of code whose execution time is non-deterministic.
Adjusts the heartbeat counter of the current thread by the given amount. This can be useful to give allocation-avoiding code additional “weight” and is also used to adjust the counter after resuming from a snapshot.
Heartbeats are a means of implementing “deterministic” timeouts. The heartbeat counter is the number of “small” memory allocations performed on the current execution thread.
Equations
- IO.addHeartbeats count = do let n ← IO.getNumHeartbeats IO.setNumHeartbeats (n + count)
Instances For
Whether a file should be opened for reading, writing, creation and writing, or appending.
A the operating system level, this translates to the mode of a file handle (i.e., a set of open
flags and an fdopen
mode).
None of the modes represented by this datatype translate line endings (i.e. O_BINARY
on Windows).
Furthermore, they are not inherited across process creation (i.e. O_NOINHERIT
on Windows and
O_CLOEXEC
elsewhere).
Operating System Specifics:
- read : Mode
The file should be opened for reading.
The read/write cursor is positioned at the beginning of the file. It is an error if the file does not exist.
open
flags:O_RDONLY
fdopen
mode:r
- write : Mode
The file should be opened for writing.
If the file already exists, it is truncated to zero length. Otherwise, a new file is created. The read/write cursor is positioned at the beginning of the file.
open
flags:O_WRONLY | O_CREAT | O_TRUNC
fdopen
mode:w
- writeNew : Mode
A new file should be created for writing.
It is an error if the file already exists. A new file is created, with the read/write cursor positioned at the start.
open
flags:O_WRONLY | O_CREAT | O_TRUNC | O_EXCL
fdopen
mode:w
- readWrite : Mode
The file should be opened for both reading and writing.
It is an error if the file does not already exist. The read/write cursor is positioned at the start of the file.
open
flags:O_RDWR
fdopen
mode:r+
- append : Mode
The file should be opened for writing.
If the file does not already exist, it is created. If the file already exists, it is opened, and the read/write cursor is positioned at the end of the file.
open
flags:O_WRONLY | O_CREAT | O_APPEND
fdopen
mode:a
Instances For
A reference to an opened file.
File handles wrap the underlying operating system's file descriptors. There is no explicit operation to close a file: when the last reference to a file handle is dropped, the file is closed automatically.
Handles have an associated read/write cursor that determines the where reads and writes occur in the file.
A pure-Lean abstraction of POSIX streams. These streams may represent an underlying POSIX stream or be implemented by Lean code.
Because standard input, standard output, and standard error are all IO.FS.Stream
s that can be
overridden, Lean code may capture and redirect input and output.
Flushes the stream's output buffers.
Reads up to the given number of bytes from the stream.
If the returned array is empty, an end-of-file marker (EOF) has been reached. An EOF does not actually close a stream, so further reads may block and return more data.
Writes the provided bytes to the stream.
If the stream represents a physical output device such as a file on disk, then the results may be buffered. Call
FS.Stream.flush
to synchronize their contents.Reads text up to and including the next newline from the stream.
If the returned string is empty, an end-of-file marker (EOF) has been reached. An EOF does not actually close a stream, so further reads may block and return more data.
Writes the provided string to the stream.
Returns
true
if a stream refers to a Windows console or Unix terminal.
Instances For
Returns the current thread's standard input stream.
Use IO.setStdin
to replace the current thread's standard input stream.
Returns the current thread's standard output stream.
Use IO.setStdout
to replace the current thread's standard output stream.
Returns the current thread's standard error stream.
Use IO.setStderr
to replace the current thread's standard error stream.
Replaces the standard input stream of the current thread and returns its previous value.
Use IO.getStdin
to get the current standard input stream.
Replaces the standard output stream of the current thread and returns its previous value.
Use IO.getStdout
to get the current standard output stream.
Replaces the standard error stream of the current thread and returns its previous value.
Use IO.getStderr
to get the current standard error stream.
Opens the file at fn
with the given mode
.
An exception is thrown if the file cannot be opened.
Acquires an exclusive or shared lock on the handle. Blocks to wait for the lock if necessary.
Acquiring a exclusive lock while already possessing a shared lock will not reliably succeed: it works on Unix-like systems but not on Windows.
Tries to acquire an exclusive or shared lock on the handle and returns true
if successful. Will
not block if the lock cannot be acquired, but instead returns false
.
Acquiring a exclusive lock while already possessing a shared lock will not reliably succeed: it works on Unix-like systems but not on Windows.
Releases any previously-acquired lock on the handle. Succeeds even if no lock has been acquired.
Returns true
if a handle refers to a Windows console or a Unix terminal.
Flushes the output buffer associated with the handle, writing any unwritten data to the associated output device.
Rewinds the read/write cursor to the beginning of the handle's file.
Truncates the handle to its read/write cursor.
This operation does not automatically flush output buffers, so the contents of the output device may
not reflect the change immediately. This does not usually lead to problems because the read/write
cursor includes buffered writes. However, buffered writes followed by IO.FS.Handle.rewind
, then
IO.FS.Handle.truncate
, and then closing the file may lead to a non-empty file. If unsure, call
IO.FS.Handle.flush
before truncating.
Reads up to the given number of bytes from the handle. If the returned array is empty, an end-of-file marker (EOF) has been reached.
Encountering an EOF does not close a handle. Subsequent reads may block and return more data.
Writes the provided bytes to the the handle.
Writing to a handle is typically buffered, and may not immediately modify the file on disk. Use
IO.FS.Handle.flush
to write changes to buffers to the associated device.
Reads UTF-8-encoded text up to and including the next line break from the handle. If the returned string is empty, an end-of-file marker (EOF) has been reached.
Encountering an EOF does not close a handle. Subsequent reads may block and return more data.
Writes the provided string to the file handle using the UTF-8 encoding.
Writing to a handle is typically buffered, and may not immediately modify the file on disk. Use
IO.FS.Handle.flush
to write changes to buffers to the associated device.
Resolves a path to an absolute path that contains no '.', '..', or symbolic links.
This function coincides with the POSIX realpath
function.
Removes (deletes) a file from the filesystem.
To remove a directory, use IO.FS.removeDir
or IO.FS.removeDirAll
instead.
Removes (deletes) a directory.
Removing a directory fails if the directory is not empty. Use IO.FS.removeDirAll
to remove
directories along with their contents.
Creates a directory at the specified path. The parent directory must already exist.
Throws an exception if the directory cannot be created.
Moves a file or directory old
to the new location new
.
This function coincides with the POSIX rename
function.
Creates a temporary file in the most secure manner possible, returning both a Handle
to the
already-opened file and its path.
There are no race conditions in the file’s creation. The file is readable and writable only by the creating user ID. Additionally on UNIX style platforms the file is executable by nobody.
It is the caller's job to remove the file after use. Use withTempFile
to ensure that the temporary
file is removed.
Creates a temporary directory in the most secure manner possible, returning the new directory's path. There are no race conditions in the directory’s creation. The directory is readable and writable only by the creating user ID.
It is the caller's job to remove the directory after use. Use withTempDir
to ensure that the
temporary directory is removed.
Returns the file name of the currently-running executable.
Returns the current working directory of the executing process.
Opens the file fn
with the specified mode
and passes the resulting file handle to f
.
The file handle is closed when the last reference to it is dropped. If references escape f
, then
the file remains open even after IO.FS.withFile
has finished.
Equations
- IO.FS.withFile fn mode f = IO.FS.Handle.mk fn mode >>= f
Instances For
Reads the entire remaining contents of the file handle until an end-of-file marker (EOF) is encountered.
The underlying file is not automatically closed upon encountering an EOF, and subsequent reads from the handle may block and/or return data.
Equations
- h.readBinToEndInto buf = IO.FS.Handle.readBinToEndInto.loop h buf
Instances For
Reads the entire remaining contents of the file handle until an end-of-file marker (EOF) is encountered.
The underlying file is not automatically closed upon encountering an EOF, and subsequent reads from the handle may block and/or return data.
Equations
Instances For
Reads the entire remaining contents of the file handle as a UTF-8-encoded string. An exception is thrown if the contents are not valid UTF-8.
The underlying file is not automatically closed, and subsequent reads from the handle may block and/or return data.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns the contents of a UTF-8-encoded text file as an array of lines.
Newline markers are not included in the lines.
Equations
- IO.FS.lines fname = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.read IO.FS.lines.read h #[]
Instances For
Write the provided bytes to a binary file at the specified path.
Equations
- IO.FS.writeBinFile fname content = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.write h.write content
Instances For
Write contents of a string to a file at the specified path using UTF-8 encoding.
Equations
- IO.FS.writeFile fname content = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.write h.putStr content
Instances For
An entry in a directory on a filesystem.
- root : System.FilePath
The directory in which the entry is found.
- fileName : String
The name of the entry.
Instances For
Equations
- IO.FS.instReprDirEntry = { reprPrec := IO.FS.reprDirEntry✝ }
The path of the file indicated by the directory entry.
Instances For
Types of files that may be found on a filesystem.
- dir : FileType
Directories don't have contents, but may contain other files.
- file : FileType
Ordinary files that have contents and are not directories.
- symlink : FileType
Symbolic links that are pointers to other named files.
- other : FileType
Files that are neither ordinary files, directories, or symbolic links.
Instances For
Equations
- IO.FS.instReprFileType = { reprPrec := IO.FS.reprFileType✝ }
Equations
- IO.FS.instBEqFileType = { beq := IO.FS.beqFileType✝ }
Low-level system time, tracked in whole seconds and additional nanoseconds.
Instances For
Equations
- IO.FS.instReprSystemTime = { reprPrec := IO.FS.reprSystemTime✝ }
Equations
- IO.FS.instBEqSystemTime = { beq := IO.FS.beqSystemTime✝ }
Equations
- IO.FS.instOrdSystemTime = { compare := IO.FS.ordSystemTime✝ }
Equations
- IO.FS.instInhabitedSystemTime = { default := { sec := default, nsec := default } }
File metadata.
The metadata for a file can be accessed with System.FilePath.metadata
.
- accessed : SystemTime
File access time.
- modified : SystemTime
File modification time.
- byteSize : UInt64
The size of the file in bytes.
- type : FileType
Whether the file is an ordinary file, a directory, a symbolic link, or some other kind of file.
Instances For
Equations
- IO.FS.instReprMetadata = { reprPrec := IO.FS.reprMetadata✝ }
Returns the contents of the indicated directory. Throws an exception if the file does not exist or is not a directory.
Returns metadata for the indicated file. Throws an exception if the file does not exist or the metadata cannot be accessed.
Checks whether the indicated path can be read and is a directory.
Equations
- p.isDir = do let __do_lift ← EIO.toBaseIO p.metadata match __do_lift with | Except.ok m => pure (m.type == IO.FS.FileType.dir) | Except.error a => pure false
Instances For
Checks whether the indicated path points to a file that exists.
Equations
- p.pathExists = do let __do_lift ← EIO.toBaseIO p.metadata pure __do_lift.toBool
Instances For
Traverses a filesystem starting at the path p
and exploring directories that satisfy enter
,
returning the paths visited.
The traversal is a preorder traversal, in which parent directories occur prior to any of their children. Symbolic links are followed.
Instances For
Reads the entire contents of the binary file at the given path as an array of bytes.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Reads the entire contents of the UTF-8-encoded file at the given path as a String
.
An exception is thrown if the contents of the file are not valid UTF-8. This is in addition to exceptions that may always be thrown as a result of failing to read files.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Runs an action with the specified stream h
as standard input, restoring the original standard
input stream afterwards.
Equations
- IO.withStdin h x = do let prev ← liftM (IO.setStdin h) tryFinally x (discard (liftM (IO.setStdin prev)))
Instances For
Runs an action with the specified stream h
as standard output, restoring the original standard
output stream afterwards.
Equations
- IO.withStdout h x = do let prev ← liftM (IO.setStdout h) tryFinally x (discard (liftM (IO.setStdout prev)))
Instances For
Runs an action with the specified stream h
as standard error, restoring the original standard
error stream afterwards.
Equations
- IO.withStderr h x = do let prev ← liftM (IO.setStderr h) tryFinally x (discard (liftM (IO.setStderr prev)))
Instances For
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
).
Equations
- IO.println s = IO.print ((toString s).push '\n')
Instances For
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
).
Equations
- IO.eprintln s = IO.eprint ((toString s).push '\n')
Instances For
Returns the directory that the current executable is located in.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates a directory at the specified path, creating 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.
Creates a temporary file in the most secure manner possible and calls f
with both a Handle
to
the already-opened file and its path. Afterwards, the temporary file is deleted.
There are no race conditions in the file’s creation. The file is readable and writable only by the creating user ID. Additionally on UNIX style platforms the file is executable by nobody.
Use IO.FS.createTempFile
to avoid the automatic deletion of the temporary file.
Equations
- IO.FS.withTempFile f = do let __discr ← liftM IO.FS.createTempFile match __discr with | (handle, path) => tryFinally (f handle path) (liftM (IO.FS.removeFile path))
Instances For
Creates a temporary directory in the most secure manner possible, providing a its path to an IO
action. Afterwards, all files in the temporary directory are recursively deleted, regardless of how
or when they were created.
There are no race conditions in the directory’s creation. The directory is readable and writable
only by the creating user ID. Use IO.FS.createTempDir
to avoid the automatic deletion of the
directory's contents.
Equations
- IO.FS.withTempDir f = do let path ← liftM IO.FS.createTempDir tryFinally (f path) (liftM (IO.FS.removeDirAll path))
Instances For
Returns the current working directory of the calling process.
Sets the current working directory of the calling process.
Returns the process ID of the calling process.
Whether the standard input, output, and error handles of a child process should be attached to pipes, inherited from the parent, or null.
If the stream is a pipe, then the parent process can use it to communicate with the child.
- piped : Stdio
The stream should be attached to a pipe.
- inherit : Stdio
The stream should be inherited from the parent process.
- null : Stdio
The stream should be empty.
Instances For
The type of handles that can be used to communicate with a child process on its standard input, output, or error streams.
For IO.Process.Stdio.piped
, this type is IO.FS.Handle
. Otherwise, it is Unit
, because no
communication is possible.
Equations
Instances For
Configuration for a child process to be spawned.
Use IO.Process.spawn
to start the child process. IO.Process.output
and IO.Process.run
can be
used when the child process should be run to completion, with its output and/or error code captured.
- cmd : String
Command name.
Arguments for the command.
- cwd : Option System.FilePath
The child process's working directory. Inherited from the parent current process if
none
. Add or remove environment variables for the child process.
The child process inherits the parent's environment, as modified by
env
. Keys in the array are the names of environment variables. Anone
, causes the entry to be removed from the environment, andsome
sets the variable to the new value, adding it if necessary. Variables are processed from left to right.- setsid : Bool
Starts the child process in a new session and process group using
setsid
. Currently a no-op on non-POSIX platforms.
Instances For
A child process that was spawned with configuration cfg
.
The configuration determines whether the child process's standard input, standard output, and
standard error are IO.FS.Handle
s or Unit
.
- stdin : cfg.stdin.toHandleType
The child process's standard input handle, if it was configured as
IO.Process.Stdio.piped
, or()
otherwise. - stdout : cfg.stdout.toHandleType
The child process's standard output handle, if it was configured as
IO.Process.Stdio.piped
, or()
otherwise. - stderr : cfg.stderr.toHandleType
The child process's standard error handle, if it was configured as
IO.Process.Stdio.piped
, or()
otherwise.
Instances For
Starts a child process with the provided configuration. The child process is spawned using operating system primitives, and it can be written in any language.
The child process runs in parallel with the parent.
If the child process's standard input is a pipe, use IO.Process.Child.takeStdin
to make it
possible to close the child's standard input before the process terminates, which provides the child with an end-of-file marker.
Blocks until the child process has exited and return its exit code.
Checks whether the child has exited. Returns none
if the process has not exited, or its exit code
if it has.
Terminates the child process using the SIGTERM
signal or a platform analogue.
If the process was started using SpawnArgs.setsid
, terminates the entire process group instead.
Extracts the stdin
field from a Child
object, allowing the handle to be closed while maintaining
a reference to the child process.
File handles are closed when the last reference to them is dropped. Closing the child's standard
input causes an end-of-file marker. Because the Child
object has a reference to the standard
input, this operation is necessary in order to close the stream while the process is running (e.g.
to extract its exit code after calling Child.wait
). Many processes do not terminate until their
standard input is exhausted.
Runs a process to completion and captures its output and exit code. The child process is run with a null standard input, and the current process blocks until it has run to completion.
The specifications of standard input, output, and error handles in args
are ignored.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Runs a process to completion, blocking until it terminates. If the child process terminates successfully with exit code 0, its standard output is returned. An exception is thrown if it terminates with any other exit code.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Terminates the current process with the provided exit code. 0
indicates success, all other values
indicate failure.
Converts individual POSIX-style file permissions to their conventional three-bit representation.
This is the bitwise or
of the following:
- If the file can be read,
0x4
, otherwise0
. - If the file can be written,
0x2
, otherwise0
. - If the file can be executed,
0x1
, otherwise0
.
Examples:
{read := true : AccessRight}.flags = 4
{read := true, write := true : AccessRight}.flags = 6
{read := true, execution := true : AccessRight}.flags = 5
Equations
Instances For
POSIX-style file permissions that describe access rights for a file's owner, members of its assigned group, and all others.
- user : AccessRight
The owner's permissions to access the file.
- group : AccessRight
The assigned group's permissions to access the file.
- other : AccessRight
The permissions that all others have to access the file.
Instances For
Converts POSIX-style file permissions to their numeric representation, with three bits each for the owner's permissions, the group's permissions, and others' permissions.
Equations
Instances For
Sets the POSIX-style permissions for a file.
Equations
- IO.setAccessRights filename mode = IO.Prim.setAccessRights filename mode.flags
Instances For
Equations
- IO.instMonadLiftSTRealWorldBaseIO = { monadLift := fun {α : Type} => id }
Mutable cell that can be passed around for purposes of cooperative task cancellation: request
cancellation with CancelToken.set
and check for it with CancelToken.isSet
.
This is a more flexible alternative to Task.cancel
as the token can be shared between multiple
tasks.
Instances For
Creates a new cancellation token.
Equations
Instances For
Activates a cancellation token. Idempotent.
Equations
- tk.set = ST.Ref.set (IO.CancelToken.ref✝ tk) true
Instances For
Checks whether the cancellation token has been activated.
Equations
- tk.isSet = ST.Ref.get (IO.CancelToken.ref✝ tk)
Instances For
Creates a Lean stream from a file handle. Each stream operation is implemented by the corresponding file handle operation.
Equations
Instances For
A byte buffer that can simulate a file in memory.
Use IO.FS.Stream.ofBuffer
to create a stream from a buffer.
Instances For
Creates a stream from a mutable reference to a buffer.
The resulting stream simulates a file, mutating the contents of the reference in response to writes
and reading from it in response to reads. These streams can be used with IO.withStdin
,
IO.setStdin
, and the corresponding operators for standard output and standard error to redirect
input and output.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Runs an action with stdin
emptied and stdout
and stderr
captured into a String
. If
isolateStderr
is false
, only stdout
is captured.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Marks given value and its object graph closure as multi-threaded if currently marked single-threaded. This will make reference counter updates atomic and thus more costly. It can still be useful to do eagerly when the value will be shared between threads later anyway and there is available time budget to mark it now.
Equations
Instances For
Marks given value and its object graph closure as persistent. This will remove reference counter updates but prevent the closure from being deallocated until the end of the process! It can still be useful to do eagerly when the value will be marked persistent later anyway and there is available time budget to mark it now or it would be unnecessarily marked multi-threaded in between.
This function is only safe to use on objects (in the full closure) which are not used concurrently or which are already persistent.
Equations
Instances For
Discards the passed owned reference. This leads to a
any any object reachable from it never being
freed. This can be a useful optimization for eliding deallocation time of big object graphs that are
kept alive close to the end of the process anyway (in which case calling Runtime.markPersistent
would be similarly costly to deallocation). It is still considered a safe operation as it cannot
lead to undefined behavior.