The gift from decades of research and development activities of functional programming languages includes efficient garbage collection, type-directed optimization, and closure conversions. These techniques are starting to be incorporated in programming languages from non-functional paradigms such as C++ and Java, promoting more "functional style" in general programming.
When we see programs written in functional programming languages and shocked at its beauty and simplicity, we may wonder its execution efficiency. In this course, we jump into an implementation of a working compiler for a functional programming language and learn techniques to gradually converting highly abstract description of the functional-style program to lower level executable code, through series of conversions. These conversions are defined over well-defined interfaces: from upper-lever abstract interface down to lowest-level machine description are abstract syntax trees, K-normal forms, closure language, virtual machine.
Students will be exposed to one of the best example of systematically organized software project which deals with software complexity with formalism, layers of abstraction, and machine independence.
Students will learn
1) a functional programming language,
2) methodologies of functional programming,
3) organization of a compiler for a functional programming language
During the course, we read a compiler of a tiny functional programming language, called MinCaml, which is written in a functional programming language called OCaml. From this experience, we can learn (1) an organization of middle-scale software project, (2) that highly abstract description of is gradually transformed down to lower-level representation passing through abstraction layers, (3) techniques to balance between description power and execution efficiency.
Functional programming, compiler organization, OCaml
✔ Specialist skills | Intercultural skills | Communication skills | Critical thinking skills | Practical and/or problem-solving skills |
The course gives lectures for the first four weeks.
For the rest, students choose parts of the compiler components and explain the implementation. Each class starts with students' explanation, followed by the instructor's brief overview for next components that are covered in the coming class.
Course schedule | Required learning | |
---|---|---|
Class 1 | Overview | Guidance |
Class 2 | Introduction to functional programming in OCaml (1) | Primitive data types, compound data types, algebraic data types. |
Class 3 | Introduction to functional programming in OCaml (2) | Recursive data structures, recursive functions, higher-order functions, mutable states. |
Class 4 | Introduction to functional programming in OCaml (3) | Records, exception handling, modules, standard library, tools |
Class 5 | Software architecture of the MinCaml compiler | MinCaml is a tiny functional programming language and is implemented in a functional programming language OCaml. |
Class 6 | From program to abstract syntax tree | Lexical analysis and parsing. |
Class 7 | Type analysis | Type analysis, type inference, unification |
Class 8 | From abstract syntax tree to K-normal form | K-normal form, alpha-conversion |
Class 9 | Optimization(1) | Beta-reduction, reduction of nested let's, inline code expansion |
Class 10 | Optimization (2) | Constant folding, elimination of redundant definitions |
Class 11 | Elimination of functional closures | Closure conversion |
Class 12 | Generation of abstract machine code | Abstract machine code generation |
Class 13 | Register assignment | Register assignment |
Class 14 | Generation of executable code | Generation of assembly code, runtime system |
Class 15 | Wrap up | Wrap up |
Unfixed
Courseware will be provided on GitHub. GitHub repository information is found on OCW-i.
Students will be assessed on their understanding of functional programming and organization of a compiler for a tiny functional programming language.
Basic understanding of algorithms and data structures, and fluency with at least one programming language are required.