Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
lib
 
 
 
 
 
 
 
 
vm
 
 
 
 
 
 
 
 
 
 
 
 

Tao

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

Demo of Tao's features

Features

  • Hindley-Milner type inference
  • Useful error messages
  • Typeclasses
  • First-class functions
  • Currying
  • Sum types
  • Records
  • Type polymorphism (for both types and values)
  • Pattern matching
  • Built-in lists
  • Static dispatch
  • Monomorphisation
  • MIR optimiser
  • Bytecode compiler

Current working on

  • Pattern exhaustivity checking (sound, but unnecessarily conservative)
  • MIR optimiser (const folding, dead code removal, and unused binding removal implemented, waiting on inlining)
  • Arithmetic patterns (only nat addition is currently implemented)
  • Typeclasses (simple implementation done, no compile-time coherence checker, compiler panics on detection of incoherence during monomorphisation)

Planned features

  • Better syntax
  • Module system
  • Monadic IO (or an effect system?)
  • Do notation
  • LLVM/Cranelift backend

Why?

Tao is primarily a personal hobby project. I have no real aspirations for the language, and I plan to spend a lot of time changing the syntax and semantics as my ideas about language design evolve. If you find the language interesting, feel free to give it a try!

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!

def 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.

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)

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages