Published July 18, 2024 | Version 1.0
Software Open

# Haskell and Agda code for the article "Calculating Compilers Effectively"

## Creators

• 1. University of Nottingham
• 2. IT University of Copenhagen

## Description

The Haskell and Agda source code for the paper

Calculating Effectful Compilers

In these files we give practical implementations of each of the
three effects we consider in the paper.  For each one, we include
the full source code as described in the paper itself, and full
definitions for each of the concrete effect interpretations.

Agda (print.agda, state.agda, non-det.agda, lemmas.agda)

As noted in the paper, we use Agda to formally verify the correctness
of our calculations.  These four files constitute those proofs.
We use function extensionality, which is postulated in lemmas.agda.

Each Agda file begins by translating the types and functions from
Haskell into Agda's syntax.  We prove all relevant results:

* The functor and monad laws for each effect type

* Compiler correctness

exec (comp e c) s = do v <- eval e; exec c (v : s)

* Correctness of the fusion of run and exec:

exec' c s = run (exec c s)

There are some differences between the Agda presentation and that
given in the paper.  In particular:

* Agda does not like partial functions, so we augment the stack
with an arity (essentially making it a vector) and the code with
tags to describe how it transforms the shape of the stack.  This
is a standard, straightforward transformation which doesn't
affect the validity of the proofs, but keeps Agda happy.

* Agda's 'do' notation only permits one monad per file.  So we are
forced to translate the IO 'do' blocks into binds and lambdas.

* The calculations are presented as "calculational proofs".  Agda
does not provide any utility for calculating data types and
functions *during* equational proofs, so we structure these by
first writing down the calculated definition and then following
up with the proof that it is correct.

These proofs, while technically not calculations, still follow the
same steps as in the paper, so the reader can follow along.

## Files

Name Size
13.2 kB

### Related works

Is referenced by
Conference paper: 10.1145/3677999.3678283 (DOI)

### Funding

Semantics-Directed Compiler Construction: From Formal Semantics to Certified Compilers EP/Y010744/1
Engineering and Physical Sciences Research Council

### Software

Programming language