From a60bb4c075244aeb114c657b31ddd0ad38d0f5b4 Mon Sep 17 00:00:00 2001 From: Magnus Madsen Date: Tue, 10 Mar 2026 12:42:20 +0100 Subject: [PATCH 1/2] fix: update Console references to use Sys.Console and new effect API - Add `use Sys.Console` import to all code blocks using the Console effect - Replace `Console.readLine()` with `Console.readln()` to match new API - Update printing-to-stdout.md to show the effect declaration instead of old module Co-Authored-By: Claude Opus 4.6 --- src/monadic-for-yield.md | 12 +++++++----- src/next-steps.md | 10 ++++++---- src/printing-to-stdout.md | 18 +++++++++++------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/monadic-for-yield.md b/src/monadic-for-yield.md index 3fd22246..a9a3212f 100644 --- a/src/monadic-for-yield.md +++ b/src/monadic-for-yield.md @@ -61,12 +61,14 @@ Similarly, we can use `forM` to work with the `Result[e, t]` data type. For example: ```flix -def main(): Result[String, Unit] \ IO = +use Sys.Console + +def main(): Result[String, Unit] \ IO = println("Please enter your first name, last name, and age:"); forM ( - fstName <- Console.readLine(); - lstName <- Console.readLine(); - ageLine <- Console.readLine(); + fstName <- Console.readln(); + lstName <- Console.readln(); + ageLine <- Console.readln(); ageNum <- Int32.parse(10, ageLine) ) yield { println("Hello ${lstName}, ${fstName}."); @@ -75,7 +77,7 @@ def main(): Result[String, Unit] \ IO = ``` Here `main` prompts the user to enter their first name, last name, and age. Each -call to `Console.readLine` returns a `Result[String, String]` value which is +call to `Console.readln` returns a `Result[String, String]` value which is either an error or the input string. Thus the local variables `fstName`, `lstName`, and `ageLine` are `String`s. We parse `ageLine` into an `Int32` using `Int32.parse`, which returns a `Result[String, Int32]` value. If every operation diff --git a/src/next-steps.md b/src/next-steps.md index 1a012bbb..4f56eb88 100644 --- a/src/next-steps.md +++ b/src/next-steps.md @@ -8,21 +8,23 @@ UNIX. We will use the opportunity to illustrate how to use algebraic effects in Flix. ```flix +use Sys.Console + def wc(file: String): Unit \ {Console, FileReadWithResult} = { match FileReadWithResult.readLines(file) { - case Ok(lines) => + case Ok(lines) => let totalLines = List.length(lines); let totalWords = List.sumWith(numberOfWords, lines); Console.println("Lines: ${totalLines}, Words: ${totalWords}") - case Err(_) => + case Err(_) => Console.println("Unable to read file: ${file}") } } -def numberOfWords(s: String): Int32 = +def numberOfWords(s: String): Int32 = s |> String.words |> List.length -def main(): Unit \ IO = +def main(): Unit \ IO = run { wc("Main.flix") } with Console.runWithIO diff --git a/src/printing-to-stdout.md b/src/printing-to-stdout.md index 20e82fbe..78ed68e4 100644 --- a/src/printing-to-stdout.md +++ b/src/printing-to-stdout.md @@ -21,15 +21,19 @@ The `println` function is rightfully effectful, hence it cannot be called from a pure function. To debug a pure function, use the builtin [debugging facilities](./debugging.md). -## The Console Module +## The Console Effect -The `Console` module defines additional functions for reading from or writing to -the terminal: +The `Console` effect defines operations for reading from and writing to the +terminal: ```flix -mod Console { - def print(x: a): Unit \ IO with ToString[a] - def println(x: a): Unit \ IO with ToString[a] - def readLine(): Result[String, String] \ IO Impure +use Sys.Console + +eff Console { + def readln(): String + def print(s: String): Unit + def eprint(s: String): Unit + def println(s: String): Unit + def eprintln(s: String): Unit } ``` From cb153ddf70ab42b8bcc34f2b94992621911eb0da Mon Sep 17 00:00:00 2001 From: Magnus Madsen Date: Tue, 10 Mar 2026 12:43:14 +0100 Subject: [PATCH 2/2] Remove Sys.Console import from documentation Removed unnecessary import of Sys.Console from the Console effect documentation. --- src/printing-to-stdout.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/printing-to-stdout.md b/src/printing-to-stdout.md index 78ed68e4..bac41fe4 100644 --- a/src/printing-to-stdout.md +++ b/src/printing-to-stdout.md @@ -27,8 +27,6 @@ The `Console` effect defines operations for reading from and writing to the terminal: ```flix -use Sys.Console - eff Console { def readln(): String def print(s: String): Unit