flix

0.78.0

Console

eff ConsoleSource

Effect for interacting with the console.

The operations are the interface that a handler implements.

Programs normally use print, println, eprint, and eprintln which accept any value with a ToString instance.

Effect for interacting with the console, and its functions.

Default Handler

runWithIO

Operations

def readln(): Option[String] \ Console§ Source

Reads a single line from the console.

Returns None if the end of input has been reached.

def write(s: String): Unit \ Console§ Source

Writes the given string s to the standard out.

def writeErr(s: String): Unit \ Console§ Source

Writes the given string s to the standard err.

def writeErrLine(s: String): Unit \ Console§ Source

Writes the given string s to the standard err followed by a new line.

def writeLine(s: String): Unit \ Console§ Source

Writes the given string s to the standard out followed by a new line.

Definitions

def confirm(p: a, default: { default = Bool }): Bool \ Console with ToString[a]§ Source

Prints prompt p with a yes/no hint and reads a boolean answer.

Appends [Y/n] if default#default is true, or [y/N] if false. Empty input returns default#default. Recognizes "y", "yes", "n", "no" (case-insensitive). Any other input prints an error to stderr and re-prompts.

Returns default#default if the end of input has been reached.

def eprint(x: a): Unit \ Console with ToString[a]§ Source

Prints the string representation of x to the standard err.

def eprintln(x: a): Unit \ Console with ToString[a]§ Source

Prints the string representation of x to the standard err followed by a new line.

def handle(f: a -> b \ ef): a -> b \ (ef - Console) + IO§ Source

Handles the Console effect of the given function f.

In other words, re-interprets the Console effect using the IO effect.

def print(x: a): Unit \ Console with ToString[a]§ Source

Prints the string representation of x to the standard out.

def println(x: a): Unit \ Console with ToString[a]§ Source

Prints the string representation of x to the standard out followed by a new line.

def readlnAs(p: a): Option[b] \ Console with ToString[a], FromString[b]§ Source

Prints prompt p, reads a line, and parses it as a value of type b.

Leading and trailing whitespace is ignored.

If the input cannot be parsed, prints an error to stderr and re-prompts.

Returns None if the end of input has been reached.

def readlnWith(p: a, f: String -> Result[String, b]): Option[b] \ Console with ToString[a]§ Source

Prints prompt p, reads a line, and applies f to the input.

If f returns Err(msg), prints msg to stderr and re-prompts. If f returns Ok(v), returns Some(v).

Returns None if the end of input has been reached.

@DefaultHandler
def runWithIO(f: Unit -> a \ ef): a \ (ef - Console) + IO§ Source

Runs the Console effect of the given function f.

In other words, re-interprets the Console effect using the IO effect.