September 2022:
This has spread to a far wider audience than I had anticipated - probably my fault for using a title that is in hindsight catnip for link aggregators. I wrote this back in 2021 just as a bunch of personal thoughts of my experiences using Rust over the years (not always well thought through), and don't intend on trying to push them further, outside of personal experiments and projects.
Managing a living language is challenging and difficult work, and I am grateful for all the hard work that the Rust community and contributors put in given the difficult constraints they work within. Many of the things I listed below are not new, and there's been plenty of difficult discussions about many of them over the years, and some are being worked on or postponed, or rejected for various good reasons. For more thoughts, please see my comment below.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Syntax | |
pub enum Expr { | |
Int(i32), | |
Neg(Box<Expr>), | |
Add(Box<Expr>, Box<Expr>), | |
Mul(Box<Expr>, Box<Expr>), | |
} | |
// Semantics |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(** Phrase generator based on an example from the Grammatical Framework tutorial. | |
- {{:https://okmij.org/ftp/gengo/NASSLLI10/} | |
Lambda: the ultimate syntax-semantics interface} | |
- {{:https://www.grammaticalframework.org/doc/tutorial/gf-tutorial.html#toc16} | |
Grammatical Framework Tutorial: Lesson 2} | |
Todo: | |
- generate languages (orthographies, vacabularies, grammars) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(** An elaborator for a simply typed lambda calculus with mutable metavars. | |
This implementation is based on Arad Arbel’s gist: | |
https://gist.github.com/aradarbel10/837aa65d2f06ac6710c6fbe479909b4c | |
*) | |
module Core = struct | |
(** {1 Types} *) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! Bidirectional type checker for a simple functional language | |
use std::rc::Rc; | |
#[derive(Clone, PartialEq, Eq)] | |
enum Type { | |
Bool, | |
Int, | |
Fun(Rc<Type>, Rc<Type>), | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module IndexedMonad = struct | |
module type S = sig | |
type ('i, 'a) t | |
val pure : 'a -> (_, 'a) t | |
val bind : ('i, 'a) t -> ('a -> ('i, 'b) t) -> ('i, 'b) t | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(** {0 An implementation of a small dependently typed language} | |
This is an implementation simple dependently typed language where types are | |
first-class and where the output types of functions may depend on the inputs | |
supplied to them. | |
Type checking is is implemented in terms of an {i elaborator}, which checks | |
and tanslates a user-friendly {i surface language} into a simpler and more | |
explicit {i core language} that is more closely connected to type theory. | |
Because we need to simplify types during elaboration we also implement an |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(** {0 Elaboration with Record Patching and Singleton Types} | |
This is a small implementation of a dependently typed language with | |
dependent record types, with some additional features intended to make it | |
more convenient to use records as first-class modules. It was originally | |
ported from {{: https://gist.github.com/mb64/04315edd1a8b1b2c2e5bd38071ff66b5} | |
a gist by mb64}. | |
The type system is implemented in terms of an ‘elaborator’, which type | |
checks and tanslates a user-friendly surface language into a simpler and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"tag":"Heading","contents":[0,"Martin-Löf Type Theory"]},{"tag":"Paragraph","contents":"A description of Martin-Löf Type Theory in Holbert, by Brendan Zabarauskas."},{"tag":"Paragraph","contents":"Original gist: ~https://gist.github.com/brendanzab/1b4732179b15201bf33fed6dbca02458~"},{"tag":"Heading","contents":[2,"Introduction"]},{"tag":"Paragraph","contents":"/Martin-Löf Type Theory/ (MLTT), also known as /Intuitionistic Type Theory/, is a type theory proposed by Per Martin-Löf in the mid 70s. It forms the basis of many popular dependently typed programming languages and theorem provers, for example Agda, Coq, Idris, Epigram, and more. The influence of MLTT also extends to other languages, for example partly inspiring the module systems of Standard ML and OCaml, and in the work on adding dependent types to Haskell."},{"tag":"Paragraph","contents":"The main forms of judgement in this presentation of Martin-Löf Type theory are:\n\n- $A:_type A$\n which can be read as “$A:A$ is a type”\n\n- $A a:_:_ a A$\n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- module(core, | |
[ % Operational semantics | |
eval/2, % +Expr, -VExpr | |
quote/2, % +VExpr, -Expr | |
normalise/2, % +Term, -Term | |
eval/3, % +Env, +Expr, -VExpr | |
quote/3, % +Len, +VExpr, -Expr | |
normalise/3, % +Env, +Term, -Term |