February 2017

Appeared at ICFP 2017

It is well-known that the simply typed lambda-calculus is modeled by any cartesian closed category (CCC). This correspondence suggests giving typed functional programs a variety of interpretations, each corresponding to a different category. A convenient way to realize this idea is as a collection of meaning-preserving transformations added to an existing compiler, such as GHC for Haskell. This paper describes such an implementation and demonstrates its use for a variety of interpretations including hardware circuits, automatic differentiation, incremental computation, and interval analysis. Each such interpretation is a category easily defined in Haskell (outside of the compiler). The general technique appears to provide a compelling alternative to deeply embedded domain-specific languages.

- Paper (800K PDF, 2017/02/27, updated 2017/06/30)
- Slides (400K PDF, 2017/09/05)
- Video (18 minutes)
- Related:
- “Teaching New Tricks to Old Programs”, Lambda Jam 2017 keynote talk (61 minutes)
- Video of “From Haskell to Hardware via CCCs”, 2015 talk (67 minutes)
- Project source repo
- Paper:
*Generic parallel functional programming: Scan and FFT*(2017) with illustrations generated by compiling Haskell programs to a graph category. - Paper:
*The simple essence of automatic differentiation*(2018) further developing the generalized category of differentiable functions, including*reverse-mode*AD. The paper derives several AD algorithms rigorously from simple specifications, including algorithms for*reverse-mode*AD that are far simpler than previously known algorithms. - Paper draft:
*Calculating compilers categorically*(2018), specifying and calculating a compiler to a simple stack-based machine.

```
@inproceedings{Elliott-2017-compiling-to-categories,
author = {Conal Elliott},
title = {Compiling to categories},
booktitle = {Proceedings of the ACM on Programming Languages (ICFP)},
year = {2017},
url = {http://conal.net/papers/compiling-to-categories}
}
```