Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seeker04/stlc-agda-elab
Agda formalisation of an elaborator for a simply typed language
https://github.com/seeker04/stlc-agda-elab
Last synced: 5 days ago
JSON representation
Agda formalisation of an elaborator for a simply typed language
- Host: GitHub
- URL: https://github.com/seeker04/stlc-agda-elab
- Owner: Seeker04
- License: mit
- Created: 2023-07-24T22:55:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-26T17:39:41.000Z (5 months ago)
- Last Synced: 2024-06-26T22:10:54.056Z (5 months ago)
- Language: Agda
- Size: 4.98 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Agda formalisation of an elaborator for a language based on simply typed lambda calculus
## Abstract
Programming languages are the backbone of software development. Defining them with mathematical rigorousness in a formal framework can help us better understand and reason about them. One way of explaining languages is through the process of elaboration. It refines the concept of the language from broader ideas such as strings and lexical tokens to more concrete and strict ones like syntax trees and well-typed terms.
This thesis aims to walk the reader through each step of such an elaboration. Our method is an extension to an existing formalisation of a simple language. We go from source code by lexical analysis to a list of tokens, then by parsing to an abstract syntax tree, which is followed by scope checking leading to an abstract binding tree. Finally, we present a bidirectional type checking algorithm which turns the binding tree to a well-typed term of our language. We apply a correct by construction approach by 1.) formalising all levels and the algorithms between them in type theory using Agda, 2.) constructing terms with an algebraic description, which cannot be badly typed by definition.
Our language is based on simply typed lambda calculus with the function space having finite types: booleans, nullary/binary products and sums; inductive types: naturals, lists, trees (and their iterators); coinductive types: streams and simple state machines; a few additional operators.
We discuss both the benefits and difficulties of the presented solution. The study is concluded by ideas on how our framework can be extended or improved.
**Keywords:** lambda-calculus, Agda, formalisation, elaboration, parsing, typechecking
## About
This project started as an extension to an existing formalisation. The quotiented well-typed description that you can see in [STLC.agda](src/STLC.agda) was written by Ambrus Kaposi [here](https://bitbucket.org/akaposi/typesystems/src/master/).
If you wish to see the commits of the elaborator from before going independent, you can find them [in this fork](https://bitbucket.org/zahoranb/typesystems/commits/).
You can read my MSc thesis in [STLC-elaboration-in-Agda.pdf](thesis/STLC-elaboration-in-Agda.pdf), view the presentation in [slides.pdf](slides/slides.pdf) and browse the source code in [src](src).
## Installation
This project requires [Agda version 2.6.2.2](https://wiki.portal.chalmers.se/agda/Main/Download).
Here is a method to install:
```bash
# from https://www.haskell.org/ghcup/
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
cabal update
cabal install alex happy
cabal install Agda-2.6.2.2
```The following libraries are also required:
* [agda-stdlib-1.7.1](https://github.com/agda/agda-stdlib/releases)
* [agdarsec-0.5.0](https://github.com/gallais/agdarsec/releases)1. Make sure to download the correct versions, i.e., `1.7.1` and `0.5.0`, respectively
2. Follow the steps of the [stdlib install guide](https://github.com/agda/agda-stdlib/blob/master/notes/installation-guide.md)
3. Also, add the agdarsec path next to the stdlib one in your `$HOME/.agda/libraries`:
```
/agda-stdlib-1.7.1/standard-library.agda-lib
/agdarsec-0.5.0/agdarsec.agda-lib
```Now you should be able to typecheck the project.