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 and continue/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 directives
  • dune
  • Making standalone OCaml executables
  • Basic ppx extensions (deriving etc)
  • Optional and named function arguments
  • Advanced pattern matching formats
  • |> and @@ syntax

Resources

Meta-resources