@@ -92,13 +92,13 @@ that the move is valid according to the rules of Tic-Tac-Toe. After each
9292player move, the AI makes a valid move. A player wins when they have
9393three consecutive x's or o's.
9494
95- Use the ` Console` effect for user input and output. Use a functional data
95+ Use the Console effect for user input and output. Use a functional data
9696structure to store the game state.
9797
9898Use a recursive function for the game loop.
9999
100- Use the ` Logger` effect to log all moves in the game. Write your own custom
101- handler for ` Logger` that writes to a logfile using the ` FileWrite` effect.
100+ Use the Logger effect to log all moves in the game. Write your own custom
101+ handler for Logger that writes to a logfile using the FileWrite effect.
102102
103103Consult the Flix documentation as necessary during planning.
104104```
@@ -126,7 +126,7 @@ How sophisticated should the AI opponent be?
126126 Optimal AI that never loses - more complex implementation
127127```
128128
129- Initially, I wanted to pick (3). However, picking (1) is more challenging
129+ Initially, I wanted to pick ** (3)** . However, picking ** (1)** is more challenging
130130because that will require Claude to use the ` Random ` effect whose handler
131131introduces the primitive ` NonDet ` effect. Claude will have to figure this out
132132for itself. We make our choice and:
@@ -206,9 +206,9 @@ Overall the plan looks reasonable, but there are a few issues:
206206 up Claude because Flix uses ` rec#field ` for field selection, not ` rec.field `
207207 which is used for Java interoperability.
208208
209- We give Claude instructions to resolve (1) and (2), and warn about (3). But
209+ We give Claude instructions to resolve ** (1)** and ** (2)** , and warn about ** (3)** . But
210210instead, let us see how well Claude does without further help. Later, we can
211- return and ask Claude to refactor (1) and (2). We proceed:
211+ return and ask Claude to refactor ** (1)** and ** (2)** . We proceed:
212212
213213``` claude
214214The plan is approved. Let me set up a task list and start implementing.
@@ -360,10 +360,10 @@ Let us return to our own TODO list. We wanted Claude to fix two issues:
360360 built-in ` Logger ` effect, but with a custom handler.
3613611 . The ` main ` entry point is correct, but non-idiomatic.
362362
363- Let us start with (1). We prompt Claude:
363+ Let us start with ** (1)** . We prompt Claude:
364364
365365``` prompt
366- Refactor the project to use the built-in ` Logger` effect.
366+ Refactor the project to use the built-in Logger effect.
367367```
368368
369369Claude consults the Flix API and Book again.
@@ -406,13 +406,13 @@ def h(logFile: String, f: Unit -> a \ ef): a \ (ef - Logger) + FileWrite =
406406
407407Impressive!
408408
409- Next, I want to fix (2) by asking Claude to use default handlers. This is a new
409+ Next, I want to fix ** (2)** by asking Claude to use default handlers. This is a new
410410feature that is barely used in any examples and only documented in the book. I prompt:
411411
412412``` prompt
413- Refactor ` main` to use default handlers for the built-in effects.
413+ Refactor main to use default handlers for the built-in effects.
414414
415- Use ` run-with` for the ` Logger` effect and custom handler.
415+ Use run-with for the Logger effect and custom handler.
416416
417417See @docs/doc.flix.dev/default-handlers.html for documentation.
418418```
@@ -467,12 +467,12 @@ things have gone wrong, which was partly our own fault:
467467Let us try again, but this time we will be more specific:
468468
469469``` 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` .
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.
476476```
477477
478478Now Claude consults the Flix documentation to learn about ` run-with ` and produces:
@@ -500,19 +500,20 @@ richness of the domain, we handle the `Logger` effect using
500500remaining effects using their associated ` runWithIO ` handlers which introduces the
501501_ primitive_ effects ` IO ` and ` NonDet ` .
502502
503- > ** Aside 1 :** The program here illustrates how in an effect-oriented programming
503+ > ** Aside:** The program here illustrates how in an effect-oriented programming
504504> languages, effects are pushed outwards towards ` main ` where they must be handled.
505505> That is to say, all the dependency injection and plumbing typically happens near ` main ` ,
506506> while most of the program remains pure modulo effects.
507507
508- > ** Aside 2:** We might be disappointed that ` main ` is so complex. Why could we
509- > not use default handlers for ` FileWrite ` and ` Random ` ? The answer is two-fold.
510- > With respect to ` Random ` , there is a limitation in Flix that prevents it. With
511- > respect to ` FileWrite ` , the API pushes errors into the handler (instead of at the call sites),
512- > hence we must deal with failure ourselves. (Here by printing to the terminal).
513- > An alternative choice would have been to use ` FileWriteWithResult ` which would force
514- > clients, i.e. the game, to deal with errors. Then we could have used a default handler
515- > in ` main ` at the cost of additional complexity within the game logic.
508+ We might be disappointed that ` main ` is so complex. Why could we not use default
509+ handlers for ` FileWrite ` and ` Random ` ? The answer is two-fold. With respect to
510+ ` Random ` , there is a limitation in Flix that prevents it. With respect to
511+ ` FileWrite ` , the API pushes errors into the handler (instead of at the call
512+ sites), hence we must deal with failure ourselves. (Here by printing to the
513+ terminal). An alternative choice would have been to use ` FileWriteWithResult `
514+ which would force clients, i.e. the game, to deal with errors. Then we could
515+ have used a default handler in ` main ` at the cost of additional complexity
516+ within the game logic.
516517
517518## Overview
518519
0 commit comments