All Projects → zesterer → tao

zesterer / tao

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

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to tao

functional-structures-refactoring-kata
Starting code and proposed solution for Functional Structures Refactoring Kata
Stars: ✭ 31 (-96.34%)
Mutual labels:  functional
Fae
A functional module for Deno inspired from Ramda.
Stars: ✭ 44 (-94.81%)
Mutual labels:  functional
when-switch
JavaScript functional implementation of switch/case
Stars: ✭ 20 (-97.64%)
Mutual labels:  functional
SeLite
Automated database-enabled navigation ✔️ of web applications
Stars: ✭ 34 (-95.99%)
Mutual labels:  functional
java-modern-tech-practice
😎 Java™ modern tech practice sandbox ⏳
Stars: ✭ 43 (-94.92%)
Mutual labels:  functional
fast-cartesian
Fast cartesian product
Stars: ✭ 51 (-93.98%)
Mutual labels:  functional
Pareto.js
An extremely small, intuitive and fast functional utility library for JavaScript
Stars: ✭ 254 (-70.01%)
Mutual labels:  functional
ObservableComputations
Cross-platform .NET library for computations whose arguments and results are objects that implement INotifyPropertyChanged and INotifyCollectionChanged (ObservableCollection) interfaces.
Stars: ✭ 94 (-88.9%)
Mutual labels:  functional
lambda-zero
A minimalist pure lazy functional programming language
Stars: ✭ 65 (-92.33%)
Mutual labels:  functional
swift-declarative-configuration
Declarative configuration for your objects
Stars: ✭ 46 (-94.57%)
Mutual labels:  functional
fnts
λ Minimal Functional Programming Utilities for TypeScript & JavaScript
Stars: ✭ 75 (-91.15%)
Mutual labels:  functional
BuBBLE
A DSL/LISP dialect written in Haskell
Stars: ✭ 20 (-97.64%)
Mutual labels:  functional
pythonic
Python like utility functions for JavaScript: range, enumerate, zip and items.
Stars: ✭ 28 (-96.69%)
Mutual labels:  functional
pipe
Functional Pipeline in Go
Stars: ✭ 30 (-96.46%)
Mutual labels:  functional
js-data-structures
🌿 Data structures for JavaScript
Stars: ✭ 56 (-93.39%)
Mutual labels:  functional
transmute
kind of like lodash but works with Immutable
Stars: ✭ 35 (-95.87%)
Mutual labels:  functional
kotlin-coroutines-jdbc
A library for interacting with blocking JDBC drivers using Kotlin Coroutines.
Stars: ✭ 40 (-95.28%)
Mutual labels:  functional
frontend-clean-architecture
React + TypeScript app built using the clean architecture principles in a more functional way · 🧼 🏛 🍪
Stars: ✭ 1,816 (+114.4%)
Mutual labels:  functional
pocketlang
A lightweight, fast embeddable scripting language.
Stars: ✭ 1,412 (+66.71%)
Mutual labels:  functional
dart-more
More Dart — Literally.
Stars: ✭ 81 (-90.44%)
Mutual labels:  functional

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)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].