Capstone Projects
Work through these to consolidate everything.
Work through these to consolidate everything. Each lists the concepts it exercises.
Project 1 — Todo CLI (beginner)
Add/list/complete/delete tasks saved to a JSON file. *Concepts: records, variants, lists, file I/O, Yojson, Cmdliner, dune.*
Project 2 — Markdown-to-HTML converter (beginner/intermediate)
Parse headings, lists, emphasis, code blocks. *Concepts: strings, Buffer, pattern matching on char lists, modules, expect tests.*
Project 3 — Arithmetic expression interpreter (intermediate)
Lexer (ocamllex) → parser (Menhir) → AST → evaluator with variables and functions; REPL. *Concepts: variants, recursion, Map for environments, result errors, Format printers.*
Extension: add a Hindley–Milner type checker (Algorithm W) with unification.
(* Skeleton *)
type value = VInt of int | VBool of bool | VClosure of string * expr * env
and env = value StringMap.t
and expr =
| Int of int | Bool of bool | Var of string
| Binop of op * expr * expr
| If of expr * expr * expr
| Let of string * expr * expr
| Fun of string * expr
| App of expr * expr
and op = Plus | Minus | Times | Lt | Eq
let rec eval env = function
| Int n -> VInt n
| Bool b -> VBool b
| Var x -> StringMap.find x env
| Binop (op, a, b) -> binop op (eval env a) (eval env b)
| If (c, t, e) -> (match eval env c with VBool true -> eval env t | _ -> eval env e)
| Let (x, e, body) -> eval (StringMap.add x (eval env e) env) body
| Fun (x, body) -> VClosure (x, body, env)
| App (f, arg) ->
(match eval env f with
| VClosure (x, body, cenv) -> eval (StringMap.add x (eval env arg) cenv) body
| _ -> failwith "not a function")
and binop op a b = match op, a, b with
| Plus, VInt x, VInt y -> VInt (x + y)
| Minus, VInt x, VInt y -> VInt (x - y)
| Times, VInt x, VInt y -> VInt (x * y)
| Lt, VInt x, VInt y -> VBool (x < y)
| Eq, VInt x, VInt y -> VBool (x = y)
| _ -> failwith "type error"Project 4 — Key-value store with persistence (intermediate)
In-memory Map, append-only log file, compaction, a TCP protocol (GET/SET/DEL). *Concepts: functors, Unix sockets or Eio, Marshal/binary formats, exceptions.*
Project 5 — Parallel image processor (advanced)
Load PPM images into Bigarrays, apply blur/edge-detection in parallel with Domainslib. *Concepts: Bigarray, domains, performance tuning, benchmarking.*
Project 6 — Web API + database (advanced)
A REST API with Dream + Caqti + SQLite, JSON via ppx_yojson_conv, tests with Alcotest and cram. *Concepts: Lwt, PPX, modules for layering (Domain / Repo / Http), error handling with result.*
Project 7 — Effects-based async runtime (advanced)
Implement async/await, sleep, and non-blocking sockets on top of effect handlers and Unix.select. *Concepts: effects, continuations, queues, scheduling.*
Project 8 — Typed DSL compiler (expert)
A GADT-typed DSL that compiles to OCaml closures or to C; includes an optimizer. *Concepts: GADTs, existential types, Format, staging, testing with QCheck.*
Project 9 — Browser game (expert)
A Snake or Tetris game compiled with js_of_ocaml + Brr, game logic pure and unit-tested. *Concepts: functional architecture (model/update/view), js interop.*