IO

Console and filesystem I/O, tracked with the `IO` effect.

IO

The IO effect represents interactions with the outside world: console output, reading input, file access, etc.

Console Output

fn main() with IO {
    print("Hello, ")
    println("Sounio!")
}

Reading Input

read_line() returns a string:

fn main() with IO {
    println("Enter your name:")
    let name = read_line()
    print("Hi, ")
    println(name)
}

Effect Enforcement

If a function requires IO, callers must also declare with IO (or otherwise propagate/handle it).

This pattern fails:

fn read_file(path: string) -> string with IO {
    ""
}

fn main() {
    let _ = read_file("test.txt")  // ERROR: IO not declared
}

And this is the fix:

fn read_file(path: string) -> string with IO {
    ""
}

fn main() with IO {
    let _ = read_file("test.txt")
}

Next