Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/segeljakt/type-theory
Typed λ-calculus in Rust
https://github.com/segeljakt/type-theory
Last synced: 9 days ago
JSON representation
Typed λ-calculus in Rust
- Host: GitHub
- URL: https://github.com/segeljakt/type-theory
- Owner: segeljakt
- Created: 2019-06-05T10:28:16.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-27T15:03:33.000Z (over 1 year ago)
- Last Synced: 2024-10-12T19:14:56.954Z (24 days ago)
- Language: Rust
- Homepage:
- Size: 50.8 KB
- Stars: 28
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-rust-formalized-reasoning - type-theory - typed λ-calculus. (Lambda Calculus / Libraries)
README
Typed λ-calculus in Rust
This project is both a playground for experimenting with type theory, and a reference for how one can implement a functional programming language compiler in Rust.
# Syntax
```
PROG ::= FUN* EXP # ProgramEXP ::= NAME # Variable
| LIT # Literal
| λ VAR . EXP # Abstraction
| EXP EXP # Application
| let NAME = EXP in EXP # Let-binding
| ( EXP ) # ParenthesizedLIT ::= INT # Integer
| BOOL # Boolean
| STR # StringFUN ::= NAME :: ( ∀ NAME* . )? TYPE # Function
TYPE ::= TYPE → TYPE # Function type
| NAME # Nominal
| ( TYPE ) # Parenthesized
```# Testing
You can run the examples as follows:
```bash
cargo run --example=end-to-end
``````
- :: (int → int)
+ :: (int → (int → int))5
Inferred type: int"hello"
Inferred type: strtrue
Inferred type: bool((+ 1) 2)
Inferred type: int((+ true) false)
Error: Cannot unify `int` with `bool`let id = λx.(x x) in id
Error: `'t0` and `('t0 → 't1)` are recursive...
```Planned/finished features are:
# Front-end
- [x] Lexing ([regex](https://crates.io/crates/regex))
- [x] Parsing ([LALRPOP](https://crates.io/crates/lalrpop))
- [ ] Alpha conversion ([De-Brujin Indices](https://en.wikipedia.org/wiki/De_Bruijn_index))
- [x] Bi-directional type inference ([Hindley-Milner, Algorithm W](https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system))
- [ ] Type classes# Quality of life:
- [x] Pretty printing
- [x] Error recovery
- [ ] Language Server Protocol integration ([LSP](https://langserver.org/) using [codespan](https://docs.rs/codespan/0.3.0/codespan/))# Middle-end
N/A
# Back-end
N/A
# Learning resources
* [Ionut G. Stan: Let’s write a type checker @ I T.A.K.E. Unconference 2015](https://www.youtube.com/watch?v=oPVTNxiMcSU)
* [A basic implementation of Hindley-Milner type inference via Algorithm W in Rust.](https://github.com/nwoeanhinnogaehr/algorithmw-rust)
* [f(by) 2019 - Christoph Hegemann, TYPE INFERENCE FROM SCRATCH](https://www.youtube.com/watch?v=ytPAlhnAKro)