|
1 | | -# Saki-Lang |
| 1 | +# Introduction |
2 | 2 |
|
3 | 3 | !!! warning |
4 | | - This project is currently in active elaboration and development, with significant progress yet to be made before it is ready for use. |
| 4 | + Saki-lang is currently in a very early stage of design and development, with substantial work required before it reaches a mature state. The prototype interpreter and REPL are still under active development, and no working interpreters are currently available. |
| 5 | + |
| 6 | +Saki is a statically typed, pure functional programming language that integrates dependent types and certain object-oriented constructs, including function overloading and algebraic subtyping. Its design emphasizes simplicity, adopting a C-family syntax while employing a sophisticated type system rooted in Martin-Löf Type Theory. Saki introduces novel features, such as [contract universes](Terms/Contract%20Universe.md) and [superposition types](Definition/Function%20Overloading.md), positioning itself as an experimental platform for investigating advanced type system mechanics and program synthesis. Heavily influenced by [Pikelet](https://github.com/pikelet-lang/pikelet) and [MLsub](https://lptk.github.io/programming/2020/03/26/demystifying-mlsub.html), Saki aims to explore new frontiers in type theory and programming paradigms. |
5 | 7 |
|
6 | 8 | ## Practical Example: Red-Black Tree in Saki |
7 | 9 |
|
8 | 10 | ```scala |
9 | 11 | universe 'LessThan(A: 'Type) = contract { |
10 | | - require (<)(self, A: 'Type): Bool |
| 12 | + require (<)(self, A: 'Type): Bool |
11 | 13 | } |
12 | 14 |
|
13 | 15 | type Option(A: 'Type) = enum { |
14 | | - None |
15 | | - Some(A) |
| 16 | + None |
| 17 | + Some(A) |
16 | 18 | } |
17 | 19 |
|
18 | 20 | type Color = enum { |
19 | | - Red |
20 | | - Black |
| 21 | + Red |
| 22 | + Black |
21 | 23 | } |
22 | 24 |
|
23 | 25 | type Tree[A: 'LessThan(A)] = enum { |
24 | | - Leaf |
25 | | - Node(Color, A, Tree[A], Tree[A]) |
| 26 | + Leaf |
| 27 | + Node(Color, A, Tree[A], Tree[A]) |
26 | 28 | } |
27 | 29 |
|
28 | 30 | impl [A: 'LessThan(A)] Tree[A] { |
29 | | - def balance(self): Self = match self { |
30 | | - case Self::Node( |
31 | | - Color::Black, valueRight, |
32 | | - Self::Node( |
33 | | - Color::Red, valueTop, |
34 | | - Self::Node(Color::Red, valueLeft, leftLeft, leftRight), |
35 | | - rightLeft |
36 | | - ), rightRight |
37 | | - ) | Self::Node( |
38 | | - Color::Black, valueRight, |
39 | | - Self::Node( |
40 | | - Color::Red, valueLeft, |
41 | | - leftLeft, |
42 | | - Self::Node(Color::Red, valueTop, leftRight, rightLeft) |
43 | | - ), rightRight |
44 | | - ) | Self::Node( |
45 | | - Color::Black, valueLeft, |
46 | | - leftLeft, |
47 | | - Self::Node( |
48 | | - Color::Red, valueRight, |
49 | | - Self::Node(Color::Red, valueTop, leftRight, rightLeft), |
50 | | - rightRight |
51 | | - ), |
52 | | - ) | Self::Node( |
53 | | - Color::Black, valueLeft, |
54 | | - leftLeft, |
55 | | - Self::Node( |
56 | | - Color::Red, valueTop, |
57 | | - leftRight, |
58 | | - Self::Node(Color::Red, valueRight, rightLeft, rightRight), |
59 | | - ), |
60 | | - ) => Self::Node( |
61 | | - Color::Red, valueTop, |
62 | | - Self::Node(Color::Black, valueLeft, leftLeft, leftRight), |
63 | | - Self::Node(Color::Black, valueRight, rightLeft, rightRight), |
64 | | - ) |
65 | | - case node: Self => node |
66 | | - } |
| 31 | + def balance(self): Self = match self { |
| 32 | + case Self::Node( |
| 33 | + Color::Black, valueRight, |
| 34 | + Self::Node( |
| 35 | + Color::Red, valueTop, |
| 36 | + Self::Node(Color::Red, valueLeft, leftLeft, leftRight), |
| 37 | + rightLeft |
| 38 | + ), rightRight |
| 39 | + ) | Self::Node( |
| 40 | + Color::Black, valueRight, |
| 41 | + Self::Node( |
| 42 | + Color::Red, valueLeft, |
| 43 | + leftLeft, |
| 44 | + Self::Node(Color::Red, valueTop, leftRight, rightLeft) |
| 45 | + ), rightRight |
| 46 | + ) | Self::Node( |
| 47 | + Color::Black, valueLeft, |
| 48 | + leftLeft, |
| 49 | + Self::Node( |
| 50 | + Color::Red, valueRight, |
| 51 | + Self::Node(Color::Red, valueTop, leftRight, rightLeft), |
| 52 | + rightRight |
| 53 | + ), |
| 54 | + ) | Self::Node( |
| 55 | + Color::Black, valueLeft, |
| 56 | + leftLeft, |
| 57 | + Self::Node( |
| 58 | + Color::Red, valueTop, |
| 59 | + leftRight, |
| 60 | + Self::Node(Color::Red, valueRight, rightLeft, rightRight), |
| 61 | + ), |
| 62 | + ) => Self::Node( |
| 63 | + Color::Red, valueTop, |
| 64 | + Self::Node(Color::Black, valueLeft, leftLeft, leftRight), |
| 65 | + Self::Node(Color::Black, valueRight, rightLeft, rightRight), |
| 66 | + ) |
| 67 | + case node: Self => node |
| 68 | + } |
67 | 69 |
|
68 | | - def insert(self, newValue: A): Self = match self { |
69 | | - case Self::Leaf => Self::Node(Color::Red, newValue, Self::Leaf, Self::Leaf) |
70 | | - case Self::Node(color, value, left, right) => if newValue < value then { |
71 | | - Self::Node(color, value, left.insert(value), right) |
72 | | - } else if value < newValue then { |
73 | | - Self::Node(color, value, left, right.insert(value)) |
74 | | - } else { |
75 | | - Self::Node(color, newValue, left, right) |
76 | | - } |
| 70 | + def insert(self, newValue: A): Self = match self { |
| 71 | + case Self::Leaf => Self::Node(Color::Red, newValue, Self::Leaf, Self::Leaf) |
| 72 | + case Self::Node(color, value, left, right) => if newValue < value then { |
| 73 | + Self::Node(color, value, left.insert(value), right) |
| 74 | + } else if value < newValue then { |
| 75 | + Self::Node(color, value, left, right.insert(value)) |
| 76 | + } else { |
| 77 | + Self::Node(color, newValue, left, right) |
77 | 78 | } |
| 79 | + } |
78 | 80 |
|
79 | | - def find(self, value: A): Option(A) = match self { |
80 | | - case Self::Leaf => Option(A)::None |
81 | | - case Self::Node(color, value, left, right) => if newValue < value then { |
82 | | - left.find(value) |
83 | | - } else if value < newValue then { |
84 | | - right.find(value) |
85 | | - } else { |
86 | | - Option(A)::Some(value) |
87 | | - } |
| 81 | + def find(self, value: A): Option(A) = match self { |
| 82 | + case Self::Leaf => Option(A)::None |
| 83 | + case Self::Node(color, value, left, right) => if newValue < value then { |
| 84 | + left.find(value) |
| 85 | + } else if value < newValue then { |
| 86 | + right.find(value) |
| 87 | + } else { |
| 88 | + Option(A)::Some(value) |
88 | 89 | } |
| 90 | + } |
89 | 91 | } |
90 | 92 | ``` |
0 commit comments