Skip to content

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 in
do
println "What is your name?"
case readLine of
Some name -> println "Hello, {name}"
None -> println "Goodbye."
end
end

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.

Write s to stdout. Returns a Promise that resolves when the kernel has accepted the write. Non-blocking.

Write s followed by a newline to stdout. Non-blocking.

Write s to stderr. Non-blocking.

Write s followed by a newline to stderr. Non-blocking.

Write s to an arbitrary fd. Non-blocking.

Write s followed by a newline to an arbitrary fd. Non-blocking.

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.

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.

Read one line from an arbitrary fd. Same semantics as readLine.

Force pending writes on fd to disk / device (fsync). Most io_uring writes are durable on completion so this is rarely needed.

True if fd is attached to a terminal (as opposed to a pipe or file). Useful for turning off colored output or prompting prefixes.

Alias for isTty, following the libc spelling.