Home

Awesome

Aith is a perfomant systems programming language with am empathises on type systems. As of now Aith is very early stages and very little is implemented. Link to typing rules.

<img src="https://raw.githubusercontent.com/Superstar64/aith/images/rules/internals.svg">
visualization of compiler internals
<img src="https://raw.githubusercontent.com/Superstar64/aith/images/rules/hierarchy.svg">
visualization of type system
<img src="https://raw.githubusercontent.com/Superstar64/aith/images/rules/pure.svg">
pure type system subset

Features

(todo: expand on all of these)

Levity Polymorphic System-F

In languages like in C++ or Rust, generics perform monomorphization. When a generic is used in these languages they will generate code for each instante of type they use.

Rather then do this, Aith uses levity polymorphism, which can be seen as a generalization of Java's type erasure generics. In Aith, a type's kind, which is the type of a type, determines how (and if) it will be represented at runtime.

First Class Inline Functions (staging)

Aith has first class inline functions, a unique (as far as I can tell) take on staging. In Aith, inline functions can take inline functions as argument and return inline functions, all of which is completely erased at runtime.

Inline functions that type check always generate valid code and inline functions are prevented from appearing at runtime though kind checking.

Linear / Unique Types

Aith supports linear types and unique types. These are types that limit how copying of variables. Linear types promise that a variable of a linear type will be used exactly once. Unique types promise that a variable of a unique type will has not been aliased.

Aith has linear types at the inline level with multiplicity in the arrow like Linear Haskell. Aith has necessarily unique types at the runtime level with multiplicity via kinds.

Effectful Regions

Aith has support for effectful regions, similar to Rust's lifetimes. Regions allow programs to reason about borrowing and scoping resources (like memory). Conceptually, an executing program has a stack of regions that it accessing at any given time (think stack frames). If a region is alive, then that region and all it's parent regions are valid.

In Aith, regions are effectful, meaning that all runtime expressions are attached to a region that they live in. These expressions can only access memory in their region or regions proven to be parents of said region.

Type Inference

Aith is built on top of Hindley Milner type inference, similiar to Haskell and OCaml. Hindley Milner is a rather fancy type inference scheme that allows the majority of a program to be without type annotations but still statically typed.

First Class Polymorpism (System-F)

Aith implements first class polymorphism at the meta level. This allows treating generic (inline) functions (or more specifically any generic term) as if they where first class. Generic inline functions can be passed to other inline functions and returned from them. As of now, first class polymorphism is only implmented at the meta level for inline functions and not for runtime functions.

As type inference for first class polymorphism is undeciable, some compromises must be made. Aith implements it's own variant of PolyML, which requires explicit boxing and unboxing and requires annotations for variables who's types are instancited.

Boolean Unification

Aith extends Hindley Milner with boolean unification. This allows certain types to contain boolean expressions (and only boolean expressions). Boolean unification is used by Aith to type check both regions and linear types.

Hindley Milner extended with boolean unification preserves it's nice properties such as principle types. This means that types that use booleans infer as nicely as types that don't. The main trade off is that now type checking now involves what is effectively a generalization of SAT solving.

Building and Running Tests

Install ghc, cabal and make. Run make to build aith, make tests to run the tests and make test.c to generate the test c source file.

Todo List

Syntax

Files are lists of declarations, where these declarations could be a plain variable declaration or a path declaration. For example f(x) { x } is a plain declaration and example/f(x) { x } is a path declaration.

Folders concatenates all it's contents where the folder name is prepend to all the declarations. A folder named abc prepends abc/ to all it's contents.

Declarations(code)

DescriptionSyntax
Inline Terminline x = e;
Inline Term Ascribeinline x : σ = e;
Functionx(pm, pm', ...) { e }
Function Ascribex(pm, pm', ...) : σ in π { e }
Function Ascribex(pm, pm', ...) :: σ { e }
Synonymtype x = σ;
New Type Declarationnewtype x : κ;

Terms(e)

DescriptionSyntax
Variablex
Variablex @_
Variablex @<σ, σ', ...>
Global Variable/x/x'/...
Inline Abstraction \pm -> e
Inline Applicatione {e'}
Inline Bindinginline pm = e; e'
Externextern [arity] "sym"
Function Applicatione (e', e'', ...)
Runtime Bindinglet pm = e; e'
Tuple Construction(e, e', ...)
Read Pointer*e
Write Pointer*e = (e')
Array Increment&e[e']
Array to Pointer&*e
Number Literaln
Additione + e'
Subtractione - e'
Multiplicatione * e'
Divsione / e'
Moduluse % e'
Equalitye == e'
Inequalitye != e'
Lesse < e'
Less or Equale <= e'
Greatere > e'
Greater or Equale >= e'
Integer Resizeresize e
Truetrue
Falsefalse
Switchswitch e { pm -> e; pm' -> e'; ... }
Poly Introductionς e
Poly Eliminatione @_
Poly Eliminatione @<σ, σ', ...>
Type Annotatione : σ
Pretype Annotatione :: σ
Continuecontinue e
Breakbreak e
Looploop (let pm = e) { e' }
Unsafe Castcast e

Terms (Syntax Sugar) (e)

DescriptionSyntaxMeaning
Not!eif e { false } else { true }
Ande & e'if e { e' } else { false }
Ore | e'if e { true } else { e' }
Doe; e'let () = e; e'
Ifif e { e' } else { e''}switch (e) { true -> e; false -> e'; }

Meta Patterns(pm)

DescriptionSyntax
Linear Variablex
Linear Variable Abscribex : σ
Unrestricted Variable Abscribex :* σ
Polymorphic Variable Abscribex :^τ σ

Runtime Patterns(pm)

DescriptionSyntax
Variablex
Variable Abscribex : σ
Tuple Destruction(pm, pm', ...)
Truetrue
Falsefalse

Scheme(ς)

DescriptionSyntax
TypeScheme<pmσ, pmσ', ...>

Types(σ, τ, π, κ, ρ)

DescriptionSyntax
Hole_
Variablex
Linear Inline Functionσ -> τ
Unrestricted Inline Functionσ -* τ
Polymorphic Inline Functionσ -π τ
Polyς σ
Function Pointerfunction(σ, σ', ...) -> τ uses π
Tuple(σ, σ', ...)
Effectσ in π
Uniqueunique σ
Sharedσ @ π
Pointerσ*
Arrayσ[]
Numberρ integer(ρ')
Booleanboolean
IO Regionio
Stepstep<σ, τ>
Meta Typemetatype
Typetype<σ, τ>
Boxedboxed
Capacitycapacity
Regionregion
Pointer Representationpointer
Struct Representationstruct (ρ, ρ', ...)
Union Representationunion (ρ, ρ', ...)
Word Representationρ word
Signedsigned
Unsignedunsigned
Byte Size8bit
Short Size16bit
Int Size32bit
Long Size64bit
Native Sizenative
Representationrepresentation
Signednesssignedness
Sizesize
Type Truetrue
Type Falsefalse
Type Andσ & τ
Type Orσ | τ
Type Not
Type Xorσ (+) τ

Types (Internal) (σ, τ, π, κ, ρ)

DescriptionSyntax
Unificationunification
Kindkind<σ>
Syntacticsyntactic
Propositionalpropositional
Top/|\
Function Literal Typefunction literal(σ) -> τ uses π
Labellabel
Ambiguous Labelambiguous

Types (Syntax Sugar) (σ, τ, π, κ, ρ)

DescriptionSyntaxMeaning
Bytebytesigned integer(8bit)
Shortshortsigned integer(16bit)
Intintsigned integer(32bit)
Longlongsigned integer(64bit)
PtrDiffptrdiffsigned integer(native)
UByteubyteunsigned integer(8bit)
UShortushortunsigned integer(16bit)
UIntuintunsigned integer(32bit)
ULongulongunsigned integer(64bit)
Integerinteger(σ)signed integer(σ)
Naturalnatural(σ)unsigned integer(σ)
Native Integerintegersigned integer(native)
Native Naturalnaturalunsigned integer(native)

Type Pattern(pmσ)

DescriptionSyntax
Variablex : κ
Concrete Variablex :* κ

C Compiler Requirements

This list may be incomplete.

Papers

Useful / Inspirational papers:

Implemented

Linear / Unique Types

Levity polymorphism

Compiler Design

Reduction

Unification

Type Inference (First Class Polymorphism)

PolyML is implemented, but with scope type variables are used rather then schematic ones.

Compiler Design

Regions

Inspirational, and / or Formerly Used

General Introductions

Pure Type Systems

Linear / Unique Types

Effect Tracking

Type Inference (First Class Polymorphism)

Type Inference (Subtyping)

Unification

Internals

Copyright

Copyright © Freddy A Cubas, "Superstar64"

Licensed under GPL3 only. See LICENSE for more info.