|
| 1 | +//! The A-normal form language, with types preserved. |
| 2 | +//! |
| 3 | +//! This language makes an explicit distinction between _computations_ and |
| 4 | +//! _values_, and makes the evaluation indifferent to the order in which |
| 5 | +//! computations are executed (somewhat like [applicative functors in |
| 6 | +//! Haskell][applicative-functors]). It does this through alterations to the |
| 7 | +//! syntactic structure of the [core language][crate::lang::core], while |
| 8 | +//! avoiding making many significant changes to the type structure which |
| 9 | +//! would make type preservation more challenging. |
| 10 | +//! |
| 11 | +//! The main inspiration for this language is William Bowman's dissertation, |
| 12 | +//! [Compiling with Dependent Types][wjb-dissertation]. |
| 13 | +//! |
| 14 | +//! Note: the 'A' in 'A-Normal Form' does not stand for anything, at least |
| 15 | +//! [according to one of the original authors, Matthias Felleisen][just-a]. |
| 16 | +//! I really wish there was a better name for this language. |
| 17 | +//! |
| 18 | +//! [applicative-functors]: https://wiki.haskell.org/Applicative_functor |
| 19 | +//! [wjb-dissertation]: https://www.williamjbowman.com/resources/wjb-dissertation.pdf |
| 20 | +//! [just-a]: https://vimeo.com/387739817 |
| 21 | +
|
| 22 | +pub use crate::lang::core::{Constant, LocalIndex, UniverseLevel, UniverseOffset}; |
| 23 | + |
| 24 | +/// Values are terms that do not reduce. |
| 25 | +pub enum Value { |
| 26 | + /// Global variables. |
| 27 | + Global(String), |
| 28 | + /// Local variables. |
| 29 | + Local(LocalIndex), |
| 30 | + |
| 31 | + /// Annotated values |
| 32 | + Ann(Box<Value>, Box<Configuration>), |
| 33 | + |
| 34 | + /// The type of types. |
| 35 | + Universe(UniverseLevel), |
| 36 | + /// Lift a value by the given number of universe levels. |
| 37 | + Lift(Box<Value>, UniverseOffset), |
| 38 | + |
| 39 | + /// Function types. |
| 40 | + /// |
| 41 | + /// Also known as: pi type, dependent product type. |
| 42 | + FunctionType(Option<String>, Box<Configuration>, Box<Configuration>), |
| 43 | + /// Function terms. |
| 44 | + /// |
| 45 | + /// Also known as: lambda abstraction, anonymous function. |
| 46 | + FunctionTerm(String, Box<Configuration>), |
| 47 | + |
| 48 | + /// Record types. |
| 49 | + RecordType(Vec<(String, Box<Configuration>)>), |
| 50 | + /// Record terms. |
| 51 | + RecordTerm(Vec<(String, Box<Value>)>), |
| 52 | + |
| 53 | + /// Constants. |
| 54 | + Constant(Constant), |
| 55 | + |
| 56 | + /// Error sentinel. |
| 57 | + Error, |
| 58 | +} |
| 59 | + |
| 60 | +/// Computations eliminate values. |
| 61 | +pub enum Computation { |
| 62 | + /// Values. |
| 63 | + Value(Box<Value>), |
| 64 | + /// Function eliminations. |
| 65 | + /// |
| 66 | + /// Also known as: function application. |
| 67 | + FunctionElim(Box<Value>, Box<Value>), |
| 68 | + /// Record eliminations. |
| 69 | + /// |
| 70 | + /// Also known as: record projection, field lookup. |
| 71 | + RecordElim(Box<Value>, String), |
| 72 | +} |
| 73 | + |
| 74 | +/// Programs that are ready to be executed. |
| 75 | +pub struct Configuration { |
| 76 | + /// A list of computations to be used when we execute this program. |
| 77 | + pub bindings: Vec<Computation>, |
| 78 | + /// The final output of the program. |
| 79 | + pub output: Computation, |
| 80 | +} |
0 commit comments