Localized V2 rewrite for this language is in progress. Showing English-first content for now.

IO

IO de console e filesystem, rastreado pelo efeito `IO`.

IO

O efeito IO representa interações com o mundo externo: saída no console, leitura de entrada, acesso a arquivos, etc.

Saída no Console

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

Lendo Entrada

read_line() retorna uma string:

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

Aplicação de Efeitos

Se uma função exige IO, quem chama também precisa declarar with IO (ou propagar/tratar o efeito).

Este padrão falha:

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

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

E esta é a correção:

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

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

Próximo