{"id":13607852,"url":"https://github.com/Superstar64/aith","last_synced_at":"2025-04-12T14:31:26.322Z","repository":{"id":28187882,"uuid":"31689654","full_name":"Superstar64/aith","owner":"Superstar64","description":"[Early Stages] Low level functional programming language with linear types, first class inline functions, levity polymorphism and regions.","archived":false,"fork":false,"pushed_at":"2024-02-02T04:08:42.000Z","size":1816,"stargazers_count":65,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-07T13:37:53.742Z","etag":null,"topics":["compiler","early-development","language"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Superstar64.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2015-03-05T01:36:50.000Z","updated_at":"2024-09-21T18:23:31.000Z","dependencies_parsed_at":"2023-12-25T02:20:14.080Z","dependency_job_id":"936690d8-f72d-4e4e-86b6-255d189e8234","html_url":"https://github.com/Superstar64/aith","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superstar64%2Faith","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superstar64%2Faith/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superstar64%2Faith/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superstar64%2Faith/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Superstar64","download_url":"https://codeload.github.com/Superstar64/aith/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248581154,"owners_count":21128111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","early-development","language"],"created_at":"2024-08-01T19:01:22.201Z","updated_at":"2025-04-12T14:31:25.813Z","avatar_url":"https://github.com/Superstar64.png","language":"Haskell","readme":"\nAith is a perfomant systems programming language with am empathises on type systems.\nAs of now Aith is very early stages and very little is implemented.\n[Link to typing rules](https://github.com/Superstar64/aith/blob/images/rules/rules.pdf).\n\n| \u003cimg src=\"https://raw.githubusercontent.com/Superstar64/aith/images/rules/internals.svg\"\u003e |\n| :--: |\n| visualization of compiler internals |\n\n| \u003cimg src=\"https://raw.githubusercontent.com/Superstar64/aith/images/rules/hierarchy.svg\"\u003e |\n| :--: |\n| visualization of type system |\n\n| \u003cimg src=\"https://raw.githubusercontent.com/Superstar64/aith/images/rules/pure.svg\"\u003e |\n| :--: |\n| pure type system subset |\n\n\n# Features\n\n(todo: expand on all of these)\n\n## Levity Polymorphic System-F\nIn languages like in C++ or Rust, generics perform monomorphization.\nWhen a generic is used in these languages they will generate code for each instante of type they use.\n\nRather then do this, Aith uses levity polymorphism, which can be seen as a generalization of Java's type erasure generics.\nIn Aith, a type's kind, which is the type of a type, determines how (and if) it will be represented at runtime.\n\n## First Class Inline Functions (staging)\nAith has first class inline functions, a unique (as far as I can tell) take on staging.\nIn Aith, inline functions can take inline functions as argument and return inline functions,\nall of which is completely erased at runtime.\n\nInline functions that type check always generate valid code\nand inline functions are prevented from appearing at runtime though kind checking.\n\n## Linear / Unique Types\nAith supports linear types and unique types.\nThese are types that limit how copying of variables.\nLinear types promise that a variable of a linear type will be used exactly once.\nUnique types promise that a variable of a unique type will has not been aliased.\n\nAith has linear types at the inline level with multiplicity in the arrow like Linear Haskell.\nAith has necessarily unique types at the runtime level with multiplicity via kinds.\n\n## Effectful Regions\nAith has support for effectful regions, similar to Rust's lifetimes.\nRegions allow programs to reason about borrowing and scoping resources (like memory).\nConceptually, an executing program has a stack of regions that it accessing at any given time (think stack frames).\nIf a region is alive, then that region and all it's parent regions are valid.\n\nIn Aith, regions are effectful, meaning that all runtime expressions are attached to a region that they live in.\nThese expressions can only access memory in their region or regions proven to be parents of said region. \n\n## Type Inference\nAith is built on top of Hindley Milner type inference, similiar to Haskell and OCaml.\nHindley Milner is a rather fancy type inference scheme that allows the majority of a program to be without type annotations but still statically typed.\n\n### First Class Polymorpism (System-F)\nAith implements first class polymorphism at the meta level.\nThis allows treating generic (inline) functions (or more specifically any generic term) as if they where first class.\nGeneric inline functions can be passed to other inline functions and returned from them.\nAs of now, first class polymorphism is only implmented at the meta level for inline functions and not for runtime functions.\n\nAs type inference for first class polymorphism is undeciable, some compromises must be made.\nAith implements it's own variant of PolyML, which requires explicit boxing and unboxing and requires annotations for variables who's types are instancited.\n\n### Boolean Unification\nAith extends Hindley Milner with boolean unification.\nThis allows certain types to contain boolean expressions (and only boolean expressions).\nBoolean unification is used by Aith to type check both regions and linear types.\n\nHindley Milner extended with boolean unification preserves it's nice properties such as principle types.\nThis means that types that use booleans infer as nicely as types that don't.\nThe main trade off is that now type checking now involves what is effectively a generalization of SAT solving.\n\n# Building and Running Tests\nInstall ghc, cabal and make.\nRun `make` to build aith, `make tests` to run the tests and `make test.c` to generate the test c source file.\n\n# Todo List\n\n* Proper Documentation\n* Algebraic data types\n* Newtypes\n* Add higher kinded types (System-F A)\n* Runtime level higher rank polymorphism\n* Simplify boolean types to DNF rather then ANF\n* Refactoring and syntax changes as usual\n\n# Syntax\n\nFiles 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.\n\nFolders 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.\n\n## Declarations(code)\n| Description | Syntax |\n|-|-|\n| Inline Term | `inline x = e;`|\n| Inline Term Ascribe | `inline x : σ = e;`|\n| Function | `x(pm, pm', ...) { e }` |\n| Function Ascribe | `x(pm, pm', ...) : σ in π { e }`|\n| Function Ascribe | `x(pm, pm', ...) :: σ { e }`|\n| Synonym | `type x = σ;` |\n| New Type Declaration | `newtype x : κ;` |\n\n## Terms(e)\n| Description | Syntax |\n|-|-|\n| Variable | `x` |\n| Variable | `x @_` |\n| Variable | `x @\u003cσ, σ', ...\u003e` |\n| Global Variable | `/x/x'/...` |\n| Inline Abstraction | ` \\pm -\u003e e` |\n| Inline Application | `e {e'}`|\n| Inline Binding | `inline pm = e; e'`|\n| Extern | `extern [arity] \"sym\"` |\n| Function Application | `e (e', e'', ...)`|\n| Runtime Binding | `let pm = e; e'` |\n| Tuple Construction | `(e, e', ...)` |\n| Read Pointer | `*e` |\n| Write Pointer | `*e = (e')` |\n| Array Increment | `\u0026e[e']` |\n| Array to Pointer | `\u0026*e` |\n| Number Literal | `n` |\n| Addition | `e + e'` |\n| Subtraction | `e - e'` |\n| Multiplication | `e * e'` |\n| Divsion | `e / e'` |\n| Modulus | `e % e'` |\n| Equality | `e == e'` |\n| Inequality | `e != e'` |\n| Less | `e \u003c e'` |\n| Less or Equal | `e \u003c= e'` |\n| Greater | `e \u003e e'` |\n| Greater or Equal | `e \u003e= e'` |\n| Integer Resize | `resize e` |\n| True | `true` |\n| False | `false` |\n| Switch | `switch e { pm -\u003e e; pm' -\u003e e'; ... }` |\n| Poly Introduction| `ς e` |\n| Poly Elimination | `e @_` |\n| Poly Elimination | `e @\u003cσ, σ', ...\u003e` |\n| Type Annotation | `e : σ` |\n| Pretype Annotation | `e :: σ` |\n| Continue | `continue e` |\n| Break | `break e` |\n| Loop | `loop (let pm = e) { e' }` |\n| Unsafe Cast | `cast e` |\n\n## Terms (Syntax Sugar) (e)\n| Description | Syntax | Meaning |\n| - | - | - |\n| Not | `!e` | `if e { false } else { true }` |\n| And | `e \u0026 e'` | `if e { e' } else { false }` |\n| Or | `e \\| e'` | `if e { true } else { e' }` |\n| Do | `e; e'` | `let () = e; e'` |\n| If | `if e { e' } else { e''}` | `switch (e) { true -\u003e e; false -\u003e e'; } ` | \n\n## Meta Patterns(pm)\n| Description | Syntax |\n|-|-|\n| Linear Variable | `x`|\n| Linear Variable Abscribe | `x : σ` |\n| Unrestricted Variable Abscribe | `x :* σ` |\n| Polymorphic Variable Abscribe | `x :^τ σ` |\n\n## Runtime Patterns(pm)\n| Description | Syntax |\n|-|-|\n| Variable | `x` |\n| Variable Abscribe | `x : σ` |\n| Tuple Destruction | `(pm, pm', ...)` |\n| True | `true` |\n| False | `false` |\n\n# Scheme(ς)\n| Description | Syntax |\n|-|-|\n| TypeScheme | `\u003cpmσ, pmσ', ...\u003e` |\n\n## Types(σ, τ, π, κ, ρ)\n| Description | Syntax |\n|-|-|\n| Hole | `_` |\n| Variable | `x` |\n| Linear Inline Function | `σ -\u003e τ`|\n| Unrestricted Inline Function | `σ -* τ` |\n| Polymorphic Inline Function | `σ -π τ ` |\n| Poly | `ς σ` |\n| Function Pointer | `function(σ, σ', ...) -\u003e τ uses π` |\n| Tuple | `(σ, σ', ...)` |\n| Effect | `σ in π` |\n| Unique | `unique σ` |\n| Shared | `σ @ π` |\n| Pointer | `σ*` |\n| Array | `σ[]` |\n| Number | `ρ integer(ρ')` |\n| Boolean | `boolean` |\n| IO Region | `io` |\n| Step | `step\u003cσ, τ\u003e` |\n| Meta Type | `metatype` |\n| Type | `type\u003cσ, τ\u003e` |\n| Boxed | `boxed` |\n| Capacity | `capacity` |\n| Region | `region` |\n| Pointer Representation | `pointer` |\n| Struct Representation | `struct (ρ, ρ', ...)` |\n| Union Representation | `union (ρ, ρ', ...)` |\n| Word Representation | `ρ word` |\n| Signed | `signed` |\n| Unsigned | `unsigned` |\n| Byte Size | `8bit`|\n| Short Size | `16bit`|\n| Int Size | `32bit` |\n| Long Size | `64bit` |\n| Native Size | `native` |\n| Representation | `representation` |\n| Signedness | `signedness` |\n| Size | `size` |\n| Type True | `true` |\n| Type False | `false` |\n| Type And | `σ \u0026 τ` |\n| Type Or | `σ \\| τ` |\n| Type Not | `!σ` |\n| Type Xor | `σ (+) τ` |\n\n# Types (Internal) (σ, τ, π, κ, ρ)\n| Description | Syntax |\n| - | - |\n| Unification | `unification` |\n| Kind | `kind\u003cσ\u003e` |\n| Syntactic |`syntactic` |\n| Propositional |`propositional` |\n| Top | `/\\|\\` |\n| Function Literal Type | `function literal(σ) -\u003e τ uses π` |\n| Label | `label` |\n| Ambiguous Label | `ambiguous` |\n\n# Types (Syntax Sugar) (σ, τ, π, κ, ρ)\n| Description | Syntax | Meaning |\n|-|-|-|\n| Byte | `byte` | `signed integer(8bit)` |\n| Short | `short` | `signed integer(16bit)` |\n| Int | `int` | `signed integer(32bit)` |\n| Long | `long` | `signed integer(64bit)` |\n| PtrDiff | `ptrdiff` | `signed integer(native)` |\n| UByte | `ubyte` | `unsigned integer(8bit)` |\n| UShort | `ushort` | `unsigned integer(16bit)` |\n| UInt | `uint` | `unsigned integer(32bit)` |\n| ULong | `ulong` | `unsigned integer(64bit)` |\n| Integer | `integer(σ)` | `signed integer(σ)` |\n| Natural | `natural(σ)` | `unsigned integer(σ)` |\n| Native Integer | `integer` | `signed integer(native)` |\n| Native Natural | `natural` | `unsigned integer(native)` |\n\n\n\n## Type Pattern(pmσ)\n| Description | Syntax |\n|-|-|\n| Variable | `x : κ` |\n| Concrete Variable | `x :* κ` |\n\n\n# C Compiler Requirements\nThis list may be incomplete.\n* All pointers must have the same representation (including function pointers).\n* Signed integers must have 2's complement wrapping. (`-fwrapv` on gcc)\n\n# Papers\nUseful / Inspirational papers:\n\n## Implemented\n\n### Linear / Unique Types\n* [Linear Haskell](https://arxiv.org/pdf/1710.09756.pdf) [(video)](https://youtu.be/t0mhvd3-60Y)\n  * Implemented for inline functions\n### Levity polymorphism\n* [Levity Polymorphism](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/11/levity-pldi17.pdf) [(video)](https://youtu.be/lSJwXZ7vWBw)\n  * Implemented with more restrictive representation lambda.\n### Compiler Design\n* [Invertible Syntax Descriptions: Unifying Parsing and Pretty Printing](https://www.mathematik.uni-marburg.de/~rendel/rendel10invertible.pdf)\n  * Implemented with prisms instead of partial isomorphisms.\n### Reduction\n* [Demonstrating Lambda Calculus Reduction](https://www.cs.cornell.edu/courses/cs6110/2014sp/Handouts/Sestoft.pdf)\n  * Applicative order reduction used for inline function reduction.\n### Unification\n* [Unification Theory](https://www.cs.bu.edu/fac/snyder/publications/UnifChapter.pdf)\n  * Reference for unification and E-unification\n* [Embedding Boolean Expressions into Logic Programming](https://core.ac.uk/download/pdf/82206645.pdf)\n\n### Type Inference (First Class Polymorphism)\nPolyML is implemented, but with scope type variables are used rather then schematic ones.\n* [Semi-Explicit First-Class Polymorphism for ML](https://caml.inria.fr/pub/papers/garrigue_remy-poly-ic99.pdf)\n### Compiler Design\n* [How OCaml type checker works -- or what polymorphism and garbage collection have in common](https://okmij.org/ftp/ML/generalization.html)\n  * Only implemented for checking escaping skolem variables. Still need to implement let generalization.\n### Regions\n* \n  * [Monadic and Substructural Type Systems for Region-Based Memory Management](https://www.cs.rit.edu/~mtf/research/thesis/fluet-thesis.single.pdf)\n    * General guide for regions.\n  * [Monadic Regions](https://www.cs.cornell.edu/people/fluet/research/rgn-monad/JFP06/jfp06.pdf)\n  * [A Step-Indexed Model of Substructural State](https://www.cs.cornell.edu/people/fluet/research/substruct-state/ICFP05/icfp05.pdf)\n  * [Linear Regions Are All You Need](https://www.cs.cornell.edu/people/fluet/research/substruct-regions/ESOP06/esop06.pdf)\n\n## Inspirational, and / or Formerly Used\n\n### General Introductions\n* [Practical Foundations for Programming Languages](https://profs.sci.univr.it/~merro/files/harper.pdf)\n* [Type Systems](http://lucacardelli.name/Papers/TypeSystems.pdf)\n### Pure Type Systems\n* [An Introduction to Generalized Type Systems](https://www.researchgate.net/profile/Henk-hendrik-Barendregt/publication/216300104_An_Introduction_to_Generalized_Type_Systems/links/584c326d08aeb989251f7565/An-Introduction-to-Generalized-Type-Systems.pdf)\n* [The Structural Theory of Pure Type Systems](https://www.andrew.cmu.edu/user//fpv/papers/struct_pts.pdf) [(video)](https://youtu.be/8zuTuE9f9Jg)\n### Linear / Unique Types\n*\n  * [Making Uniqueness Typing Less Unique](http://edsko.net/pubs/thesis.pdf)\n  * [Uniqueness Typing Redefined](http://www.edsko.net/pubs/ifl06-paper.pdf)\n  * [Equality-Based Uniqueness Typing](http://www.edsko.net/pubs/tfp07-paper.pdf)\n  * [Uniqueness Typing Simplified](http://www.edsko.net/pubs/ifl07-paper.pdf)\n  * [Modelling Unique and Affine Typing using Polymorphism](http://www.edsko.net/pubs/modelling-unique-and-affine.pdf)\n* [A taste of linear logic](https://homepages.inf.ed.ac.uk/wadler/papers/lineartaste/lineartaste-revised.pdf)\n* [Linearity and Uniqueness: An Entente Cordiale](https://granule-project.github.io/papers/esop22-paper.pdf)\n* [The Best of Both Worlds: Linear Functional Programming without Compromise](https://jgbm.github.io/pubs/morris-icfp2016-linearity-extended.pdf) [(video)](https://youtu.be/ij9DbNTr-B8)\n### Effect Tracking\n * [Polymorphic Types and Effects with Boolean Unification](https://flix.dev/paper/oopsla2020b.pdf)\n### Type Inference (First Class Polymorphism)\n*\n  * [HMF: Simple type inference for first-class polymorphism](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/tr-2007-118.pdf)\n  * [Flexible types: robust type inference for first-class polymorphism](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/tr-2008-55.pdf)\n* [FreezeML : Complete and Easy Type Inference for First-Class Polymorphism](https://export.arxiv.org/pdf/2004.00396) [(video)](https://youtu.be/bZKC3o4jsek)\n* [A Quick Look at Impredicativity](https://www.microsoft.com/en-us/research/uploads/prod/2020/01/quick-look-icfp20.pdf) [(video)](https://youtu.be/ZuNMo136QqI)\n* [QML : Explicit First-Class Polymorphism for ML](https://www.microsoft.com/en-us/research/wp-content/uploads/2009/09/QML-Explicit-First-Class-Polymorphism-for-ML.pdf)\n### Type Inference (Subtyping)\n*\n  * [Algebraic Subtyping](https://www.cs.tufts.edu/~nr/cs257/archive/stephen-dolan/thesis.pdf)\n  * [Polymorphism, Subtyping, and Type Inference in MLsub](https://www.repository.cam.ac.uk/bitstream/handle/1810/261583/Dolan_and_Mycrof-2017-POPL-AM.pdf) [(video)](https://youtu.be/-P1ks4NPIyk)\n* [The Simple Essence of Algebraic Subtyping](https://dl.acm.org/doi/pdf/10.1145/3409006) [(video)](https://youtu.be/d10q-b8jNKg)\n### Unification\n* [Unification Under a Mixed Prefix](https://www.lix.polytechnique.fr/~dale/papers/jsc92.pdf)\n### Internals\n* [System F with Type Equality Coercions](https://www.microsoft.com/en-us/research/wp-content/uploads/2007/01/tldi22-sulzmann-with-appendix.pdf)\n* [Generalizing Hindley-Milner Type Inference Algorithms](https://www.cs.uu.nl/research/techreps/repo/CS-2002/2002-031.pdf)\n\n\n# Copyright\nCopyright © Freddy A Cubas, \"Superstar64\"\n\nLicensed under GPL3 only. See LICENSE for more info.\n","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSuperstar64%2Faith","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSuperstar64%2Faith","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSuperstar64%2Faith/lists"}