Skip to content

Commit db76e1c

Browse files
committed
.
1 parent 6f9ea5d commit db76e1c

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

content/blog/llms-new-languages.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ I need to keep Random.runWithIO() explicit:
441441
The refactoring completes successfully. The new `main` is:
442442

443443
```flix
444-
445444
def main(): Unit \ {Console, IO, NonDet} =
446445
let logFile = "game_log.txt";
447446
// Initialize log file
@@ -456,7 +455,47 @@ def main(): Unit \ {Console, IO, NonDet} =
456455
)
457456
```
458457

459-
**TODO**.
458+
Ugh. This is not good. While the code works, its structure is terrible. A few
459+
things have gone wrong, which was partly our own fault:
460+
461+
- We asked Claude to use default handlers for all effects. However, the
462+
`FileWrite` effect lacks a default handler because it can fail. Specifically,
463+
`FileWrite.runWithIO` returns a `Result[IoError, Unit]`. Claude, in its
464+
infinite wisdom, decided that we should just discard the `Result`.
465+
- We asked Claude to use the `run-with` construct, but it simply ignored us.
466+
467+
Let us try again, but this time we will be more specific:
468+
469+
```prompt
470+
I want you to refactor main. I want it to use a single run-with construct.
471+
Let bind the result to a local variable called r. Inside the run, you
472+
should call FileWrite.write and startGame. You should then use "with" to
473+
install the handlers handleLoggerWithFile and Random.runWithIO. Lastly,
474+
pattern match on the result r, and print an error message using
475+
Console.println if it is Result.Err.
476+
```
477+
478+
Now Claude consults the Flix documentation to learn about `run-with` and produces:
479+
480+
```
481+
def main(): Unit \ {Console, IO, NonDet} =
482+
let logFile = "game_log.txt";
483+
let r = run {
484+
FileWrite.write({str = "=== Tic-Tac-Toe Game Log ===\n"}, logFile);
485+
startGame()
486+
} with handleLoggerWithFile(logFile)
487+
with Random.runWithIO
488+
with FileWrite.runWithIO;
489+
match r {
490+
case Result.Err(e) => Console.println("Error: ${e}")
491+
case Result.Ok(_) => ()
492+
}
493+
```
494+
495+
Much better.
496+
497+
> **Aside:** We
498+
460499

461500
## Overview
462501

0 commit comments

Comments
 (0)