2022-07-14 05:19:47 +03:00
Kind2
=====
2022-07-19 04:47:18 +03:00
Kind2 is a pure functional, lazy, non-garbage-collected, general-purpose,
dependently typed programming language focusing on performance and usability. It
2022-07-23 19:20:42 +03:00
features a blazingly fast type-checker based on **optimal
[normalization-by-evaluation ](https://en.wikipedia.org/wiki/Normalisation_by_evaluation )**. It can also
2022-07-23 19:21:01 +03:00
compile programs to [HVM ](https://github.com/kindelia/hvm ) and [Kindelia ](https://github.com/kindelia/kindelia ),
2022-07-19 05:12:35 +03:00
and can be used to prove and verify mathematical theorems.
2022-07-19 04:47:18 +03:00
2022-07-23 20:56:54 +03:00
Examples
--------
2022-07-19 04:47:18 +03:00
2022-07-23 20:56:54 +03:00
Pure functions can be defined using an equational notation that resembles [Haskell ](https://www.haskell.org/ ):
2022-07-19 04:47:18 +03:00
2022-07-23 20:56:54 +03:00
```idris
2022-07-19 04:47:18 +03:00
List.map < a: Type > < b: Type > (x: (List a)) (f: (x: a) b) : (List b)
List.map a b (Nil t) f = (Nil b)
List.map a b (Cons t x xs) f = (Cons b (f x) (List.map xs f))
```
2022-07-23 20:56:54 +03:00
Mathematical theorems can be proved via inductive reasoning, as in [Idris ](https://www.idris-lang.org/ ) and [Agda ](https://wiki.portal.chalmers.se/agda/pmwiki.php ):
2022-07-19 04:47:18 +03:00
2022-07-23 20:56:54 +03:00
```idris
2022-07-19 04:47:18 +03:00
Nat.commutes (a: Nat) (b: Nat) : (Nat.add a b) == (Nat.add b a)
Nat.commutes Zero b = (Nat.comm.a b)
Nat.commutes (Succ a) b =
let e0 = (Equal.apply @x (Succ x) (Nat.commutes a b))
let e1 = (Equal.mirror (Nat.commutes.b b a))
(Equal.chain e0 e1)
```
2022-07-23 20:56:54 +03:00
Normal programs can be written in a monadic syntax that is inspired by [Rust ](https://www.rust-lang.org/ ) and [TypeScript ](https://www.typescriptlang.org/ ):
2022-07-14 05:19:47 +03:00
2022-07-23 20:56:54 +03:00
```idris
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 ())
}
2022-07-14 05:19:47 +03:00
```
2022-07-23 20:56:54 +03:00
For more examples, check the [Wikind ](https://github.com/kindelia/wikind ).
2022-07-14 05:19:47 +03:00
2022-07-23 20:56:54 +03:00
Installation
------------
2022-07-14 05:57:15 +03:00
2022-07-23 20:56:54 +03:00
Install [Rust ](https://www.rust-lang.org/tools/install ) first, then enter:
2022-07-19 04:47:18 +03:00
```
2022-07-23 20:56:54 +03:00
cargo install kind2
2022-07-19 04:47:18 +03:00
```
2022-07-23 20:56:54 +03:00
Enter `kind2` on the terminal to make sure it worked.
2022-07-19 04:47:18 +03:00
2022-07-23 20:56:54 +03:00
Usage
-----
2022-07-14 05:57:15 +03:00
2022-07-23 20:56:54 +03:00
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 ](https://github.com/kindelia/hvm ) file. Can then be compiled to C.
To-KDL | `kind2 to-kdl file.kind2` | Generates a [.kdl ](https://github.com/kindelia/kindelia ) file. Can then be deployed to Kindelia.
2022-07-19 04:47:18 +03:00
Benchmarks
----------
2022-07-23 19:23:32 +03:00
In preliminary [benchmarks ](/bench ), Kind2's type-checker has outperformed Agda, Idris by 90x to 900x, which is an expressive difference. That said, we only tested a few small programs, so there isn't enough data to draw a conclusion yet. We're working on a more extensive benchmark suite.