I/O
Console I/O (std.io)
All console I/O functions are effect functions.
std.io.println(s: string) -> void
Print a string followed by a newline:
effect fn main() -> void {
std.io.println("Hello, World!")
}std.io.print(s: string) -> void
Print a string without a trailing newline:
effect fn main() -> void {
std.io.print("Enter name: ")
}std.io.read_line() -> IO[string]
Read a line of input from stdin:
effect fn main() -> void {
std.io.print("Name: ")
match std.io.read_line() {
Ok(line) => { std.io.println("Hello, " + line) }
Err(e) => { std.io.println("Error: " + e) }
}
}File System (std.fs)
std.fs.read_file(path: string) -> Result[string, string]
Read a file's contents as a string:
effect fn main() -> void {
match std.fs.read_file("data.txt") {
Ok(content) => { std.io.println(content) }
Err(e) => { std.io.println("Error: " + e) }
}
}std.fs.write_file(path: string, content: string) -> Result[void, string]
Write a string to a file:
effect fn main() -> void {
match std.fs.write_file("output.txt", "Hello!") {
Ok(_) => { std.io.println("Written successfully") }
Err(e) => { std.io.println("Error: " + e) }
}
}std.fs.exists(path: string) -> bool
Check if a file exists.