Skip to content

Commit 5284355

Browse files
lukstaficlaude
andauthored
Solution for task_chapter12 (#7)
* Round 1: Chapter 12 implemented: 941 lines, 11 sections (12.1-12.11), 34 code blocks across 8 env tags, 12 exercises. All MDX tests pass, full build succeeds. * Remove unmodified feature file task_chapter12.md * Pre-PR cleanup for task_chapter12 * Address PR feedback: fix leq GADT and VL lens encoding - Fix unsound leq GADT: use Peano type-level naturals so the Step constructor preserves the upper bound type parameter, with a working transitivity (composition) proof. - Fix Van Laarhoven lens: replace single _fst that was specialized to Identity with separate get/set demonstrations, and explain OCaml's higher-rank limitation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5efc852 commit 5284355

8 files changed

Lines changed: 3344 additions & 2 deletions

File tree

AGENTS_STAGING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Agent Learnings (Staging)
2+
3+
This file collects agent-discovered learnings for later curation into CLAUDE.md / AGENTS.md.
4+
5+
<!-- Entry: task_chapter12-coder | 2026-02-20 -->
6+
### Chapter 12 build and MDX gotchas
7+
8+
- **Float.round API**: OCaml's `Float.round` takes only one argument (the float). It does not accept a rounding direction parameter. Use `Float.floor`, `Float.ceil`, or `Float.round` (rounds to nearest even) directly.
9+
- **MDX env isolation**: Each `env=` tag creates a fully isolated toplevel. The prelude is loaded into every environment, but definitions from one `env=` block are invisible to blocks with a different tag. Plan environment grouping carefully before writing code.
10+
- **Root dune concatenation**: When adding a new chapter, update both the `deps` list and the `action` body in the root `dune` file's README.md rule. Missing either causes a build failure.
11+
- **Pipeline assertion values**: When writing test assertions for multi-stage pipelines, trace through each stage manually. A common error is asserting the wrong intermediate count (e.g., counting words after split without accounting for all tokens).
12+
- **Unicode in code comments**: Characters like ``, ``, `` in OCaml code comments or markdown prose trigger PDF font warnings (`Missing character` from lualatex). These are non-fatal but noisy. Prefer ASCII equivalents in code comments; Unicode is fine in markdown prose where KaTeX/pandoc handles rendering.
13+
14+
<!-- End entry -->

README.md

Lines changed: 943 additions & 0 deletions
Large diffs are not rendered by default.

chapter12/README.md

Lines changed: 953 additions & 0 deletions
Large diffs are not rendered by default.

chapter12/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(mdx
2+
(files README.md)
3+
(preludes prelude.ml))

chapter12/prelude.ml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
let ( -| ) f g x = f (g x)
2+
let ( |- ) f g x = g (f x)
3+
4+
module type MONAD = sig
5+
type 'a t
6+
val return : 'a -> 'a t
7+
val bind : 'a t -> ('a -> 'b t) -> 'b t
8+
end
9+
10+
module type MONAD_OPS = sig
11+
type 'a monad
12+
include MONAD with type 'a t := 'a monad
13+
val ( let* ) : 'a monad -> ('a -> 'b monad) -> 'b monad
14+
val ( let+ ) : 'a monad -> ('a -> 'b) -> 'b monad
15+
val ( >>= ) : 'a monad -> ('a -> 'b monad) -> 'b monad
16+
val join : 'a monad monad -> 'a monad
17+
end
18+
19+
module MonadOps (M : MONAD) = struct
20+
open M
21+
type 'a monad = 'a t
22+
let ( let* ) a b = bind a b
23+
let ( let+ ) a f = bind a (fun x -> return (f x))
24+
let (>>=) a b = bind a b
25+
let join m =
26+
let* x = m in
27+
x
28+
end
29+
30+
module Monad (M : MONAD) :
31+
sig
32+
include MONAD_OPS
33+
val run : 'a monad -> 'a M.t
34+
end = struct
35+
include M
36+
include MonadOps(M)
37+
let run x = x
38+
end

dune

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
chapter8/README.md
1616
chapter9/README.md
1717
chapter10/README.md
18-
chapter11/README.md)
18+
chapter11/README.md
19+
chapter12/README.md)
1920
(action
2021
(with-stdout-to
2122
README.md
@@ -45,7 +46,9 @@
4546
(echo "\n\n")
4647
(cat chapter10/README.md)
4748
(echo "\n\n")
48-
(cat chapter11/README.md)))))
49+
(cat chapter11/README.md)
50+
(echo "\n\n")
51+
(cat chapter12/README.md)))))
4952

5053
(rule
5154
(target old_lectures_as_book.md)

pdfs/new_book.pdf

79.8 KB
Binary file not shown.

site/new_book.html

Lines changed: 1388 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)