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 OCamlarrow-up-right - 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: OCamlarrow-up-right for a syntax overview

  2. Follow A Tour of OCamlarrow-up-right from the official documentation

  3. Take a look at OCaml By Examplearrow-up-right and ofrondsarrow-up-right 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 versionarrow-up-right *

    • Comprehensive coverage of OCaml with practical examples

    • Co-authored by Jane Street's Ron Minsky

  2. OCaml from the Very Beginning - Free HTML versionarrow-up-right or PDF versionarrow-up-right

    • Beginner-friendly introduction to OCaml and functional programming

  3. OCaml Programming: Correct + Efficient + Beautiful - Cornell CS3110 Textbookarrow-up-right *

  4. Abstraction and Design in Computation - Harvard CS51 Textbookarrow-up-right

    • Covers functional programming concepts with OCaml

  5. CS3100: Paradigms of Programming - Monsoon 2020arrow-up-right

    • An excellent course that covers functional programming concepts with OCaml

  6. CSCI7000: Principles of Functional Programming - Spring 2023arrow-up-right

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

  7. University of Washington CSE341: Programming Languages - Autumn 2024arrow-up-right

    • An extensive course on functional programming with a complete set of homework, assignments and notes.

Interactive Learning

  1. OCaml Exercises - ocamorg/exercisesarrow-up-right

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

  2. Advent of Code - adventofcode.comarrow-up-right

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

  3. Jane Street Bootcamp - github.com/janestreet/learn-ocaml-workshoparrow-up-right

    • 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/manualarrow-up-right

    • Comprehensive reference documentation

  2. Optimizing OCaml Performance - OCamlverse Guidearrow-up-right

    • Learn how to write efficient OCaml code

  3. Tiger Style Guide - tigerbeetle/TIGER_STYLE.mdarrow-up-right

    • 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 Blogarrow-up-right

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

  4. Recreate the Hardcaml ZPrize - zprize.hardcaml.comarrow-up-right

  5. OCaml All The Way Down :: Jane Street - Talkarrow-up-right

    • 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 READMEarrow-up-right

  2. Create your very own version of fzfarrow-up-right in OCaml - fuzzy-finder READMEarrow-up-right

  3. Implement a small hardware module using HardCaml

  4. Build your own deterministic hypervisor - Antithesis blogarrow-up-right *

  5. Reimplement Z Garbage Collector from scratch - Oracle Docsarrow-up-right *

  6. MapReduce from Scratch - Original Paperarrow-up-right

  7. Toy type inferencer by implementing Hindley-Milner algorithm - Related Paperarrow-up-right + Related paper IIarrow-up-right, Blog Iarrow-up-right + Blog IIarrow-up-right // Experimental type inference scheme for Rust - Blogarrow-up-right

  8. Build a binary-serialization protocol generator

  9. Writing a Game Boy Emulator - LINKarrow-up-right

  10. Serde like framework for OCaml - Docsarrow-up-right

  11. OCaml IDE - LINKarrow-up-right

  12. A proper web app using OCaml and ReasonML - Docsarrow-up-right

  13. Reimplement MIPS & RISC-V CPU in HardCaml - LINKarrow-up-right

  14. An image compressor with quadtrees

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

  16. Build a basic implementation of OpenAI’s tokenization library tiktokenarrow-up-right with a handcrafted automaton

  17. User‑Level CPU Profiler – research.swtch.comarrow-up-right

  18. Binary Memcached Protocol with OCaml and Bitstring - Blogarrow-up-right

  19. TODO app with the following stack:

    • Elm / ReasonML (frontend)

    • OCaml (backend)

    • SQLite (DB)

    • Nix (build, deployment)

  20. More awesome stuff @ hackocamlarrow-up-right

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. Elasticsearch client for OCaml (ocaml-elasticsearch is abandoned)

  2. Contribute to Mirage OS - Github Repoarrow-up-right

  3. Ravenarrow-up-right is an ecosystem of libraries to make OCaml a first‑class citizen for ML

  4. Eioarrow-up-right — Effects-Based Parallel IO for OCaml 5

  5. Saturnarrow-up-right is collection of Lock-free data structures for multicore OCaml

  6. Kcasarrow-up-right provides Software Transactional Memory (STM) for OCaml

  7. Help out people in the official forumsarrow-up-right

Here are some good blog posts on PL

courtesy of Max Bernsteinarrow-up-right

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. OCamlversearrow-up-right - Community-driven OCaml knowledge base

  2. OCaml Discussarrow-up-right - Forum for OCaml discussions

  3. /r/ocamlarrow-up-right - Reddit community

Further Reading & Watching

  1. The OCaml language Reference - ocaml.org/manual/5.3/indexarrow-up-right

  2. Teach Yourself Programming in Ten Years - norvig.com/21-daysarrow-up-right

  3. What are the biggest reasons newcomers give up on OCaml? - Discuss.Ocaml Forumarrow-up-right

  4. Making OCaml Safe for Performance Engineering - Talkarrow-up-right

  5. Jane Street's Blog and YT channel - Blogarrow-up-right, Youtubearrow-up-right

  6. OCaml for the Masses - ACMarrow-up-right

  7. On getting started with Category Theory – ludwigabap.comarrow-up-right

  8. Thomas Letan’s OCaml posts – soap.coffeearrow-up-right

  9. OK Mij’s FTP archive – okmij.orgarrow-up-right

  10. Functional Programming (DCL @ Stanford) – dcl-prog.stanford.eduarrow-up-right

  11. CS43 – Class Information (Stanford Lambda) – stanford-lambda.gitlab.ioarrow-up-right

  12. CS 99: Functional Programming and Theorem Proving in Lean 4 – leni.sharrow-up-right

  13. OPLSS 2024 | University of Oregon Summerschool – cs.uoregon.eduarrow-up-right

  14. Fun OCaml Multicore workshop – github.com/ocaml-multicorearrow-up-right

  15. OCaml 5 Parallel Programming tutorial – github.com/ocaml-multicorearrow-up-right

  16. Intro to Eio (video + discussion) – discuss.ocaml.orgarrow-up-right

  17. OCaml manual: Effect Handlers – ocaml.org/manual/5.3/effectsarrow-up-right

  18. BugBash 2025: software reliability conference – bugbash.antithesis.comarrow-up-right

  19. Haskell Performance – wiki.haskell.orgarrow-up-right

  20. On Competing with C Using Haskell – entropicthoughts.comarrow-up-right

  21. Haskell as fast as C – donsbot.comarrow-up-right

  22. Data‑Oriented Design – dataorienteddesign.comarrow-up-right

  23. Ludwig: On getting started with Category Theory - Blogarrow-up-right

  24. Category Theory for Programmers – YouTubearrow-up-right


Last updated