• Stars
    star
    923
  • Rank 49,492 (Top 1.0 %)
  • Language
    Rust
  • License
    Mozilla Public Li...
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A statically-typed functional language with generics, typeclasses, sum types, pattern-matching, first-class functions, currying, algebraic effects, associated types, good diagnostics, etc.

Tao

You can now test Tao in the browser!

A statically-typed functional language with polymorphism, typeclasses, algebraic effects, sum types, pattern-matching, first-class functions, currying, good diagnostics, and much more!

Demo of Tao's features

For more example programs, see...

Goals

Right now, Tao is a hobby project and I have no plans to turn it into a production-worthy language. This may change as the project evolves, but I'd rather spend as much time experimenting with new language features for now. That said, I do have a few goals for the language itself:

  • Totality

    • All programs must explicitly handle all inputs. There are no mechanisms for panicking, exceptions, etc. The goal is to build a type system that's expressive enough to prove the totality of a wide range of programs.
    • In time, I'd like to see the language develop support for termination analysis techniques like Walther recursion.
  • Extreme optimisation

    • A rather dogged and obnoxious opinion of mine is that the 'optimisation ceiling' for statically-typed, total functional programming languages is significantly higher than traditional imperative languages with comparably weak type systems. I want Tao to be a practical example of this that I can point to rather than deploying nebulous talking points about invariants.
    • I've deliberately made sure that the core MIR of Tao has a very small surface area, making it amenable to a variety of optimisations and static analyses.
  • Learning

    • I have only a high-school knowledge of mathematics. I want to use Tao as a test bench to help me learn more about mathematics, proofs, type systems, logic, and computation.
    • In addition, I hope that Tao can serve as a useful tool for others looking to get into language design, compiler development, or simply functional programming in general.

Features

  • Hindley-Milner type inference
  • Useful error messages
  • Algebraic data types
    • Sum types
    • Record types
    • Generic data types
    • Nominal aliases (i.e: data Metres = Real)
  • Type aliases
  • Type polymorphism via generics
    • Class constraints
    • Associated type equality constraints
    • Arbitrary where clauses (including associated type equality)
    • Lazy associated item inference (Foo.Bar.Baz.Biz lazily infers the class at each step!)
    • Type checker is Turing-complete (is this a feature? Probably not...)
  • Pattern matching
    • Destructuring and binding
    • ADT patterns
    • List patterns ([a, b, c], [a, b .. c], etc.)
    • Arithmetic patterns (i.e: n + k)
    • Inhabitance checks (i.e: None exhaustively covers Maybe Never)
    • Recursive exhaustivity checks
    • let does pattern matching
  • First-class functions
    • Functions support pattern-matching
    • Currying
  • Typeclasses
    • Type parameters
    • Associated types
    • Operators are implemented as typeclasses
  • Monadic IO (due for removal in favour of effect-based IO)
    • do notation
  • Algebraic effects
    • Effect objects (independent of functions, unlike some languages)
    • Basin and propagation syntax (equivalent to Haskell's do notation, or Rust's async/try blocks)
    • Generic effects
    • Polymorphic effects (no more try_x or async_x functions!)
    • Effect sets (i.e: can express values that have multiple side effects)
    • Effect aliases
    • Effect handlers (including stateful handlers, allowing expressing effect-driven IO in terms of monadic IO)
  • Built-in lists
    • Dedicated list construction syntax ([a, b, c], [a, b .. c, d], etc.)
  • Explicit tail call optimisation
  • MIR optimiser
    • Monomorphisation of generic code
    • Inlining
    • Const folding
    • Symbolic execution
    • Dead code removal
    • Exhaustive pattern flattening
    • Unused function pruning
  • Bytecode compiler
  • Bytecode virtual machine

Current working on

  • Pattern exhaustivity checking (sound, but unnecessarily conservative)
  • Arithmetic patterns (only nat addition is currently implemented)
  • Typeclasses
    • Coherence checker
    • Visible member semantics to relax orphan rules
  • MIR optimiser
    • Unboxing
    • Automatic repr changes for recursive types
      • Transform data Nat = Succ Nat | Zero into a runtime integer
      • Transform data List A = Cons (A, List A) | Nil into a vector
  • Algebraic effects
    • Polymorphic effects
    • Higher-ranked effects (needed for async, etc.)
    • Arbitrary resuming/suspending of effect objects
    • Full monomorphisation of effect objects

Planned features

  • Better syntax
  • Module system (instead of import copy/paste)
  • LLVM/Cranelift backend

Interesting features

Here follows a selection of features that are either unique to Tao or are uncommon among other languages.

Arithmetic patterns

Tao's type system is intended to be completely sound (i.e: impossible to trigger runtime errors beyond 'implementation' factors such as OOM, stack overflow, etc.). For this reason, subtraction of natural numbers yields a signed integer, not a natural number. However, many algorithms still require that numbers be counted down to zero!

To solve this problem, Tao has support for performing arithmetic operations within patterns, binding the result. Because the compiler intuitively understands these operations, it's possible to statically determine the soundness of such operations and guarantee that no runtime errors or overflows can ever occur. Check out this 100% sound factorial program!

fn factorial =
    | 0 => 1
    \ y ~ x + 1 => y * factorial(x)

All functions are lambdas and permit pattern matching

Excluding syntax sugar (like type aliases), Tao has only two high-level constructs: values and types. Every 'function' is actually just a value that corresponds to an line lambda, and the inline lambda syntax naturally generalises to allow pattern matching. Multiple pattern arguments are permitted, each corresponding to a parameter of the function.

def five =
    let identity = fn x => x in
    identity(5)

Exhaustive pattern matching

Tao requires that pattern matching is exhaustive and will produce errors if patterns are not handled.

Very few delimiters, but whitespace isn't semantic

In Tao, every value is an expression. Even let, usually a statement in most languages, is an expression. Tao requires no semicolons and no code blocks because of this fact.

Currying and prefix calling

In Tao, arg->f is shorthand for f(arg) (function application). Additionally, this prefix syntax can be chained, resulting in very natural, first-class pipeline syntax.

my_list
    -> filter(fn x => x % 2 == 0) # Include only even elements
    -> map(fn x => x * x)         # Square elements
    -> sum                        # Sum elements

Useful, user-friendly error diagnostics

This one is better demonstrated with an image.

Example Tao error

Tao preserves useful information about the input code such as the span of each element, allowing for rich error messages that guide users towards solutions to their programs. Diagnostic rendering itself is done by my crate Ariadne.

Automatic call graph generation.

Tao's compiler can also automatically generate graphviz call graphs of your programs to help you understand them better. Here's the expression parser + REPL from examples/calc.tao. The call graph will automatically ignore utility functions (i.e: functions with a $[util] attribute on them), meaning that even very complex programs suddenly become understandable.

Call graph of an expression parser in Tao

Commands

Compile/run a .tao file

cargo run -- <FILE>

Run compiler tests

cargo test

Compile/run the standard library

cargo run -- lib/std.tao

Compiler arguments

  • --opt: Specify an optimisation mode (none, fast, size)

  • --debug: Enable debugging output for a compilation stage (tokens, ast, hir, mir, bytecode)

More Repositories

1

chumsky

Write expressive, high-performance parsers with ease.
Rust
3,334
star
2

flume

A safe and fast multi-producer, multi-consumer channel.
Rust
1,820
star
3

ariadne

A fancy diagnostics & error reporting crate
Rust
1,309
star
4

pollster

A minimal async executor that lets you block on a future
Rust
288
star
5

broom

An ergonomic tracing garbage collector that supports mark 'n sweep garbage collection
Rust
243
star
6

euc

A software rendering crate that lets you write shaders with Rust
Rust
241
star
7

forge

A lightweight, elegant scripting language with built-in Rust-FFI.
Rust
161
star
8

atto

An insanely simple self-hosted functional programming language
Rust
141
star
9

parze

A clean, efficient parser combinator
Rust
123
star
10

teloren

A command-line frontend for Veloren
Rust
90
star
11

funkicrab

Optimising Brainfuck compiler: Run your beloved Brainfuck code, but faster.
Rust
64
star
12

openmw-volumetric-clouds

A volumetric clouds mod for OpenMW
64
star
13

openmw-shaders

Photorealistic shaders for Morrowind
GLSL
59
star
14

vulcan

A minimalistic text editor designed for both ordinary use and software development
Vala
45
star
15

lagoon

A thread pool crate with an array of features
Rust
36
star
16

mutation

Unleash the power of nightly Rust to write code that's generic over mutation!
Rust
23
star
17

coord-rs

[deprecated] A simple, ergonomic vector mathematics crate for Rust
Rust
22
star
18

errant

A (mostly) drop-in replacement for Rust's Result that provides backtrace support.
Rust
22
star
19

leon

A lightweight scripting language for Rust
Rust
19
star
20

zte

Zesterer's Text Editor
Rust
18
star
21

tupai

A modular POSIX-like operating system created for educational purposes
C++
16
star
22

gui

An experimental stateful, structured, declarative GUI crate
Rust
12
star
23

the-bitwise-challenge

Challenge: Can you develop a game with only 8 bytes of state?
9
star
24

vast-outdated

As The Name Suggests: A Pretty Large Space Sim
C++
8
star
25

vm-perf

Performance comparisons between various virtual interpreter implementation strategies
Rust
8
star
26

gba-test

Software rasterisation on the GBA in Rust. Some experiments from a while ago.
Rust
7
star
27

thoth

A modular, x86_64 micro-kernel operating system
C
6
star
28

alonzo

A pure Rust functional compiler backend
Rust
6
star
29

que

An experimental lock-free queue
Rust
6
star
30

cargo-veloren

Name-squatting, for the moment
Rust
5
star
31

fula

A functional programming language with Hindley-Milner type inference
Rust
5
star
32

babble

A (horrendously hackish) clean room reimplementation of the Library of Babel, originally at https://libraryofbabel.info (seriously, check it out)
Python
5
star
33

synco

An experimental ECS crate that makes use of GATs
Rust
5
star
34

fuckvm

A highly experimental Brainfuck-targetting LLVM-like compiler backend
Rust
4
star
35

smash

Yet another blazingly fast hashmap written in Rust
Rust
4
star
36

emul8

Yet another CHIP-8 emulator written in Rust
Rust
4
star
37

bitwise-examples

Example games that persist just 8 bytes of state between frames
Rust
4
star
38

browser

Vala
4
star
39

nilts-old

A game about many things. I don't know what, since most content is randomly generated.
C
3
star
40

oms

[WIP] Orbital mechanics simulation tool/library
Rust
3
star
41

hire-me

Hire me! Here's why...
3
star
42

turk

A generic minmax algorithm that may be used as an AI player for 2-player games
Rust
3
star
43

libvolume

A voxel engine library used primarily in my other projects
C++
3
star
44

wavefront

A Wavefront OBJ parser and utility crate
Rust
3
star
45

voxeltest

A test voxel engine program
C++
3
star
46

emul8or

A CHIP-8 emulator written using Vala and SDL
Vala
3
star
47

sdf-test

An experiment in Signed Distance Field (SDF) raytracing and raymarching
C++
3
star
48

ir

An experimental language intermediate representation
Rust
2
star
49

yurt

A highly experiment portable runtime
Rust
2
star
50

parze-new

Rust
2
star
51

nilts

Work in progress which will hopefully one day be good
C++
2
star
52

picos

Raspberry Pi Card Operating System
C
2
star
53

async-priority-queue

An async-aware priority queue
Rust
2
star
54

spurv

A free, open-source CPU and instruction set specification with a minimalist design
2
star
55

jsbarretto

A personal website
HTML
2
star
56

opplyse

A clean, efficient GTK3 text editor for programmers. The big brother of Vulcan.
Vala
2
star
57

nilts-oldish

The procedurally generated game
C++
2
star
58

super-block

A platforming game written for the CHIP-8
1
star
59

forge-demo

Run Forge code online!
JavaScript
1
star
60

cragmoor

A text-based ASCII RPG procedurally generated game inspired by Dwarf Fortress
C++
1
star
61

snakes-on-a-continuous-plane

A 2D Continuous Snakes Game Created For Ludum Dare 34
CMake
1
star
62

timber

I got bored one afternoon and started writing a desktop panel
Vala
1
star
63

vast-old

Vast is a space sim written in C++ using OpenGL
C++
1
star
64

pokerom

A GameBoy Color (GBC) emulator written in C++ with SDL 2
CMake
1
star