https://cs3110.github.io/textbook/cover.html Skip to main content Back to top [ ] [ ] [ ] Ctrl+K OCaml Programming: Correct + Efficient + Beautiful - Home Preface * About This Book * Installing OCaml Introduction * 1. Better Programming Through OCaml[ ] + 1.1. The Past of OCaml + 1.2. The Present of OCaml + 1.3. Look to Your Future + 1.4. A Brief History of CS 3110 + 1.5. Summary * 2. The Basics of OCaml[ ] + 2.1. The OCaml Toplevel + 2.2. Compiling OCaml Programs + 2.3. Expressions + 2.4. Functions + 2.5. Documentation + 2.6. Printing + 2.7. Debugging + 2.8. Summary + 2.9. Exercises OCaml Programming * 3. Data and Types[ ] + 3.1. Lists + 3.2. Variants + 3.3. Unit Testing with OUnit + 3.4. Records and Tuples + 3.5. Advanced Pattern Matching + 3.6. Type Synonyms + 3.7. Options + 3.8. Association Lists + 3.9. Algebraic Data Types + 3.10. Exceptions + 3.11. Example: Trees + 3.12. Example: Natural Numbers + 3.13. Summary + 3.14. Exercises * 4. Higher-Order Programming[ ] + 4.1. Higher-Order Functions + 4.2. Map + 4.3. Filter + 4.4. Fold + 4.5. Beyond Lists + 4.6. Pipelining + 4.7. Currying + 4.8. Summary + 4.9. Exercises * 5. Modular Programming[ ] + 5.1. Module Systems + 5.2. Modules + 5.3. Modules and the Toplevel + 5.4. Encapsulation + 5.5. Compilation Units + 5.6. Functional Data Structures + 5.7. Module Type Constraints + 5.8. Includes + 5.9. Functors + 5.10. Summary + 5.11. Exercises Correctness and Efficiency * 6. Correctness[ ] + 6.1. Specifications + 6.2. Function Documentation + 6.3. Module Documentation + 6.4. Testing and Debugging + 6.5. Black-box and Glass-box Testing + 6.6. Randomized Testing with QCheck + 6.7. Proving Correctness + 6.8. Structural Induction + 6.9. Equational Specification + 6.10. Summary + 6.11. Exercises * 7. Mutability[ ] + 7.1. Refs + 7.2. Mutable Fields + 7.3. Arrays and Loops + 7.4. Summary + 7.5. Exercises * 8. Data Structures[ ] + 8.1. Hash Tables + 8.2. Amortized Analysis + 8.3. Red-Black Trees + 8.4. Sequences + 8.5. Memoization + 8.6. Persistent Arrays + 8.7. Promises + 8.8. Monads + 8.9. Summary + 8.10. Exercises Language Implementation * 9. Interpreters[ ] + 9.1. Example: Calculator + 9.2. Parsing + 9.3. Substitution Model + 9.4. Environment Model + 9.5. Type Checking + 9.6. Type Inference + 9.7. Summary + 9.8. Exercises Lagniappe * The Curry-Howard Correspondence Appendix * Big-Oh Notation * Virtual Machine * Repository * Suggest edit * Open issue * .md * .pdf OCaml Programming: Correct + Efficient + Beautiful OCaml Programming: Correct + Efficient + Beautiful# A textbook on functional programming and data structures in OCaml, with an emphasis on semantics and software engineering. This book is the textbook for CS 3110 Data Structures and Functional Programming at Cornell University. A past title of this book was "Functional Programming in OCaml". Spring 2025 Edition. Videos. There are over 200 YouTube videos embedded in this book. They can be watched independently of reading the book. Start with this YouTube playlist. Authors. This book is based on courses taught by Michael R. Clarkson, Robert L. Constable, Nate Foster, Michael D. George, Dan Grossman, Justin Hsu, Daniel P. Huttenlocher, Dexter Kozen, Anshuman Mohan, Greg Morrisett, Andrew C. Myers, Radu Rugina, and Ramin Zabih. Together they have created over 20 years worth of course notes and intellectual contributions. Teasing out who contributed what is, by now, not an easy task. The primary compiler and author of this work in its form as a unified textbook is Michael R. Clarkson, who as of the Fall 2021 edition was the author of about 40% of the words and code tokens. Copyright 2021-2025 Michael R. Clarkson. Released under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. Creative Commons License next About This Book By Michael R. Clarkson et al. (c) Copyright 2025.