@fraczak/k 3.0.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/INTRO.md DELETED
@@ -1,88 +0,0 @@
1
- ### Introduction to Kernel/Core
2
-
3
- **Kernel/Core** is a minimal, gradually typed, first-order functional programming language designed for defining and transforming data using partial functions. It is built on the foundation of Algebraic Data Types (ADTs), specifically tagged unions and products.
4
-
5
- #### Core Concepts
6
-
7
- 1. **Statements**:
8
- - The program consists of a possibly empty list of statements, each ending with a semicolon (`;`), followed by an expression.
9
- - There are two types of statements:
10
- - **Code Definitions**: Define data types and start with a dollar sign (`$`).
11
- - **Relation Definitions**: Define partial functions (transformations) of data.
12
-
13
- 2. **Codes**:
14
- - Codes represent data types and can be either unions (`<...>`) or products (`{...}`).
15
- - Example:
16
- ```kernelcore
17
- $ bool = <{} true, {} false>;
18
- $ pair_of_bools = {bool x, bool y};
19
- ```
20
-
21
- 3. **Relations**:
22
- - Relations are partial functions defined to transform data from one type to another.
23
- - Example:
24
- ```kernelcore
25
- is_x_true = $pair_of_bools (.x .true);
26
- ```
27
-
28
- 4. **Composition of Partial Functions**:
29
- - **Sequential (Functional) Composition**: Sequential application of partial functions.
30
- ```kernelcore
31
- (.x .true)
32
- ```
33
- - **Parallel (Product) Composition**: Combine multiple partial functions to construct a new product type.
34
- ```kernelcore
35
- {.x x_value, .y y_value}
36
- ```
37
- - **Concurrent (Union) Composition**: Try different functions in sequence, returning the first successful result.
38
- ```kernelcore
39
- <{.x .true false_bool}, {} true_bool>
40
- ```
41
-
42
- 5. **Constants**:
43
- - Constants are defined as partial functions that ignore their input.
44
- - Example:
45
- ```kernelcore
46
- true_bool = {{} true} $bool;
47
- false_bool = {{} false} $bool;
48
- ```
49
-
50
- #### Example Program
51
-
52
- ```kernelcore
53
- // Define a boolean type as a union of true and false
54
- $ bool = <{} true, {} false>;
55
-
56
- // Define a pair of booleans as a product of two booleans
57
- $ pair_of_bools = {bool x, bool y};
58
-
59
- // Check if the `x` field is `true`
60
- is_x_true = $pair_of_bools (.x .true);
61
-
62
- // Extract both `x` and `y` fields into a new product
63
- extract_both = $pair_of_bools {.x x_value, .y y_value} $pair_of_bools;
64
-
65
- // Check if either `x` or `y` is `true`
66
- is_any_true = $pair_of_bools <{.x .true false_bool}, {} true_bool> $bool;
67
-
68
- // Define constants
69
- true_bool = {{} true} $bool;
70
- false_bool = {{} false} $bool;
71
-
72
- // Create instances of `pair_of_bools`
73
- pair1 = {true_bool x, true_bool y} $pair_of_bools;
74
- pair2 = {true_bool x, false_bool y} $pair_of_bools;
75
- pair3 = {false_bool x, false_bool y} $pair_of_bools;
76
-
77
- // Example usage of the functions
78
- result1 = pair1 is_x_true; // Should return true
79
- result2 = pair2 is_x_true; // Should return true
80
-
81
- both_values = pair1 extract_both; // Should return {x_value true, y_value true}
82
-
83
- any_true1 = pair1 is_any_true; // Should return true
84
- any_true2 = pair2 is_any_true; // Should return true
85
- any_true3 = pair3 is_any_true; // Should return false
86
- ```
87
-
88
- This brief introduction covers the fundamental concepts of Kernel/Core, enabling you to start defining data types and writing partial functions to transform data.
package/TODO.md DELETED
@@ -1,54 +0,0 @@
1
- # TODO list
2
-
3
- - [ ] Incremental compilation
4
- - [ ] After `annotation` is done, find fully closed patterns, turn them into codes, then rerun
5
- the code minimization step
6
- - [ ] Named relations can be polymorphic:
7
- -- can we introduce polymorphic patterns? E.g.,: `{ .x if, .y then} .then`.
8
- Here, the input pattern could be "open" product with two fields `.x` and `.y`, end the ouput pattern could be the pattern of field `.y`.
9
- -- should we introduce a scope (e.g., syntactic or dynamic?) for all calls to the relation and
10
- run annotations for all scopes separately?
11
- - [ ] Implement support for different relations under a same name as long as they have
12
- "very" different input or output patterns.
13
- - [ ] In type graphs, we should detect cycles over only product types and reject such programs, e.g.,:
14
-
15
- ```k
16
- $boo = {{} _, boo b};
17
- ```
18
-
19
- ---
20
-
21
- ## Type system
22
-
23
- Example:
24
-
25
- ```Examples/pats.k
26
- xy = .x y;
27
- y = .y;
28
- $A = < {} a, {} other >;
29
- $B = < {} b, {} other >;
30
- $ya = < {} a, $A y >;
31
- $yb = < {} b, $B y >;
32
- $input = {{ya x, {} y} one, {yb x, {} y} two};
33
- $input {.one xy one, .two xy two}
34
- ```
35
-
36
- We would like to correctly type the above program as `$input -> { A one, B two }`.
37
-
38
- filters for typing `__main__`:
39
-
40
- ```?
41
- __main__
42
- 0 / \ 1
43
- / \
44
- $input {.one xy one, .two xy two}
45
- 2 3 4 / \ 5
46
- / \
47
- (.one xy) (.two xy)
48
- / \ / \
49
- 6 / \ 7 8 / \ 9
50
- / \ / \
51
- .one xy .two xy
52
- 10 11 12 13 14 15 16 17
53
-
54
- ```
package/bug.json DELETED
@@ -1,419 +0,0 @@
1
- {
2
- "rels": {
3
- "xy": [
4
- {
5
- "op": "comp",
6
- "comp": [
7
- {
8
- "op": "dot",
9
- "dot": "x",
10
- "start": {
11
- "line": 1,
12
- "column": 6
13
- },
14
- "end": {
15
- "line": 1,
16
- "column": 8
17
- },
18
- "patterns": [
19
- 2,
20
- 3
21
- ]
22
- },
23
- {
24
- "op": "ref",
25
- "ref": "y",
26
- "start": {
27
- "line": 1,
28
- "column": 9
29
- },
30
- "end": {
31
- "line": 1,
32
- "column": 10
33
- },
34
- "patterns": [
35
- 3,
36
- 4
37
- ]
38
- }
39
- ],
40
- "start": {
41
- "line": 1,
42
- "column": 6
43
- },
44
- "end": {
45
- "line": 1,
46
- "column": 10
47
- },
48
- "patterns": [
49
- 2,
50
- 4
51
- ]
52
- }
53
- ],
54
- "y": [
55
- {
56
- "op": "dot",
57
- "dot": "y",
58
- "start": {
59
- "line": 2,
60
- "column": 5
61
- },
62
- "end": {
63
- "line": 2,
64
- "column": 7
65
- },
66
- "patterns": [
67
- 0,
68
- 1
69
- ]
70
- }
71
- ],
72
- "__main__": [
73
- {
74
- "op": "comp",
75
- "comp": [
76
- {
77
- "op": "code",
78
- "code": "BrQwZuzvQqL",
79
- "start": {
80
- "line": 8,
81
- "column": 1
82
- },
83
- "end": {
84
- "line": 8,
85
- "column": 7
86
- },
87
- "patterns": [
88
- 9,
89
- 9
90
- ]
91
- },
92
- {
93
- "op": "product",
94
- "product": [
95
- {
96
- "label": "one",
97
- "exp": {
98
- "op": "comp",
99
- "comp": [
100
- {
101
- "op": "dot",
102
- "dot": "one",
103
- "start": {
104
- "line": 8,
105
- "column": 9
106
- },
107
- "end": {
108
- "line": 8,
109
- "column": 13
110
- },
111
- "patterns": [
112
- 9,
113
- 5
114
- ]
115
- },
116
- {
117
- "op": "ref",
118
- "ref": "xy",
119
- "start": {
120
- "line": 8,
121
- "column": 14
122
- },
123
- "end": {
124
- "line": 8,
125
- "column": 16
126
- },
127
- "patterns": [
128
- 5,
129
- 6
130
- ]
131
- }
132
- ],
133
- "start": {
134
- "line": 8,
135
- "column": 9
136
- },
137
- "end": {
138
- "line": 8,
139
- "column": 16
140
- },
141
- "patterns": [
142
- 9,
143
- 6
144
- ]
145
- }
146
- },
147
- {
148
- "label": "two",
149
- "exp": {
150
- "op": "comp",
151
- "comp": [
152
- {
153
- "op": "dot",
154
- "dot": "two",
155
- "start": {
156
- "line": 8,
157
- "column": 22
158
- },
159
- "end": {
160
- "line": 8,
161
- "column": 26
162
- },
163
- "patterns": [
164
- 9,
165
- 7
166
- ]
167
- },
168
- {
169
- "op": "ref",
170
- "ref": "xy",
171
- "start": {
172
- "line": 8,
173
- "column": 27
174
- },
175
- "end": {
176
- "line": 8,
177
- "column": 29
178
- },
179
- "patterns": [
180
- 7,
181
- 8
182
- ]
183
- }
184
- ],
185
- "start": {
186
- "line": 8,
187
- "column": 22
188
- },
189
- "end": {
190
- "line": 8,
191
- "column": 29
192
- },
193
- "patterns": [
194
- 9,
195
- 8
196
- ]
197
- }
198
- }
199
- ],
200
- "start": {
201
- "line": 8,
202
- "column": 8
203
- },
204
- "end": {
205
- "line": 8,
206
- "column": 34
207
- },
208
- "patterns": [
209
- 9,
210
- 10
211
- ]
212
- }
213
- ],
214
- "start": {
215
- "line": 8,
216
- "column": 1
217
- },
218
- "end": {
219
- "line": 10,
220
- "column": 3
221
- },
222
- "patterns": [
223
- 9,
224
- 10
225
- ]
226
- }
227
- ]
228
- },
229
- "codes": {
230
- "DBO": {
231
- "code": "product",
232
- "product": {},
233
- "def": "$C0={};"
234
- },
235
- "BDAJxzVAZYX": {
236
- "code": "union",
237
- "union": {
238
- "y": "DBO",
239
- "a": "DBO"
240
- },
241
- "start": {
242
- "line": 3,
243
- "column": 7
244
- },
245
- "end": {
246
- "line": 3,
247
- "column": 21
248
- },
249
- "def": "$C0=<C1\"a\",C1\"y\">;$C1={};"
250
- },
251
- "CDRPHMxTHrX": {
252
- "code": "union",
253
- "union": {
254
- "y": "DBO",
255
- "b": "DBO"
256
- },
257
- "start": {
258
- "line": 4,
259
- "column": 7
260
- },
261
- "end": {
262
- "line": 4,
263
- "column": 21
264
- },
265
- "def": "$C0=<C1\"b\",C1\"y\">;$C1={};"
266
- },
267
- "CJFCNvVySrW": {
268
- "code": "product",
269
- "product": {
270
- "x": "CDRPHMxTHrX",
271
- "yb": "DBO"
272
- },
273
- "start": {
274
- "line": 6,
275
- "column": 8
276
- },
277
- "end": {
278
- "line": 6,
279
- "column": 21
280
- },
281
- "def": "$C0={C1\"x\",C2\"yb\"};$C1=<C2\"b\",C2\"y\">;$C2={};"
282
- },
283
- "BrQwZuzvQqL": {
284
- "code": "product",
285
- "product": {
286
- "one": "CJFCNvVySrW",
287
- "two": "CJFCNvVySrW"
288
- },
289
- "start": {
290
- "line": 7,
291
- "column": 10
292
- },
293
- "end": {
294
- "line": 7,
295
- "column": 28
296
- },
297
- "def": "$C0={C1\"one\",C2\"two\"};$C1={C3\"x\",C4\"ya\"};$C2={C5\"x\",C4\"yb\"};$C3=<C4\"a\",C4\"y\">;$C4={};$C5=<C4\"b\",C4\"y\">;"
298
- }
299
- },
300
- "representatives": {
301
- "BrQwZuzvQqL": "BrQwZuzvQqL",
302
- "CJFCNvVySrW": "CJFCNvVySrW",
303
- "CDRPHMxTHrX": "CDRPHMxTHrX",
304
- "BDAJxzVAZYX": "BDAJxzVAZYX",
305
- "DBO": "DBO",
306
- "{}": "DBO",
307
- ":1": "DBO",
308
- ":2": "DBO",
309
- "ya": "BDAJxzVAZYX",
310
- ":4": "DBO",
311
- ":5": "DBO",
312
- "yb": "CDRPHMxTHrX",
313
- ":7": "DBO",
314
- "one": "CJFCNvVySrW",
315
- ":9": "DBO",
316
- "two": "CJFCNvVySrW",
317
- "input": "BrQwZuzvQqL"
318
- },
319
- "patternNodes": [
320
- {
321
- "_id": 6,
322
- "code": null,
323
- "type": null,
324
- "closed": false
325
- },
326
- {
327
- "_id": 7,
328
- "code": null,
329
- "type": null,
330
- "closed": false
331
- },
332
- {
333
- "_id": 26,
334
- "code": null,
335
- "type": null,
336
- "closed": false,
337
- "_from": "(0,1)"
338
- },
339
- {
340
- "_id": 27,
341
- "code": null,
342
- "type": null,
343
- "closed": false,
344
- "_from": "(2,3)"
345
- },
346
- {
347
- "_id": 28,
348
- "code": null,
349
- "type": null,
350
- "closed": false,
351
- "_from": "(4,5)"
352
- },
353
- {
354
- "_id": 32,
355
- "code": "CJFCNvVySrW",
356
- "type": "code",
357
- "closed": true,
358
- "_from": "(14,15)"
359
- },
360
- {
361
- "_id": 33,
362
- "code": null,
363
- "type": null,
364
- "closed": false,
365
- "_from": "(16,17)"
366
- },
367
- {
368
- "_id": 35,
369
- "code": "CJFCNvVySrW",
370
- "type": "code",
371
- "closed": true,
372
- "_from": "(20,21)"
373
- },
374
- {
375
- "_id": 36,
376
- "code": null,
377
- "type": null,
378
- "closed": false,
379
- "_from": "(22,23)"
380
- },
381
- {
382
- "_id": 39,
383
- "code": "BrQwZuzvQqL",
384
- "type": "code",
385
- "closed": true,
386
- "_from": "((8,(9,10)),((18,19),((12,13),11)))"
387
- },
388
- {
389
- "_id": 40,
390
- "code": null,
391
- "type": "product",
392
- "closed": true,
393
- "_from": "(24,25)"
394
- }
395
- ],
396
- "patternEdges": {
397
- "0": {
398
- "y": 1
399
- },
400
- "1": {},
401
- "2": {
402
- "x": 3
403
- },
404
- "3": {},
405
- "4": {},
406
- "5": {},
407
- "6": {},
408
- "7": {},
409
- "8": {},
410
- "9": {
411
- "one": 5,
412
- "two": 7
413
- },
414
- "10": {
415
- "one": 6,
416
- "two": 8
417
- }
418
- }
419
- }