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:

  1. Installing OCaml - Follow the official guide

  2. Install OPAM (OCaml Package Manager)

  3. Install Dune (build system) via OPAM: opam install dune

  4. 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:

  1. Check out Learn X in Y minutes: OCaml for a syntax overview

  2. Follow A Tour of OCaml from the official documentation

  3. Take a look at OCaml By Example and ofronds for practical examples *

Crash Course into Systems programming

  1. 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.

  2. 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

  1. Real World OCaml - Free HTML version *

    • Comprehensive coverage of OCaml with practical examples

    • Co-authored by Jane Street's Ron Minsky

  2. OCaml from the Very Beginning - Free HTML version or PDF version

    • Beginner-friendly introduction to OCaml and functional programming

  3. OCaml Programming: Correct + Efficient + Beautiful - Cornell CS3110 Textbook *

  4. Abstraction and Design in Computation - Harvard CS51 Textbook

    • Covers functional programming concepts with OCaml

  5. CS3100: Paradigms of Programming - Monsoon 2020

    • An excellent course that covers functional programming concepts with OCaml

  6. CSCI7000: Principles of Functional Programming - Spring 2023

    • Super interesting course that goes over concepts such as concurrency & distributed programming.

  7. 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

  1. OCaml Exercises - ocamorg/exercises

    • Practice OCaml with interactive exercises inspired by Ninety-Nine Lisp Problems.

  2. Advent of Code - adventofcode.com

    • Solve Advent of Code problems using OCaml to get a feel of the language.

  3. 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:

  1. The OCaml Manual - ocaml.org/manual

    • Comprehensive reference documentation

  2. Optimizing OCaml Performance - OCamlverse Guide

    • Learn how to write efficient OCaml code

  3. 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:

  1. 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

  2. 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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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:

  1. HardCaml Documentation *

  2. GitHub Repository Examples

  3. Advent of Hardcaml - Jane Street Tech Blog

    • Solve advent of code puzzles entirely on an FPGA using HardCaml

  4. Recreate the Hardcaml ZPrize - zprize.hardcaml.com

  5. 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:

  1. Writing a bot for a chat protocol called IRC - irc-bot README

  2. Create your very own version of fzf in OCaml - fuzzy-finder README

  3. Implement a small hardware module using HardCaml

  4. Build your own deterministic hypervisor - Antithesis blog *

  5. Reimplement Z Garbage Collector from scratch - Oracle Docs *

  6. MapReduce from Scratch - Original Paper

  7. Toy type inferencer by implementing Hindley-Milner algorithm - Related Paper + Related paper II, Blog I + Blog II // Experimental type inference scheme for Rust - Blog

  8. Reimplementing TCP/IP in pure OCaml - RFC 9293 , TCP/IP Illustrated, Low-Level Academy

  9. Build a binary-serialization protocol generator

  10. Writing a Game Boy Emulator - LINK

  11. Serde like framework for OCaml - Docs

  12. OCaml IDE - LINK

  13. A proper web app using OCaml and ReasonML - Docs

  14. Reimplement MIPS & RISC-V CPU in HardCaml - LINK

  15. An image compressor with quadtrees

  16. Writing An Interpreter / Compiler In OCaml

  17. Hack together a time-traveling debugger or something like Magic-trace

  18. Build a basic implementation of OpenAI’s tokenization library tiktoken with a handcrafted automaton

  19. StatsD filter proxy - Article / Reference

  20. User‑Level CPU Profiler – research.swtch.com

  21. Binary Memcached Protocol with OCaml and Bitstring - Blog

  22. Parser for HCL - Reference

  23. TODO app with the following stack:

    • Elm / ReasonML (frontend)

    • OCaml (backend)

    • SQLite (DB)

    • Nix (build, deployment)

  24. 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:

  1. Add gRPC support to OCaml

  2. Elasticsearch client for OCaml (ocaml-elasticsearch is abandoned)

  3. Have ppx_graphql support the full GraphQL spec

  4. Bindings for NATS/NATS Streaming

  5. Contribute to Mirage OS - Github Repo

  6. Raven is an ecosystem of libraries to make OCaml a first‑class citizen for ML

  7. Eio — Effects-Based Parallel IO for OCaml 5

  8. Saturn is collection of Lock-free data structures for multicore OCaml

  9. Kcas provides Software Transactional Memory (STM) for OCaml

  10. Help out people in the official forums

Here are some good blog posts on PL

courtesy of Max Bernstein

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:

  1. OCamlverse - Community-driven OCaml knowledge base

  2. OCaml Discuss - Forum for OCaml discussions

  3. /r/ocaml - Reddit community

Further Reading & Watching

  1. The OCaml language Reference - ocaml.org/manual/5.3/index

  2. Teach Yourself Programming in Ten Years - norvig.com/21-days

  3. Laziness Impatience Hubris - wiki.c2.com/LazinessImpatienceHubris

  4. OCaml 5 Performance - Part-1, Part-2

  5. What are the biggest reasons newcomers give up on OCaml? - Discuss.Ocaml Forum

  6. Making OCaml Safe for Performance Engineering - Talk

  7. Jane Street's Blog and YT channel - Blog, Youtube

  8. OCaml for the Masses - ACM

  9. On getting started with Category Theory – ludwigabap.com

  10. Thomas Letan’s OCaml posts – soap.coffee

  11. OK Mij’s FTP archive – okmij.org

  12. Functional Programming (DCL @ Stanford) – dcl-prog.stanford.edu

  13. CS43 – Class Information (Stanford Lambda) – stanford-lambda.gitlab.io

  14. CS 99: Functional Programming and Theorem Proving in Lean 4 – leni.sh

  15. OPLSS 2024 | University of Oregon Summerschool – cs.uoregon.edu

  16. Fun OCaml Multicore workshop – github.com/ocaml-multicore

  17. OCaml 5 Parallel Programming tutorial – github.com/ocaml-multicore

  18. Intro to Eio (video + discussion) – discuss.ocaml.org

  19. OCaml manual: Effect Handlers – ocaml.org/manual/5.3/effects

  20. OCaml manual: Parallelism – ocaml.org/manual/5.3/parallelism

  21. BugBash 2025: software reliability conference – bugbash.antithesis.com

  22. Haskell Performance – wiki.haskell.org

  23. On Competing with C Using Haskell – entropicthoughts.com

  24. Haskell as fast as C – donsbot.com

  25. Data‑Oriented Design – dataorienteddesign.com

  26. OCaml Discourse – discuss.ocaml.org

  27. Ludwig: On getting started with Category Theory - Blog

  28. Category Theory for Programmers – YouTube


Last updated