io
本頁內容尚未翻譯。
readFile
Section titled “readFile”extern readFile (path : String) : IO (Either String String)The contents of a file, or why it could not be read.
writeFile
Section titled “writeFile”extern writeFile (path : String) (content : String) : IO (Either String Unit)Writes a file (replacing what was there).
appendFile
Section titled “appendFile”extern appendFile (path : String) (content : String) : IO (Either String Unit)Appends to a file (creating it).
getEnv
Section titled “getEnv”extern getEnv (name : String) : IO (Option String)An environment variable’s value, if it is set.
getArgs
Section titled “getArgs”extern getArgs : IO (List String)The program’s arguments.
listDir
Section titled “listDir”extern listDir (path : String) : IO (Either String (List String))The names in a directory, in dictionary order (without . and ..).
fileExists
Section titled “fileExists”extern fileExists (path : String) : IO BoolWhether a file or a directory exists.
createDir
Section titled “createDir”extern createDir (path : String) : IO (Either String Unit)Makes a directory (and its parents).
removeFile
Section titled “removeFile”extern removeFile (path : String) : IO (Either String Unit)Removes a file.
putErr
Section titled “putErr”extern putErr (text : String) : IO UnitWrites a line to the error output.
runProcess
Section titled “runProcess”extern runProcess (program : String) (args : List String) (stdin : String) : IO (Either String (Nat × (String × String)))Runs a program with arguments and input, and waits: its exit code, output and error output.
spawnProcess
Section titled “spawnProcess”extern spawnProcess (program : String) (args : List String) (stdin : String) : IO (Either String String)Starts a program with arguments and input without waiting: a handle for awaitProcess.
awaitProcess
Section titled “awaitProcess”extern awaitProcess (job : String) : IO (Either String (Nat × (String × String)))Waits for a started program: as runProcess gives.
monadIO
Section titled “monadIO”instance monadIO : Monad IOIO is a monad; its pure and bind are the IO primitives (IO.pure, IO.bind).
def seq_ {A : Type} {B : Type} (m : IO A) (k : IO B) : IO BRuns m, discards its result, then runs k.
def when (b : Bool) (m : IO Unit) : IO UnitRuns the action only when the condition is true.
unless
Section titled “unless”def unless (b : Bool) (m : IO Unit) : IO UnitRuns the action only when the condition is false.
def mapM_ {A : Type} (f : A -> IO Unit) (xs : List A) : IO UnitRuns f on each list element in order, discarding the results.
expectEither
Section titled “expectEither”def expectEither {E : Type} {A : Type} (m : IO (Either E A)) : IO (Either E A)Identity on fallible actions; e? expands through it so a type mismatch is reported at e with the expected IO (Either E A) shape.
def mapIO {A : Type} {B : Type} (f : A -> IO B) (xs : List A) : IO (List B)Runs f on each list element in order and collects the results; ys <- for x in xs do ... expands to it.
def forIO {A : Type} {B : Type} (xs : List A) (f : A -> IO B) : IO (List B)mapIO with the list first, so the element type is known when the loop body is elaborated; target of ys <- for x in xs do ....
sequence_
Section titled “sequence_”def sequence_ (ms : List (IO Unit)) : IO UnitRuns each action of a list in order.
replicateM_
Section titled “replicateM_”def replicateM_ (n : Nat) (m : IO Unit) : IO UnitRuns an action n times.
forInList
Section titled “forInList”def forInList {A : Type} {S : Type} (xs : List A) (s : S) (f : A -> S -> IO S) : IO SExpansion of for x in xs do ...: runs f on each element in order, threading a state through.
forInListCtl
Section titled “forInListCtl”def forInListCtl {A : Type} {S : Type} (xs : List A) (s : S) (f : A -> S -> IO (LoopCtl S)) : IO SStateful loop over a list whose body may stop early with loopStop; used for loops with break or continue.
forInListR
Section titled “forInListR”def forInListR {A : Type} {R : Type} {S : Type} (xs : List A) (s : S) (f : A -> S -> IO (LoopStep R S)) : IO (Either R S)Stateful loop over a list whose body may break or return early; yields left v for an early return and right s when the loop ends.
forFrom_
Section titled “forFrom_”def forFrom_ (lo : Nat) (n : Nat) (f : Nat -> IO Unit) : IO UnitRuns f lo, f (lo+1), …, n times in order.
forRange_
Section titled “forRange_”def forRange_ (n : Nat) (f : Nat -> IO Unit) : IO UnitRuns f 0, f 1, …, f (n-1) in order.
def pureE {E : Type} {A : Type} (a : A) : IO (Either E A)A fallible action that succeeds with the given value.
throwE
Section titled “throwE”def throwE {E : Type} {A : Type} (e : E) : IO (Either E A)A fallible action that fails with the given error.
def bindE {E : Type} {A : Type} {B : Type} (m : IO (Either E A)) (k : A -> IO (Either E B)) : IO (Either E B)Sequences fallible actions, continuing only on success and stopping at the first failure.
catchE
Section titled “catchE”def catchE {E : Type} {A : Type} (m : IO (Either E A)) (h : E -> IO (Either E A)) : IO (Either E A)Runs a fallible action and hands any failure to the handler.
def liftE {E : Type} {A : Type} (m : IO A) : IO (Either E A)Lifts an infallible action into a fallible one.
orElseIO
Section titled “orElseIO”def orElseIO {E : Type} {A : Type} (m : IO (Either E A)) (alt : IO (Either E A)) : IO (Either E A)Runs a fallible action and falls back to alt if it fails.
record JobAn external program to run: program name, arguments and standard input.
startJob
Section titled “startJob”def startJob (j : Job) : IO (Either String String)Starts an external program, returning a process handle or an error.
awaitJob
Section titled “awaitJob”def awaitJob (h : Either String String) : IO (Either String (Nat × (String × String)))Waits for a started (or failed-to-start) job and returns its exit code, stdout and stderr, as runProcess does.
data Task (A : Type)A result that can be awaited later: an already computed value, or a running external process with a function converting its result.
def async {A : Type} (e : IO A) : IO (Task A)Starts a task; currently the action runs immediately and its result is stored.
awaitTask
Section titled “awaitTask”def awaitTask {A : Type} (t : Task A) : IO AWaits for a task to finish and returns its result; written await t inside do.
spawnTask
Section titled “spawnTask”def spawnTask (j : Job) : IO (Task (Either String (Nat × (String × String))))Starts an external program as a task that runs concurrently with other tasks.
runWindow
Section titled “runWindow”def runWindow (fuel : Nat) (running : List (Either String String)) (pending : List Job) : IO (List (Either String (Nat × (String × String))))Sliding-window job runner: awaits the oldest running job and starts the next pending one, with fuel counting remaining jobs.
runAll
Section titled “runAll”def runAll (limit : Nat) (jobs : List Job) : IO (List (Either String (Nat × (String × String))))Runs external programs with at most limit (at least one) in parallel, returning results in the order of jobs.
Bool.whenTrue
Section titled “Bool.whenTrue”def Bool.whenTrue (b : Bool) : Option (b = true)The proof that a Boolean is true, when it is.
IO.Ensured
Section titled “IO.Ensured”def IO.Ensured (R : Type) (p : R -> Bool) : TypeWhat an external function with ensures p gives: a value that passed p, with the proof, or the failure.
IO.ensure
Section titled “IO.ensure”def IO.ensure {R : Type} (broken : String) (p : R -> Bool) (m : IO (Either String R)) : IO.Ensured R pAn external function’s result checked against its contract p: a value that does not pass is the failure
broken.