Syllabus
This is the preliminary list of proposed lecture topics and readings. See the dateline for what we actually end up doing as the course evolves.
Intro to Functional Programming in OCaml
- History and background
- Basic OCaml coding with simple data, lists, and functions
- The
List
library and combinatorial programming - Variants
- Programming with persistent data structures
- Records
- Elementary modules (
struct
,sig
, existential types) - Side effects: state, exceptions, I/O, mutable data structure libraries
- More modules: functors, first-class modules,
include
, more data structure libraries
Specification
- Specifying program behavior
- Type-directed programming
- Pre- and post-conditions,
assert
- Data structure invariants
- Reasoning about programs by induction
Testing
- Review of testing principles
- Unit testing with
OUnit2
- Code coverage with
Bisect
- Random testing with
Base_quickcheck
Idiomatic Functional Programming
- Functional programming principles: concision, modularity, avoiding effects
- Functional programming idioms: DRY, interfaces, combinators
- Efficiency in FP
- Idiomatic FP by example: code reviews of well-written OCaml
- OO vs Imperative vs FP; the expression problem
Advanced OCaml
- The type sorts of OCaml; Existential types
- Module sharing constraints, first-class modules
- Phantom types
- GADTs
Encoding effects with monads
- Implicit state threading with persistent data structures
- Implicit exception encoding with
Ok/Error
- Officially encoding exceptions: the exception monad
- The monad laws
- Using the exception monad: syntactic sugar, examples
- More monads and their uses: I/O, state
- Asynchronous programming with Lwt
Algebraic Effects (aka the mother of all effects)
- Multicore OCaml’s
effect
andcontinue
/discontinue
- Encoding control effects with the MOAF: coroutines, generators, promises, asynchronous I/O
- Control effects code reviews
Multicore Programming
- Multicore OCaml threads, channels, async/await, etc.
OCaml Tools and miscelanea
(Smaller topics injected as tangents or for self-study)
- Visual Studio Code’s OCaml Platform
utop
and top-level directivesdune
- Making standalone OCaml executables
- Basic
ppx
extensions (deriving
etc) - Optional and named function arguments
- Advanced pattern matching formats
|>
and@@
syntax
Resources
- Real World OCaml 2nd Edition - a comprehensive book focusing on the software engineering side of OCaml
- Learn OCaml - a series of online exercises to teach yourself OCaml
Related course materials
- Cornell CS3110 book - book used in a sophomore-level course on functional programming
- Advanced Functional Programming - a course taught at Cambridge focusing on the deeper principles behind modern OCaml.
- Functional Programming - a course taught at Princeton focusing more on program correctness.
Meta-resources
- Awesome OCaml - a curated list of OCaml resources
- Ocaml.org - the central clearinghouse for all things OCaml, includes lists of tutorials, books, and videos.