Kind/README.md

108 lines
2.5 KiB
Markdown
Raw Permalink Normal View History

2024-03-14 22:46:00 +03:00
# Kind2: a parallel proof & programming language
2024-02-08 19:51:51 +03:00
2024-05-15 22:57:01 +03:00
> NOTE: THIS REPOSITORY IS A WIP. OFFICIAL RELEASE COMING SOON!
2024-03-14 22:46:00 +03:00
Kind2 is a general-purpose programming language made from scratch to harness
[HVM](https://github.com/HigherOrderCO/HVM)'s **massive parallelism** and
computational advantages (no garbage collection, optimal β-reduction). Its type
system is a minimal core based on the Calculus of Constructions, making it
2024-03-16 05:38:31 +03:00
inherently secure. Essentially, Kind2 aims to be:
2024-02-09 02:04:56 +03:00
2024-03-14 22:46:00 +03:00
- As *friendly* as **Python**
2024-02-09 02:04:56 +03:00
2024-03-14 22:46:00 +03:00
- As *efficient* as **Rust**
2024-02-09 02:04:56 +03:00
2024-03-14 22:46:00 +03:00
- As *high-level* as **Haskell**
2024-02-09 02:04:56 +03:00
2024-03-14 22:46:00 +03:00
- As *parallel* as **CUDA**
2024-02-09 02:04:56 +03:00
2024-03-14 22:46:00 +03:00
- As *formal* as **Lean**
And it seeks to accomplish that goal by relying on the solid foundations of [Interaction Combinators](https://www.semanticscholar.org/paper/Interaction-Combinators-Lafont/6cfe09aa6e5da6ce98077b7a048cb1badd78cc76).
2024-05-15 22:57:01 +03:00
2024-03-16 05:38:02 +03:00
2024-03-14 22:46:00 +03:00
## Usage
1. Install [Rust](https://www.rust-lang.org/) and (optionally) [Haskell](https://www.haskell.org/) in your system.
2. Clone this repository and install it:
```
git clone https://github.com/HigherOrderCO/Kind2
cargo install --path .
```
3. Type-check a Kind2 definition:
```
kind2 check name_here
```
4. Test it with the interpreter:
```
kind2 run name
```
5. Compile and run in parallel, powered by HVM!
```
kind2 compile name
./name
```
## Syntax
Kind2's syntax aims to be as friendly as Python's, while still exposing the
high-level functional idioms that result in fast, parallel HVM binaries.
Function application (`(f x y z ...)`) follows a Lisp-like style and
pattern-matching `(match x { ctr: .. })` feels like Haskell; but control-flow is
more Python-like. In short, it can be seen as *"Haskell inside, Python
outside"*: a friendly syntax on top of a powerful functional core.
### Functions:
```javascript
// The Fibonacci function
fib (n: U60) : U60 =
switch n {
0: 0
1: 1
_: (+ (fib (- n 1)) (fib (- n 2)))
}
```
### Datatypes (ADTs):
```javascript
// Polymorphic Lists
data List T
| cons (head: T) (tail: (List T))
| nil
// Applies a function to all elements of a list
2024-03-16 04:07:01 +03:00
map <A> <B> (xs: (List A)) (f: A -> B) : (List B) =
fold xs {
++: (f xs.head) ++ xs.tail
[]: []
2024-03-14 22:46:00 +03:00
}
```
### Theorems and Proofs:
```javascript
2024-03-16 04:07:01 +03:00
use Nat/{succ,zero,half,double}
2024-03-14 22:46:00 +03:00
// Proof that `∀n. n*2/2 = n`
2024-03-16 04:07:01 +03:00
bft (n: Nat) : (half (double n)) == n =
2024-03-14 22:46:00 +03:00
match n {
2024-03-16 04:07:01 +03:00
succ: (Equal/apply succ (bft n.pred))
2024-03-14 22:46:00 +03:00
zero: {=}
}
```
### More Examples:
There are countless examples on the [`Book/`](book) directory. Check it!