mpri-funcprog-project/README.md

207 lines
8.6 KiB
Markdown
Raw Normal View History

2017-09-11 10:40:02 +02:00
# Functional programming and type systems (2017-2018)
2017-09-11 10:29:22 +02:00
2017-09-20 15:48:34 +02:00
This page supplements
[the official page of MPRI 2-4](https://wikimpri.dptinfo.ens-cachan.fr/doku.php?id=cours:c-2-4-2).
2017-09-14 18:11:11 +02:00
2017-09-20 15:48:34 +02:00
## Location and duration
2017-09-14 18:11:11 +02:00
2017-09-20 15:48:34 +02:00
The lectures take place at University Paris 7 - Denis Diderot,
Bâtiment Sophie Germain, in room 2035.
They are scheduled on Fridays from 12:45 to 15:30.
There is a 15-minute break in the middle of each lecture.
2017-09-14 16:35:49 +02:00
2017-09-11 10:40:02 +02:00
## Teachers
2017-09-11 10:29:22 +02:00
2017-09-11 10:32:58 +02:00
* Functional Programming: Under the Hood (12h30, [François Pottier](http://gallium.inria.fr/~fpottier))
2017-09-14 11:22:15 +02:00
* [Metatheory of Typed Programming Languages](http://gallium.inria.fr/~remy/mpri/) (12h30, [Didier Rémy](http://gallium.inria.fr/~remy/), *head*)
2017-09-11 10:32:58 +02:00
* Advanced Aspects of Type Systems (12h30, [Yann Régis Gianas](http://www.pps.jussieu.fr/~yrg/))
* Dependently-typed Functional Programming (12h30, [Pierre-Evariste Dagand](https://pages.lip6.fr/Pierre-Evariste.Dagand/))
2017-09-11 10:40:02 +02:00
## Aims
This course presents the principles and formalisms that underlie many of
today's typed functional programming languages.
2017-09-21 11:06:57 +02:00
(Here are some [introductory slides](slides/fpottier-00.pdf).)
2017-09-11 10:40:02 +02:00
The course is made up of four parts and can be split after the first two
parts.
In the first part, we discuss the *operational semantics* of functional
programming languages, and we present several classic *program
transformations*, including closure conversion, defunctionalization, and the
transformation into continuation-passing style (CPS). These program
transformations are interesting from two points of view. First, they are
*useful programming techniques*, which can help write or understand
programs. Second, they are used in the *compilation* of functional
programming languages, so they help understand what happens when the machine
executes a program. We use operational semantics to *prove* that the meaning
of programs is preserved by these transformations. Finally, we suggest how
these definitions and theorems can be expressed in a form that a machine can
check. That is, although Coq is not a prerequisite of the course, we will at
least try to *read and understand Coq definitions and statements*.
In the second part, we focus on the meta-theoretical properties of type
systems. We study parametric polymorphism (as in System F and ML), data
types and type abstraction. We show syntactic type soundness (via progress
and subject reduction) by reasoning by induction on typing derivations. We
also show how to obtain semantic properties via logical relations by
2017-09-20 15:48:34 +02:00
reasoning by induction on the structure of types. Finally, we introduce
subtyping, row polymorphism, and illustrate the problems induced by
2017-09-11 10:40:02 +02:00
side effects (references) and the need for the value restriction.
The third part of the course describes more advanced features of type
systems: exceptions and effect handlers, including their typechecking and
static analyses: type inference, data flow and control flow analyses.
Finally, it introduces dependent types and refinement types.
The last part focuses on the use of dependent types for programming:
effectful programming with monads and algebraic effects; tagless
interpreters; programming with total functions; generic programming.
We also show the limits of dependently-typed functional programming.
## Approximate syllabus
### Functional Programming: Under the Hood
* (22/09/2017)
Introduction ([slides 00](slides/fpottier-00.pdf)).
Syntax and operational semantics, on paper and on a machine
([slides 01a](slides/fpottier-01a.pdf))
([slides 01b](slides/fpottier-01b.pdf))
2017-09-26 16:50:45 +02:00
([OCaml solution to Newton-Raphson exercise](ocaml/NewtonRaphson.ml))
([Even.v](coq/Even.v)).
* (29/09/2017)
From a small-step semantics down to an efficient verified interpreter,
2017-09-26 16:50:45 +02:00
in several stages
([Coq demo](coq/DemoSyntaxReduction.v))
([slides 02](slides/fpottier-02.pdf))
([OCaml code](ocaml/Lambda.ml))
([Coq repo](coq/)).
2017-09-11 10:41:47 +02:00
* (06/10/2017) Compiling away first-class functions: closure conversion, defunctionalization.
* (13/10/2017) Compiling away the call stack: the CPS transformation.
* (20/10/2017) Equational reasoning and program optimizations.
2017-09-11 10:40:02 +02:00
### Metatheory of Typed Programming Languages
2017-09-15 08:55:27 +02:00
* (15/09/2017)
2017-09-15 08:52:43 +02:00
[Metatheory of System F](http://gallium.inria.fr/~remy/mpri/slides1.pdf)
2017-09-20 15:48:34 +02:00
(See also [intro](http://gallium.inria.fr/~remy/mpri/slides8.pdf),
and chap [1](http://gallium.inria.fr/~remy/mpri/cours1.pdf)
and [2](http://gallium.inria.fr/~remy/mpri/cours2.pdf)
2017-09-20 13:50:54 +02:00
of [course notes](http://gallium.inria.fr/~remy/mpri/cours.pdf))
2017-09-20 15:48:34 +02:00
* (27/10/2017) ADTs, existential types, GADTs.
2017-09-11 10:43:57 +02:00
* (03/11/2017) Logical relations.
2017-09-20 15:48:34 +02:00
* (10/11/2017) Subtyping. Rows.
2017-09-14 11:22:15 +02:00
* (17/11/2017) References, Value restriction, Side effects.
2017-09-11 10:40:02 +02:00
### Advanced Aspects of Type Systems
2017-09-11 10:41:47 +02:00
* Exceptions and effect handlers. (Compiled away via CPS.)
* Typechecking exceptions and handlers.
* Type inference. (ML. Bidirectional. Elaboration.)
* Data/control flow analysis.
* Functional correctness. Intro to dependent/refinement types.
2017-09-11 10:40:02 +02:00
### Dependently-typed Functional Programming
2017-09-11 10:41:47 +02:00
* Effectful functional programming.
* Dependent functional programming.
* Total functional programming.
* Generic functional programming.
* Open problems in dependent functional programming.
2017-09-11 10:47:09 +02:00
2017-09-14 15:12:03 +02:00
## Evaluation of the course
Two written exams (a partial and a final exam) and one programming project
or several programming exercises are used to evaluate the students that
follow the full course. Only the partial exam will count to grade students
who split the course.
2017-09-14 16:35:49 +02:00
Although the course has changed, you may still have a look at previous exams
available with solutions:
2017-09-14 15:18:16 +02:00
2017-09-20 15:48:34 +02:00
- mid-term exam 2016-2017:
2017-09-14 15:22:47 +02:00
[Record concatenation](http://gallium.inria.fr/~remy/mpri/exams/partiel-2016-2017.pdf)
2017-09-20 15:48:34 +02:00
- mid-term exam 2015-2016:
2017-09-14 15:22:47 +02:00
[Type containment](http://gallium.inria.fr/~remy/mpri/exams/partiel-2015-2016.pdf)
- final exam 2014-2015: [Copatterns](http://gallium.inria.fr/~remy/mpri/exams/final-2014-2015.pdf)
2017-09-20 15:48:34 +02:00
- mid-term exam 2014-2015:
2017-09-14 15:22:47 +02:00
[Information flow](http://gallium.inria.fr/~remy/mpri/exams/partiel-2014-2015.pdf)
2017-09-20 15:48:34 +02:00
- final exam 2013-2014:
2017-09-14 15:22:47 +02:00
[Operation on records](http://gallium.inria.fr/~remy/mpri/exams/final-2013-2014.pdf)
2017-09-20 15:48:34 +02:00
- mid-term exam 2013-2014:
2017-09-14 15:22:47 +02:00
[Typechecking Effects](http://gallium.inria.fr/~remy/mpri/exams/partiel-2013-2014.pdf)
2017-09-20 15:48:34 +02:00
- final exam 2012-2013:
2017-09-14 15:22:47 +02:00
[Refinement types](http://gallium.inria.fr/~remy/mpri/exams/final-2012-2013.pdf)
2017-09-20 15:48:34 +02:00
- mid-term exam 2012-2013:
2017-09-14 15:22:47 +02:00
[Variations on ML](http://gallium.inria.fr/~remy/mpri/exams/partiel-2012-2013.pdf)
2017-09-20 15:48:34 +02:00
- final exam 2011-2012:
2017-09-14 15:22:47 +02:00
[Intersection types](http://gallium.inria.fr/~remy/mpri/exams/final-2011-2012.pdf)
2017-09-20 15:48:34 +02:00
- mid-term exam 2011-2012:
2017-09-14 15:22:47 +02:00
[Parametricity](http://gallium.inria.fr/~remy/mpri/exams/partiel-2011-2012.pdf)
2017-09-14 15:12:03 +02:00
- final exam 2010-2011:
2017-09-14 15:22:47 +02:00
[Compiling a language with subtyping](http://gallium.inria.fr/~xleroy/mpri/2-4/exam-2010-2011.pdf)
2017-09-14 15:18:16 +02:00
- mid-term exam 2010-2011:
2017-09-14 15:22:47 +02:00
[Compilation
2017-09-14 15:20:36 +02:00
of polymorphic records](http://gallium.inria.fr/~remy/mpri/exams/2010/partiel-2010-2011.pdf)
2017-09-14 15:12:03 +02:00
2017-09-11 10:47:09 +02:00
## Recommended software
Please install [opam](https://opam.ocaml.org/doc/Install.html) first.
2017-09-11 10:47:09 +02:00
Then, install OCaml 4.0x and Coq **8.5** via the following commands:
2017-09-11 10:47:09 +02:00
```bash
opam init --comp=4.05 # for instance
opam repo add coq-released https://coq.inria.fr/opam/released
opam update
opam install -j4 -v coq.8.5.3
```
(Do *not* install Coq 8.6. The version of AutoSubst that I am using is
not compatible with it. If for some reason you need Coq 8.6, or have
already installed Coq 8.6, note that `opam switch` can be used to let
multiple versions of Coq coexist.)
2017-09-11 10:50:20 +02:00
2017-09-20 15:51:16 +02:00
Please also install François Pottier's
[variant](https://github.com/fpottier/autosubst)
of the
[AutoSubst](https://www.ps.uni-saarland.de/autosubst/) library:
```bash
git clone git@github.com:fpottier/autosubst.git
make -C autosubst install
```
In order to use Coq inside `emacs`,
[ProofGeneral](https://proofgeneral.github.io/)
is highly recommended.
Here is a suggested installation script:
```bash
rm -rf /tmp/PG
cd /tmp
git clone git@github.com:ProofGeneral/PG.git
cd PG
EMACS=/Applications/Aquamacs.app/Contents/MacOS/Aquamacs
if [ ! -x $EMACS ]; then
EMACS=emacs
fi
make EMACS=$EMACS compile
TARGET=/usr/local/share/emacs/site-lisp/ProofGeneral
sudo rm -rf $TARGET
sudo mv /tmp/PG $TARGET
```
Enable ProofGeneral by adding the following line to your `.emacs` file:
```elisp
(load-file "/usr/local/share/emacs/site-lisp/ProofGeneral/generic/proof-site.el")
```
If desired, ProofGeneral can be further
[customized](https://proofgeneral.github.io/doc/userman/ProofGeneral_9/).
2017-09-11 10:50:20 +02:00
## Bibliography
2017-09-20 15:48:34 +02:00
[Types and Programming Languages](https://mitpress.mit.edu/books/types-and-programming-languages),
2017-09-11 10:50:20 +02:00
Benjamin C. Pierce, MIT Press, 2002.
2017-09-14 11:22:15 +02:00
[Advanced Topics in Types and Programming Languages](https://www.cis.upenn.edu/~bcpierce/attapl/),
Edited by Benjamin C. Pierce, MIT Press, 2005.