A next-gen functional language
Go to file
2022-12-13 09:06:18 -03:00
.github/workflows fix: changed to tids=1 in the type checker because snooze is causing some problems in HVM 2022-12-01 11:24:42 -03:00
crates fix: bug with ampersand operator 2022-12-13 09:06:18 -03:00
example Omit most parenthesis; arrow lambda syntax (x => y) 2022-08-05 05:03:25 -03:00
guide fix: change guide URLs 2022-11-29 13:57:46 -03:00
.gitignore Add conv_eval 2022-07-19 20:23:07 -03:00
Cargo.lock fix: problem with u60 term in rule side and added Nat syntax sugar 2022-12-05 09:27:09 -03:00
Cargo.toml style: added a lot of tests, benchmarks and fixed code style 2022-11-30 11:19:14 -03:00
CHANGELOG.md refactor: started to refactor the entire compiler inspired in rustc 2022-10-04 14:02:44 -03:00
FEATURES.md merge: with main 2022-11-30 13:44:20 -03:00
README.md fix: readme and added rust-toolchain 2022-12-01 11:33:54 -03:00
rust-toolchain fix: readme and added rust-toolchain 2022-12-01 11:33:54 -03:00
SYNTAX.md fix: Remove copy/paste leftover in syntax.md 2022-11-10 17:49:53 +01:00

Kind2

Kind2 is a functional programming language and proof assistant.

It is a complete rewrite of Kind1, based on HVM, a lazy, non-garbage-collected and massively parallel virtual machine. In our benchmarks, its type-checker outperforms every alternative proof assistant by a far margin, and its programs can offer exponential speedups over Haskell's GHC. Kind2 unleashes the inherent parallelism of the Lambda Calculus to become the ultimate programming language of the next century.

Welcome to the inevitable parallel, functional future of computers!

Examples

Pure functions are defined via equations, as in Haskell:

// Applies a function to every element of a list
map <a> <b> (list: List a) (f: a -> b) : List b
map a b Nil              f = Nil
map a b (Cons head tail) f = Cons (f head) (map tail f)

Side-effective programs are written via monads, resembling Rust and TypeScript:

// Prints the double of every number up to a limit
Main : IO (Result () String) {
  ask limit = IO.prompt "Enter limit:"
  for x in (List.range limit) {
    IO.print "{} * 2 = {}" x (Nat.double x)
  }
  return Ok ()
}

Theorems can be proved inductivelly, as in Agda and Idris:

// Black Friday Theorem. Proof that, for every Nat n: n * 2 / 2 == n.
black_friday_theorem (n: Nat) : Equal Nat (Nat.half (Nat.double n)) n
black_friday_theorem Nat.zero     = Equal.refl
black_friday_theorem (Nat.succ n) = Equal.apply (x => Nat.succ x) (black_friday_theorem n)

For more examples, check the Wikind.

Usage

First, install Rust first, then enter:

cargo install kind2

Warning:

New versions probably are not in cargo, so you can install the current version of kind2 by following these instructions:

  1. Install Rust Nightly Toolchain
  2. Clone the repository
  3. cargo install --path crates/kind-cli --force

Then, use any of the commands below:

Command Usage Note
Check kind2 check file.kind2 Checks all definitions.
Eval kind2 eval file.kind2 Runs using the type-checker's evaluator.
Run kind2 run file.kind2 Runs using HVM's evaluator, on Rust-mode.
To-HVM kind2 to-hvm file.kind2 Generates a .hvm file. Can then be compiled to C.
To-KDL kind2 to-kdl file.kind2 Generates a .kdl file. Can then be deployed to Kindelia.

Executables can be generated via HVM:

kind2 to-hvm file.kind2
hvm compile file.hvm
clang -O2 file.c -o file
./file