# OCaml Bootcamp

Here's a cool spotify link to listen as you program in ocaml:\
**CS51 2024 - playlist by neopostretro | Spotify**

{% embed url="<https://open.spotify.com/playlist/1bEk77HgjQn6U3X1r74qoY>" %}

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.

{% embed url="<https://youtube.com/playlist?list=PLJpDuqVVFXkn_eVtCJw_Of2T_u-3nl12t&si=n0fYES5Q6gNnHWBB>" %}

***

### 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](https://ocaml.org/docs/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](https://learnxinyminutes.com/docs/ocaml/) for a syntax overview
2. Follow [A Tour of OCaml](https://ocaml.org/docs/tour-of-ocaml) from the official documentation
3. Take a look at [OCaml By Example](https://o1-labs.github.io/ocamlbyexample/) and [ofronds](https://github.com/gs0510/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](https://dev.realworldocaml.org/toc.html) \*
   * Comprehensive coverage of OCaml with practical examples
   * Co-authored by Jane Street's Ron Minsky
2. **OCaml from the Very Beginning -** [**Free HTML version**](https://johnwhitington.net/ocamlfromtheverybeginning/index.html) **or** [**PDF version**](https://johnwhitington.net/ocamlfromtheverybeginning/mlbook.pdf)
   * Beginner-friendly introduction to OCaml and functional programming
3. **OCaml Programming: Correct + Efficient + Beautiful** - [Cornell CS3110 Textbook](https://cs3110.github.io/textbook/cover.html) \*
   * Excellent free textbook with accompanying [YouTube lectures](https://www.youtube.com/playlist?list=PLre5AT9JnKShBOPeuiD9b-I4XROIJhkIU)
   * Solutions available in this [GitHub repository](https://github.com/cs3110/textbook-solutions)
4. **Abstraction and Design in Computation** - [Harvard CS51 Textbook](https://book.cs51.io/)
   * Covers functional programming concepts with OCaml
5. **CS3100: Paradigms of Programming -** [Monsoon 2020](https://kcsrk.info/cs3100_m20/)
   * An excellent course that covers functional programming concepts with OCaml
6. **CSCI7000: Principles of Functional Programming -** [Spring 2023](https://gowthamk.github.io/csci7000_pfp_s23/)
   * Super interesting course that goes over concepts such as concurrency & distributed programming.
7. **University of Washington CSE341: Programming Languages**  - [Autumn 2024](https://sites.google.com/cs.washington.edu/cse341autumn2024/course-information?authuser=0)
   * An extensive course on functional programming with a complete set of homework, assignments and notes.

#### Interactive Learning

1. **OCaml Exercises -** [ocamorg/exercises](https://ocaml.org/exercises)
   * Practice OCaml with interactive exercises inspired by Ninety-Nine Lisp Problems.
2. **Advent of Code -** [adventofcode.com](https://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](https://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](https://ocaml.org/manual/5.3/index.html)
   * Comprehensive reference documentation
2. **Optimizing OCaml Performance** - [OCamlverse Guide](https://ocamlverse.net/content/optimizing_performance.html)
   * Learn how to write efficient OCaml code
3. **Tiger Style Guide** - [tigerbeetle/TIGER\_STYLE.md](https://github.com/tigerbeetle/tigerbeetle/blob/main/docs/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:**<br>

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 \***
   * Official documentation and [examples](https://github.com/janestreet/hardcaml/blob/master/docs/index.md)
2. **GitHub Repository Examples**
   * Study existing HardCaml projects like [hardcaml\_arty](https://github.com/fyquah/hardcaml_arty) and blogs like [ujamjar.com/hardcaml](https://www.ujamjar.com/hardcaml/)
3. **Advent of Hardcaml** - [Jane Street Tech Blog](https://blog.janestreet.com/advent-of-hardcaml-2024/)
   * Solve advent of code puzzles entirely on an FPGA using HardCaml
4. **Recreate the Hardcaml ZPrize**  - [zprize.hardcaml.com](https://zprize.hardcaml.com/)
   * Go over their [blog post](https://blog.janestreet.com/really-low-latency-multipliers-and-cryptographic-puzzles/) and re-implement their [solution](https://blog.janestreet.com/zero-knowledge-fpgas-hardcaml/) from scratch
5. **OCaml All The Way Down :: Jane Street** - [Talk](https://www.janestreet.com/tech-talks/ocaml-all-the-way-down/)
   * 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](https://github.com/janestreet/learn-ocaml-workshop/blob/master/04-bigger-projects/irc-bot/README.org)&#x20;
2. Create your very own version of [fzf](https://github.com/junegunn/fzf) in OCaml - [fuzzy-finder README](https://github.com/janestreet/learn-ocaml-workshop/blob/master/04-bigger-projects/fuzzy-finder/README.org)&#x20;
3. Implement a small hardware module using HardCaml
4. Build your own deterministic hypervisor - [Antithesis blog](https://antithesis.com/blog/deterministic_hypervisor/) \*
5. Reimplement Z Garbage Collector from scratch - [Oracle Docs](https://docs.oracle.com/en/java/javase/21/gctuning/z-garbage-collector.html#GUID-8637B158-4F35-4E2D-8E7B-9DAEF15BB3CD) \*
6. MapReduce from Scratch - [Original Paper](https://static.googleusercontent.com/media/research.google.com/en/archive/mapreduce-osdi04.pdf)
7. Toy type inferencer by implementing Hindley-Milner algorithm - [Related Paper](https://research.cs.queensu.ca/home/jana/papers/bidir/) + [Related paper II](https://xnning.github.io/papers/let-arguments-go-first.pdf), [Blog I](https://eli.thegreenplace.net/2018/type-inference/) + [Blog II](https://rickyhan.com/jekyll/update/2018/05/26/hindley-milner-tutorial-rust.html) // Experimental  type inference scheme for Rust - [Blog](https://smallcultfollowing.com/babysteps/blog/2014/07/09/an-experimental-new-type-inference-scheme-for-rust/)
8. Reimplementing TCP/IP in pure OCaml - [RFC 9293](https://datatracker.ietf.org/doc/html/rfc9293) , [TCP/IP Illustrated](https://www.oreilly.com/library/view/tcpip-illustrated/020163354X/), [Low-Level Academy](https://lowlvl.org/)
9. Build a binary-serialization protocol generator
10. Writing a Game Boy Emulator - [LINK](https://linoscope.github.io/writing-a-game-boy-emulator-in-ocaml/)
11. Serde like framework for OCaml - [Docs](https://serde.rs/)&#x20;
12. OCaml  IDE - [LINK](https://x.com/tacticalgrace/status/1939681850542137521)
13. A proper web app using OCaml and ReasonML - [Docs](https://aantron.github.io/dream/)
14. Reimplement MIPS & RISC-V CPU in HardCaml - [LINK](https://ceramichacker.com/blog/20-1212-project-conclusion)&#x20;
15. An image compressor with quadtrees&#x20;
16. Writing An [Interpreter](https://interpreterbook.com/)  /  [Compiler](https://compilerbook.com/) 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](https://github.com/openai/tiktoken) with a handcrafted automaton
19. StatsD filter proxy - [Article](https://dev.to/yawaramin/practical-ocaml-314j) / [Reference](https://medium.com/tenable-techblog/optimizing-700-cpus-away-with-rust-dc7a000dbdb2)
20. User‑Level CPU Profiler  – [research.swtch.com](https://research.swtch.com/pprof)
21. Binary Memcached Protocol with OCaml and Bitstring - [Blog](https://andreas.github.io/2014/08/22/implementing-the-binary-memcached-protocol-with-ocaml-and-bitstring/)
22. Parser for [HCL](https://github.com/hashicorp/hcl) - [Reference](https://github.com/drowzy/hxl)
23. TODO app with the following stack:
    * Elm / ReasonML (frontend)
    * OCaml (backend)
    * SQLite (DB)
    * Nix (build, deployment)
24. More awesome stuff @ [hackocaml](https://github.com/orgs/tarides/projects/32)

### **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](https://github.com/grpc/grpc/issues/14251) to OCaml
2. Elasticsearch client for OCaml (ocaml-elasticsearch is abandoned)
3. Have [ppx\_graphql](https://github.com/andreas/ppx_graphql) support the full [GraphQL spec](http://spec.graphql.org/)
4. Bindings for [NATS/NATS Streaming](https://nats.io/)
5. Contribute to Mirage OS - [Github Repo](https://github.com/mirage/mirage)
6. [Raven](https://github.com/raven-ml/raven) is an ecosystem of libraries to make OCaml a first‑class citizen for ML
7. [Eio](https://github.com/ocaml-multicore/eio) — Effects-Based Parallel IO for OCaml 5
8. [Saturn](https://github.com/ocaml-multicore/saturn) is collection of Lock-free data structures for multicore OCaml&#x20;
9. [Kcas](https://github.com/ocaml-multicore/kcas/) provides Software Transactional Memory (STM) for OCaml
10. Help out people in the [official forums](https://discuss.ocaml.org/) &#x20;

### Here are some good blog posts on PL

*courtesy of* [*Max Bernstein*](https://bernsteinbear.com/blog/pl-writing/)&#x20;

* [a simple semi-space collector](https://wingolog.org/archives/2022/12/10/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](https://pypy.org/posts/2022/07/toy-optimizer.html) 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](https://pypy.org/posts/2024/08/toy-knownbits.html) by CF Bolz-Tereick introduces  to a new abstract domain for optimizers.
* [Cranelift, Part 3: Correctness in Register Allocation](https://cfallin.org/blog/2021/03/15/cranelift-isel-3/) by Chris Fallin also made proofs more accessible, but in a different way.&#x20;
* [Regular Expression Matching: the Virtual Machine Approach](https://swtch.com/~rsc/regexp/regexp2.html) by Russ Cox make regular expression engines sense.
* [micrograd](https://github.com/karpathy/micrograd) by Andrej Karpathy is a tiny implementation of neural networks with no libraries (not even NumPy).&#x20;
* [How I implement SSA form](https://gist.github.com/pizlonator/cf1e72b8600b1437dda8153ea3fdb963) by Fil Pizlo changed how you think about union-find.&#x20;
* [Speculation in JavaScriptCore](https://webkit.org/blog/10308/speculation-in-javascriptcore/) is another absolute banger by Fil Pizlo.&#x20;
* [Modernizing Compiler Design for Carbon Toolchain](https://www.youtube.com/watch?v=ZI198eFghJk) is a talk by Chandler Carruth on the design of the Carbon compiler.&#x20;
* [A Python Interpreter Written in Python](https://aosabook.org/en/500L/a-python-interpreter-written-in-python.html) by Allison Kaptur made bytecode interpreters (and, specifically, how CPython works internally) click.
* [Parsing expressions by precedence climbing](https://eli.thegreenplace.net/2012/08/02/parsing-expressions-by-precedence-climbing) by Eli Bendersky presented an understandable and easier-to-develop alternative to traditional hand-written recursive descent parsers.&#x20;
* [Ruby JIT Challenge](https://github.com/k0kubun/ruby-jit-challenge) by Takashi Kokubun is a great start to code generation and it is more general than JIT, too.&#x20;
* [An Incremental Approach to Compiler Construction](https://bernsteinbear.com/assets/img/11-ghuloum.pdf) (PDF) by Abdulaziz Ghuloum brought compilers and code generation from a mystical multi-pass beast down to an understandable single-pass form.&#x20;
* [Lessons from Writing a Compiler](https://borretti.me/article/lessons-writing-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](https://dl.acm.org/doi/10.1145/3434304) by \[multiple authors] changes how you think about optimizers and pass ordering.&#x20;
* [Cranelift: Using E-Graphs for Verified, Cooperating Middle-End Optimizations](https://github.com/bytecodealliance/rfcs/blob/main/accepted/cranelift-egraph.md) by Chris Fallin showed that e-graphs are workable and remarkably effective in a production compiler.
* [Acyclic Egraphs and Smart Constructors](https://www.philipzucker.com/smart_constructor_aegraph/) by Phil Zucker further explores acyclic egraphs in the small.&#x20;
* [This Reddit comment](https://old.reddit.com/r/ProgrammingLanguages/comments/mrifdr/treewalking_interpreters_and_cachelocality/gumsi2v/) by Bob Nystrom and [Flattening ASTs](https://www.cs.cornell.edu/~asampson/blog/flattening.html) 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:

1. [OCamlverse](https://ocamlverse.net/) - Community-driven OCaml knowledge base
2. [OCaml Discuss](https://discuss.ocaml.org/) - Forum for OCaml discussions
3. [/r/ocaml](https://www.reddit.com/r/ocaml/) - Reddit community

### Further Reading & Watching

1. The OCaml language Reference - [ocaml.org/manual/5.3/index](https://ocaml.org/manual/5.3/index.html)&#x20;
2. Teach Yourself Programming in Ten Years - [norvig.com/21-days](https://norvig.com/21-days.html)&#x20;
3. Laziness Impatience Hubris - [wiki.c2.com/LazinessImpatienceHubris](https://wiki.c2.com/?LazinessImpatienceHubris)
4. OCaml 5 Performance - [Part-1](https://roscidus.com/blog/blog/2024/07/22/performance/), [Part-2](https://roscidus.com/blog/blog/2024/07/22/performance-2/)
5. What are the biggest reasons newcomers give up on OCaml? - [Discuss.Ocaml Forum](https://discuss.ocaml.org/t/what-are-the-biggest-reasons-newcomers-give-up-on-ocaml/10958/435?u=kayceesrk)
6. Making OCaml Safe for Performance Engineering - [Talk](https://www.youtube.com/watch?v=g3qd4zpm1LA)
7. Jane Street's Blog and YT channel - [Blog](https://blog.janestreet.com/), [Youtube](https://www.youtube.com/@janestreet/search?query=OCaml)
8. OCaml for the Masses - [ACM](https://queue.acm.org/detail.cfm?id=2038036)
9. On getting started with Category Theory – [ludwigabap.com](https://ludwigabap.com/posts/On%20getting%20started%20with%20Category%20Theory)
10. Thomas Letan’s OCaml posts – [soap.coffee](https://soap.coffee/~lthms/tags/ocaml.html)
11. OK Mij’s FTP archive – [okmij.org](https://okmij.org/ftp/)
12. Functional Programming (DCL @ Stanford) – [dcl-prog.stanford.edu](https://dcl-prog.stanford.edu/)
13. CS43 – Class Information (Stanford Lambda) – [stanford-lambda.gitlab.io](https://stanford-lambda.gitlab.io)
14. CS 99: Functional Programming and Theorem Proving in Lean 4 – [leni.sh](https://perfect-math-class.leni.sh/)
15. OPLSS 2024 | University of Oregon Summerschool – [cs.uoregon.edu](https://www.cs.uoregon.edu/research/summerschool/summer25/)
16. Fun OCaml Multicore workshop – [github.com/ocaml-multicore](https://github.com/ocaml-multicore/fun-ocaml-workshop?tab=readme-ov-file)
17. OCaml 5 Parallel Programming tutorial – [github.com/ocaml-multicore](https://github.com/ocaml-multicore/ocaml5-tutorial)
18. Intro to Eio (video + discussion) – [discuss.ocaml.org](https://discuss.ocaml.org/t/introduction-to-eio-video/11571)
19. OCaml manual: Effect Handlers – [ocaml.org/manual/5.3/effects](https://ocaml.org/manual/5.3/effects.html)
20. OCaml manual: Parallelism – [ocaml.org/manual/5.3/parallelism](https://ocaml.org/manual/5.3/parallelism.html)
21. BugBash 2025: software reliability conference – [bugbash.antithesis.com](https://bugbash.antithesis.com/#about)
22. Haskell Performance – [wiki.haskell.org](https://wiki.haskell.org/Performance)
23. On Competing with C Using Haskell – [entropicthoughts.com](https://entropicthoughts.com/on-competing-with-c-using-haskell)
24. Haskell as fast as C – [donsbot.com](https://donsbot.com/2008/06/04/haskell-as-fast-as-c-working-at-a-high-altitude-for-low-level-performance/)
25. Data‑Oriented Design – [dataorienteddesign.com](https://www.dataorienteddesign.com/dodbook/node2.html)
26. OCaml Discourse – [discuss.ocaml.org](https://discuss.ocaml.org/)
27. Ludwig: On getting started with Category Theory - [Blog](https://ludwigabap.bearblog.dev/on-getting-started-with-category-theory/)
28. Category Theory for Programmers – [YouTube](https://www.youtube.com/watch?v=SmXB2K_5lcA\&list=PLVFrD1dmDdvcjCQDPhExqP56jqxp0Ssn_)

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ocamlstreet.gitbook.io/hardcaml-wiki/basics/ocaml-bootcamp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
