Nanyx

io

Input and output operations

The io module provides functions for reading from and writing to standard I/O.

All functions in this module require a Console context. The program’s @entry function runs in Console, so they are available in main without any setup; any other function that calls them must declare [Console] in its type.

println

println: [Console] string -> ()

Prints a string followed by a newline to stdout.

println("Hello, World!")

print

print: [Console] string -> ()

Prints a string to stdout without a trailing newline.

print("Enter your name: ")

eprintln

eprintln: [Console] string -> ()

Prints a string followed by a newline to stderr.

eprintln("Configuration file missing")

eprint

eprint: [Console] string -> ()

Prints a string to stderr without a trailing newline.

eprint("warning: ")

dbg

dbg: [Console] a -> a

Prints a debug representation of any value and returns it. Useful for inspecting values in pipelines.

[1, 2, 3]
  \map { * 2 }
  \dbg
-- Prints: [2, 4, 6]

readLine

readLine: [Console] () -> #some(string) | #error(IoError)

Reads a line of input from stdin.

match readLine()
  | #some(line) -> println("You said: {line}")
  | #error(_) -> println("Failed to read input")

readToEnd

readToEnd: [Console] () -> #some(string) | #error(IoError)

Reads all remaining input from stdin.

match readToEnd()
  | #some(text) -> println("Read {text.length} chars")
  | #error(_) -> eprintln("Failed to read stdin")

flush

flush: [Console] () -> ()

Flushes buffered output streams.

print("processing...")
flush()