Std\IO
Std\IO — non-blocking console and handle-based byte I/O.
Every operation that can block on a slow device submits through
io_uring (on Linux) or the thread pool (for reads), returns a
Promise, and auto-awaits at the use site. The only synchronous
calls are pure syscalls that never block — isTty, flush.
Trivial programs stay trivial: println "hello" is still one line.
The non-blocking machinery is invisible until you put several I/O
calls in a let block, at which point the structured-concurrency
grouping runs them concurrently.
import println, readLine from Std\IO indoprintln "What is your name?"case readLine ofSome name -> println "Hello, {name}"None -> println "Goodbye."endendFunctions
Section titled “Functions”stdinFd : Int = 0
Section titled “stdinFd : Int = 0”File descriptor numbers, exposed as Int so any Std\File handle call
that expects FileHandle can be wrapped — FileHandle stdoutFd
builds the Linear-compatible handle — and the raw int is also useful
for passing to write without constructing the ADT.
stdoutFd : Int = 1
Section titled “stdoutFd : Int = 1”stderrFd : Int = 2
Section titled “stderrFd : Int = 2”print : String -> ()
Section titled “print : String -> ()”Write s to stdout. Returns a Promise that resolves when the kernel
has accepted the write. Non-blocking.
println : String -> ()
Section titled “println : String -> ()”Write s followed by a newline to stdout. Non-blocking.
eprint : String -> ()
Section titled “eprint : String -> ()”Write s to stderr. Non-blocking.
eprintln : String -> ()
Section titled “eprintln : String -> ()”Write s followed by a newline to stderr. Non-blocking.
putStr : Int -> String -> ()
Section titled “putStr : Int -> String -> ()”Write s to an arbitrary fd. Non-blocking.
putStrLn : Int -> String -> ()
Section titled “putStrLn : Int -> String -> ()”Write s followed by a newline to an arbitrary fd. Non-blocking.
write : Int -> String -> ()
Section titled “write : Int -> String -> ()”write fd s is an alias for putStr fd s. Kept for when you want
the “I’m emitting bytes, not printing text” shape at the call site.
readLine : Option String
Section titled “readLine : Option String”Read one line from stdin, stripping trailing ‘\n’ (and any ‘\r’).
Returns Some line or None at EOF. Non-blocking — the read runs
on a thread-pool worker.
readLineFrom : Int -> Option String
Section titled “readLineFrom : Int -> Option String”Read one line from an arbitrary fd. Same semantics as readLine.
flush : Int -> Bool
Section titled “flush : Int -> Bool”Force pending writes on fd to disk / device (fsync). Most
io_uring writes are durable on completion so this is rarely needed.
isTty : Int -> Bool
Section titled “isTty : Int -> Bool”True if fd is attached to a terminal (as opposed to a pipe or file).
Useful for turning off colored output or prompting prefixes.
isatty : Int -> Bool
Section titled “isatty : Int -> Bool”Alias for isTty, following the libc spelling.