OCaml Bootcamp
This guide provides a structured approach to quickly getting up to speed with OCaml, particularly focusing on resources that will help with HardCaml development.
Here's a cool spotify link to listen as you program in ocaml: CS51 2024 - playlist by neopostretro | Spotify
I usually learn any programming language by immersing myself into the syntax, libraries, and developer tools and gradually solve basic exercises to open-ended challenges. Feel free to skip over if you're in a time crunch. Below is my personal playlist of some good content on OCaml I found on youtube.
Why OCaml?
OCaml combines the elegance of functional programming with pragmatic features that make it suitable for real-world applications:
Blazingly fast compiler with excellent type inference
Exhaustive pattern-matching that makes programs concise and robust
Strong static typing that catches bugs at compile time
Mature ecosystem with battle-proven libraries and tools
More beginner-friendly than other functional languages like Haskell
Getting Started
Installation and Setup
Before diving into learning OCaml, you'll need to set up your development environment:
Installing OCaml - Follow the official guide
Install OPAM (OCaml Package Manager)
Install Dune (build system) via OPAM:
opam install dune
Set up an editor with OCaml support (VSCode with OCaml extension for complete beginners or NeoVim/Emacs/Helix for the rest of us)
First Steps
To get a quick overview of OCaml syntax and features:
Check out Learn X in Y minutes: OCaml for a syntax overview
Follow A Tour of OCaml from the official documentation
Take a look at OCaml By Example and ofronds for practical examples *
Crash Course into Systems programming
Try solving systems problems with functional programming. Do course work on OS, compilers and computer architecture. Significant projects in any of those areas plays a huge role in understanding computer systems.
Then, get demonstrable systems building experience by working on projects that go beyond those coursework. Make sure that the projects are developed publicly on GitHub or other similar platforms so that one can take a look at what you’ve built. Even better is contributions to other open-source projects.
Core Learning Resources
Books and Courses
Real World OCaml - Free HTML version *
Comprehensive coverage of OCaml with practical examples
Co-authored by Jane Street's Ron Minsky
OCaml from the Very Beginning - Free HTML version or PDF version
Beginner-friendly introduction to OCaml and functional programming
OCaml Programming: Correct + Efficient + Beautiful - Cornell CS3110 Textbook *
Excellent free textbook with accompanying YouTube lectures
Solutions available in this GitHub repository
Abstraction and Design in Computation - Harvard CS51 Textbook
Covers functional programming concepts with OCaml
CS3100: Paradigms of Programming - Monsoon 2020
An excellent course that covers functional programming concepts with OCaml
CSCI7000: Principles of Functional Programming - Spring 2023
Super interesting course that goes over concepts such as concurrency & distributed programming.
University of Washington CSE341: Programming Languages - Autumn 2024
An extensive course on functional programming with a complete set of homework, assignments and notes.
Interactive Learning
OCaml Exercises - ocamorg/exercises
Practice OCaml with interactive exercises inspired by Ninety-Nine Lisp Problems.
Advent of Code - adventofcode.com
Solve Advent of Code problems using OCaml to get a feel of the language.
Jane Street Bootcamp - github.com/janestreet/learn-ocaml-workshop
Clone and work through the repo for extra practice.
Advanced Topics
Once you're comfortable with the basics, explore more articles on OCaml best practices and advanced techniques:
The OCaml Manual - ocaml.org/manual
Comprehensive reference documentation
Optimizing OCaml Performance - OCamlverse Guide
Learn how to write efficient OCaml code
Tiger Style Guide - tigerbeetle/TIGER_STYLE.md
Best practices for writing clean, maintainable OCaml code [ NEED REPLACEMENT ]
Learning Path Recommendation
For a structured approach to learning OCaml quickly:
Week 1: Installation, syntax basics, and simple exercises
Set up your environment
Go through "Tour of OCaml", Read chapters 1-5 of Real World OCaml
Study advanced OCaml features (modules, functors) and complete basic Jane Street workshop exercises
Week 2: Dive deeper into HardCaml
Start exploring basic HardCaml examples and try re-implementing it
Begin working on small HardCaml projects
Implement simple hardware designs
Here’s what Prof.KC usually recommends:
Learn the basics. Go through the OCaml part of his CS3100 course. The course has a YouTube playlist and programming assignments. Complete the programming assignments.
Read the Real World OCaml book. There are lots of other resources at OCaml.org, the official website of the OCaml community and the ecosystem.
Join the community. OCaml discord and discuss are great places to hang out with other OCaml folks and ask questions. Discord is better for quick clarifications and discuss for longer form discussions.
Look for “good first issues” in the OCaml projects and work on them Check out the core platform tools under the OCaml github org. See OCaml compiler, dune build system, opam package manager, ocaml.org, etc.
Across the wider ecosystem – SemGrep, OpenGrep, Rocq, etc. Work on self-directed projects and keep gaining experience.
OCaml for Hardware Development
Hardcaml is a hardware development toolchain embedded in OCaml. To prepare specifically, go over the following:
HardCaml Documentation *
Official documentation and examples
GitHub Repository Examples
Study existing HardCaml projects like hardcaml_arty and blogs like ujamjar.com/hardcaml
Advent of Hardcaml - Jane Street Tech Blog
Solve advent of code puzzles entirely on an FPGA using HardCaml
Recreate the Hardcaml ZPrize - zprize.hardcaml.com
OCaml All The Way Down :: Jane Street - Talk
Check out how Jane Street replaced 10 lines of Verilog with 200,000 lines of OCaml
Practice Projects
I recommend the following to solidify your OCaml knowledge:
Writing a bot for a chat protocol called IRC - irc-bot README
Create your very own version of fzf in OCaml - fuzzy-finder README
Implement a small hardware module using HardCaml
Build your own deterministic hypervisor - Antithesis blog *
Reimplement Z Garbage Collector from scratch - Oracle Docs *
MapReduce from Scratch - Original Paper
Toy type inferencer by implementing Hindley-Milner algorithm - Related Paper + Related paper II, Blog I + Blog II // Experimental type inference scheme for Rust - Blog
Reimplementing TCP/IP in pure OCaml - RFC 9293 , TCP/IP Illustrated, Low-Level Academy
Build a binary-serialization protocol generator
Writing a Game Boy Emulator - LINK
Serde like framework for OCaml - Docs
OCaml IDE - LINK
A proper web app using OCaml and ReasonML - Docs
Reimplement MIPS & RISC-V CPU in HardCaml - LINK
An image compressor with quadtrees
Writing An Interpreter / Compiler In OCaml
Hack together a time-traveling debugger or something like Magic-trace
Build a basic implementation of OpenAI’s tokenization library tiktoken with a handcrafted automaton
User‑Level CPU Profiler – research.swtch.com
Binary Memcached Protocol with OCaml and Bitstring - Blog
TODO app with the following stack:
Elm / ReasonML (frontend)
OCaml (backend)
SQLite (DB)
Nix (build, deployment)
More awesome stuff @ hackocaml
Ocaml frontend stack:
Melange, Reason, reason-react
react.js (react dates, recharts, etc…)
styled-ppx
server-reason-react
atd (migrating to melange-json)
OCaml, Lwt, Routes, sqlgg, devkit
OSS Projects
Give back to the OCaml ecosystem:
Add gRPC support to OCaml
Elasticsearch client for OCaml (ocaml-elasticsearch is abandoned)
Have ppx_graphql support the full GraphQL spec
Bindings for NATS/NATS Streaming
Contribute to Mirage OS - Github Repo
Raven is an ecosystem of libraries to make OCaml a first‑class citizen for ML
Eio — Effects-Based Parallel IO for OCaml 5
Saturn is collection of Lock-free data structures for multicore OCaml
Kcas provides Software Transactional Memory (STM) for OCaml
Help out people in the official forums
Here are some good blog posts on PL
courtesy of Max Bernstein
a simple semi-space collector by Andy Wingo brought the concept of a Cheney/copying/compacting garbage collector from theory to practice.
Implementing a Toy Optimizer by CF Bolz-Tereick changes how you think about instruction rewrites in an optimizer. The whole toy optimizer series is fantastic.
A Knownbits Abstract Domain for the Toy Optimizer, Correctly by CF Bolz-Tereick introduces to a new abstract domain for optimizers.
Cranelift, Part 3: Correctness in Register Allocation by Chris Fallin also made proofs more accessible, but in a different way.
Regular Expression Matching: the Virtual Machine Approach by Russ Cox make regular expression engines sense.
micrograd by Andrej Karpathy is a tiny implementation of neural networks with no libraries (not even NumPy).
How I implement SSA form by Fil Pizlo changed how you think about union-find.
Speculation in JavaScriptCore is another absolute banger by Fil Pizlo.
Modernizing Compiler Design for Carbon Toolchain is a talk by Chandler Carruth on the design of the Carbon compiler.
A Python Interpreter Written in Python by Allison Kaptur made bytecode interpreters (and, specifically, how CPython works internally) click.
Parsing expressions by precedence climbing by Eli Bendersky presented an understandable and easier-to-develop alternative to traditional hand-written recursive descent parsers.
Ruby JIT Challenge by Takashi Kokubun is a great start to code generation and it is more general than JIT, too.
An Incremental Approach to Compiler Construction (PDF) by Abdulaziz Ghuloum brought compilers and code generation from a mystical multi-pass beast down to an understandable single-pass form.
Lessons from Writing a Compiler by Fernando Borretti puts into words this stripey implementation strategy in the first section, which is really neat.
egg: Fast and extensible equality saturation by [multiple authors] changes how you think about optimizers and pass ordering.
Cranelift: Using E-Graphs for Verified, Cooperating Middle-End Optimizations by Chris Fallin showed that e-graphs are workable and remarkably effective in a production compiler.
Acyclic Egraphs and Smart Constructors by Phil Zucker further explores acyclic egraphs in the small.
This Reddit comment by Bob Nystrom and Flattening ASTs by Adrian Sampson are a double changes how you think about allocating and referring to IR nodes.
PL-focused areas to explore
OCaml
Graph-structured incremental compute
Python tooling
Hardware synthesis tools
Build systems
DSLs for web apps
Infrastructure and very large-scale computing systems
Community Resources
Connect with the OCaml community:
OCamlverse - Community-driven OCaml knowledge base
OCaml Discuss - Forum for OCaml discussions
/r/ocaml - Reddit community
Further Reading & Watching
The OCaml language Reference - ocaml.org/manual/5.3/index
Teach Yourself Programming in Ten Years - norvig.com/21-days
Laziness Impatience Hubris - wiki.c2.com/LazinessImpatienceHubris
What are the biggest reasons newcomers give up on OCaml? - Discuss.Ocaml Forum
Making OCaml Safe for Performance Engineering - Talk
OCaml for the Masses - ACM
On getting started with Category Theory – ludwigabap.com
Thomas Letan’s OCaml posts – soap.coffee
OK Mij’s FTP archive – okmij.org
Functional Programming (DCL @ Stanford) – dcl-prog.stanford.edu
CS43 – Class Information (Stanford Lambda) – stanford-lambda.gitlab.io
CS 99: Functional Programming and Theorem Proving in Lean 4 – leni.sh
OPLSS 2024 | University of Oregon Summerschool – cs.uoregon.edu
Fun OCaml Multicore workshop – github.com/ocaml-multicore
OCaml 5 Parallel Programming tutorial – github.com/ocaml-multicore
Intro to Eio (video + discussion) – discuss.ocaml.org
OCaml manual: Effect Handlers – ocaml.org/manual/5.3/effects
OCaml manual: Parallelism – ocaml.org/manual/5.3/parallelism
BugBash 2025: software reliability conference – bugbash.antithesis.com
Haskell Performance – wiki.haskell.org
On Competing with C Using Haskell – entropicthoughts.com
Haskell as fast as C – donsbot.com
Data‑Oriented Design – dataorienteddesign.com
OCaml Discourse – discuss.ocaml.org
Ludwig: On getting started with Category Theory - Blog
Category Theory for Programmers – YouTube
Last updated