OCaml, every single time.
Here’s why I’d happily fire up utop instead of cracking open Zig when the goal is “write a roguelike from scratch”:
1. A roguelike is a walking algebraic-data-type demo
A roguelike’s heart is a glorified state machine:
type action =
| Move of dir
| Melee of entity_id
| Fire of projectile * dir
| Drink of potion
| Wait
Pattern-matching on that is one match … with away from bliss. You get:
- Exhaustiveness checks → “did you forget ‘Fire’ when you refactor?”
- Refactoring is surgical: add a new variant, compiler lights up every missing branch.
- No nulls, no
switch (default), no surprises.
In Zig you’ll hand-roll tagged unions, switch over them, and manually keep the enum/union in sync. Works, but it’s friction compared to OCaml’s algebraic data types + pattern matching + compiler-enforced coverage.
2. The GC is your friend, not your enemy
A traditional roguelike spends most of its time:
- Updating a few hundred entities.
- Flood-filling FOV.
- Running A* now and then.
- Pushing characters to a tile map.
That’s tiny allocation pressure. OCaml’s simple stop-the-world minor GC (the “nursery”) will chew through those allocations without you noticing. You get to write code like:
let new_world = World.update world action
Immutable structures, structural sharing, and the GC clean up after you. No allocator wrangling, arenas, or lifetime gymnastics. Yes, Zig can give you deterministic control, but here it’s overkill—like bringing a lathe to peel an orange.
3. REPL-driven gameplay tweaks
“Actually, gelignite potions should explode in a 7-tile radius, let’s try it.”
With OCaml:
utop # #use "world.ml";;
let radius = 7;;
Hot-reload in milliseconds. In Zig you’re recompiling the whole project, even if your compile times are nice. The interactive loop (and ocamlemit hot code reload if you want) is a cheat code for iterating on content.
4. Expressiveness > raw SIMD
Could you squeeze more fps out of Zig? Absolutely. Do you need it? No.
ASCII tile maps or even SDL2 blitting aren’t going to bottleneck on CPU; your design iterations will. OCaml lets you write “the thing you meant” directly and move on.
5. Refactoring courage
OCaml’s type inference + structural equality + polymorphic variants → you will rip out and replace whole subsystems midway through a weekend jam and the compiler will point at the 7 places still broken. You’ll fix them in five minutes instead of grepping through pointer soup.
6. “But C interop!”
Yes, you said ignore ecosystem, but bindings still exist. OCaml’s ctypes is painless:
let ( ++ ) = Ctypes.( +@ )
let sdl_init = foreign "SDL_Init" (uint32_t @-> returning int)
Compile once, call forever. Good enough. You only write that FFI code once.
7. When performance does matter, the escape hatches exist
Bigarray, Bytes, -unsafe, flambda, ocamlopt, or straight‐up external C stubs: you’re covered. 90% of the code stays pretty, the 10% hot paths get the low-level love. (The “spend two hours to save two microseconds” crowd can still drop into C.)
8. It’s fun
This is the trump card. OCaml is simply a delight for modeling complex rulesets without ceremony. If the language keeps me in flow, I ship more features, and a roguelike lives or dies on features.
The honest counter-punch to myself
Zig is a joy when:
- You need deterministic memory footprints (embedded, consoles).
- You want to tweak allocators per subsystem (e.g., an arena per dungeon level).
- Compile-time codegen (Zig’s
comptime) can bake levels, items, whatever.
- You’re allergic to GC pauses, however tiny.
But for the archetypal PC roguelike—with more game design than poly-count—those advantages don’t outweigh the ergonomic goodies OCaml brings.
Verdict
Write the roguelike in OCaml.
You’ll prototype faster, keep the codebase cleaner, and spend your brain-cycles designing devilish vaults instead of micromanaging lifetimes.
Now go roll a new character. 🐉