Course10610600273 lectures
Functional Programming with OCaml
Prof. K C Sivaramakrishnan · IIT Madras
About
This course introduces the principles of functional programming using OCaml, with a strong emphasis on building reliable and secure software systems. It covers core concepts such as higher-order functions, type systems, and modular design, along with advanced topics like concurrency and memory safety. Through hands-on programming assignments and projects, learners will gain practical experience in writing robust systems software using modern functional programming techniques.
The interactive course book is available at: https://fplaunchpad.org/ocaml_nptel/
Intended audience: • Undergraduate and postgraduate students in Computer Science and related disciplines. • Systems engineers, software developers, and researchers. • Professionals interested in secure and reliable software development. • Any interested learners.
Prerequisites: C Programming, Data structures and Algorithms
Lectures
Week 1
- Course introduction: what you'll learn, how it's run
- Why functional programming?
- A tour of OCaml: values, types, and the toplevel
- Your first OCaml program: hello, world (and beyond)
- Tutorial: temperature conversions and small expressions
Week 2
- Literals: integers, floats, booleans, strings
- `let` bindings and shadowing
- Static vs dynamic semantics, and type inference
- Operators, precedence, and common pitfalls
- `if`/`then`/`else` as an expression
- Tutorial: small expressions, end to end
Week 3
- Functions as values, and anonymous functions
- Recursion
- Currying and partial application
- Tail recursion and accumulators
- Local functions and mutual recursion
- Tutorial: Fibonacci, GCD, power, digits
Week 4
- Tuples
- Records
- Variants (sum types)
- Recursive types: lists, trees, expressions
- Tutorial: a tiny AST for OCaml
- Tutorial: a tiny file system
Week 5
- Basic patterns: literals, variables, wildcards
- Pattern matching on lists and trees
- Nested patterns and or-patterns
- Guards: when-clauses on patterns
- Exhaustiveness checking
- Tutorial: an interpreter for the OCaml AST
Week 6
- Functions as values, revisited
- map: transform every element
- filter: keep what passes the predicate
- fold: reduce a list to a single value
- Function composition and pipelines
- Tutorial: fold across data structures
Week 7
- Mutable references
- Mutable records and arrays
- Exceptions
- Streams and Laziness
- Memoization
- Module basics
- Module signatures
- Functors
- Tutorial: A Queue functor
Week 8
- The option monad and `let*`
- Monad laws, the list monad, and the result monad
- The state monad and parameterised state
- GADTs: variants with type-level information
- GADTs: use cases beyond toy interpreters
- GADTs: hlists and witnesses
- Tutorial: a tiny well-typed evaluator
Week 9
- Why test a type-safe program?
- Specifications and invariants
- Designing test cases: black-box and glass-box
- Unit testing
- Property-based testing with QCheck
- Model-based testing of stateful data structures
- Tutorial: testing the expr evaluator with OUnit2 and QCheck
Week 10
- What memory safety is, and why it is a security story
- Memory safety by construction
- Data races are undefined behaviour
- Where OCaml itself has UB
- Tutorial: walking Heartbleed end to end
Week 11
- Locality: safe stack allocation
- Uniquenss: the only reference
- Linearity: use at most once
- Contention: Synchronisation at compile time
- Portability: data race freedom across domains
- Tutorial: a resource-management API
Week 12
Syllabus and materials
At NPTEL, as the course publishes them.
Credits and licence
- Institution
- IIT Madras
- Department
- Computer Science and Engineering
- Teacher
- Prof. K C Sivaramakrishnan
- Level
- Undergraduate
- Language
- English
- Subjects
- Computer science, Engineering
- Source
- NPTEL
- Licence
- CC BY-NC-SA, as NPTEL states it. Non-commercial use only. NPTEL's terms
- Attribution
- NPTEL states: "Distributed under Creative Commons Attribution-ShareAlike / CC BY - NC - SA", beside a BY-NC-SA badge.
- Who can watch
- NPTEL gives no rating. Invisible Network shows it to Tweens profiles and older, judged from what the source says about it. How courses are placed