Skip to content

Commit aa30f0a

Browse files
committed
.
1 parent 44e3333 commit aa30f0a

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

content/blog/llms-new-languages.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ I now understand the built-in Logger API. The refactoring involves:
401401
Notably Claude has figured out that it has to write its own handler for `Logger`
402402
which _itself_ uses the `FileWrite` effect.
403403

404-
I ask Claude to continue. The refactoring is successful. The `GameLogger` effect
404+
I ask Claude to continue. The refactoring is successful: the `GameLogger` effect
405405
is removed and `Logger` is used. The new custom handler is:
406406

407407
```flix
@@ -418,18 +418,16 @@ def h(logFile: String, f: Unit -> a \ ef): a \ (ef - Logger) + FileWrite =
418418
}
419419
```
420420

421-
Notably, Claude has figured out the correct syntax for an effect polymorphic
422-
function that handles `Logger` while causing the `FileWrite` effect, i.e. the
423-
signature:
421+
Claude has figured out the correct syntax for an effect polymorphic function
422+
that handles `Logger` while causing the `FileWrite` effect, i.e. the signature:
424423

425424
```flix
426425
def h(logFile: String, f: Unit -> a \ ef): a \ (ef - Logger) + FileWrite =
427426
```
428427

429428
Impressive!
430429

431-
Next, I want to fix **(2)** by asking Claude to use default handlers. This is a new
432-
feature that is barely used in any examples and only documented in the book. I prompt:
430+
Next, I want to fix **(2)**, i.e. improve the style of `main`. I prompt:
433431

434432
```prompt
435433
Refactor main to use default handlers for the built-in effects.
@@ -439,7 +437,7 @@ Use run-with for the Logger effect and custom handler.
439437
See @docs/doc.flix.dev/default-handlers.html for documentation.
440438
```
441439

442-
At this point the dreaded "compacting conversation" happens. Lets see how it goes.
440+
At this point the dreaded "compacting conversation" happens. Let's see how it goes.
443441

444442
After a bit of `Clauding...`:
445443

@@ -477,14 +475,15 @@ def main(): Unit \ {Console, IO, NonDet} =
477475
)
478476
```
479477

480-
Ugh. This is not good. While the code works, its structure is terrible. A few
481-
things have gone wrong, which was partly our own fault:
478+
**Ugh.** _This is not good._ While the code is technically correct, its
479+
structure is terrible. A few things have gone wrong, partly due to my own
480+
instructions:
482481

483-
- We asked Claude to use default handlers for all effects. However, the
484-
`FileWrite` effect lacks a default handler because it can fail. Specifically,
482+
- I asked Claude to use default handlers for all effects. However, the
483+
`FileWrite` effect has no default handler because it can fail. In particular,
485484
`FileWrite.runWithIO` returns a `Result[IoError, Unit]`. Claude, in its
486-
infinite wisdom, decided that we should just discard the `Result`.
487-
- We asked Claude to use the `run-with` construct, but it simply ignored us.
485+
infinite wisdom, decided that we should simply discard the `Result` 🤡
486+
- I asked Claude to use the `run-with` construct, but it did not.
488487

489488
Let us try again, but this time we will be more specific:
490489

@@ -514,13 +513,13 @@ def main(): Unit \ {Console, IO, NonDet} =
514513
}
515514
```
516515

517-
Much better. The example shows that Claude is able to program effectively (no
518-
pun intended!) with a rich collection of effects. Here we have a program that
519-
uses the `Console`, `FileWrite`, `Logger`, and `Random` effects. Embracing the
520-
richness of the domain, we handle the `Logger` effect using
521-
`handleLoggerWithFile` which causes the `FileWrite` effect. We then handle the
522-
remaining effects using their associated `runWithIO` handlers which introduces the
523-
_primitive_ effects `IO` and `NonDet`.
516+
Much better. This example shows that Claude is able to program effectively (no
517+
pun intended!) with a rich collection of effects. The program uses the
518+
`Console`, `FileWrite`, `Logger`, and `Random` effects. Embracing the richness
519+
of the domain, we handle the `Logger` effect using `handleLoggerWithFile`, which
520+
in turn causes the `FileWrite` effect. We then handle the remaining effects
521+
using their associated `runWithIO` handlers, introducing the _primitive_ effects
522+
`IO` and `NonDet`. Lastly, `Console` is handled by its default effect handler.
524523

525524
> **Aside:** The program here illustrates how in an effect-oriented programming
526525
> languages, effects are pushed outwards towards `main` where they must be handled.

0 commit comments

Comments
 (0)