@fraczak/k 2.1.6 → 3.0.1
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/Code-derivation-tests/bnat.mjs +10 -0
- package/Code-derivation-tests/built-in.mjs +19 -0
- package/Code-derivation-tests/dot.mjs +15 -0
- package/Code-derivation-tests/index.mjs +20 -0
- package/Code-derivation-tests/loop.mjs +11 -0
- package/Code-derivation-tests/nat.mjs +10 -0
- package/Code-derivation-tests/not-not.mjs +14 -0
- package/Code-derivation-tests/product.mjs +21 -0
- package/Code-derivation-tests/rlz.mjs +14 -0
- package/Code-derivation-tests/vector.mjs +28 -0
- package/INTRO.md +88 -0
- package/README.md +68 -14
- package/TODO.md +54 -0
- package/TYPES.md +32 -0
- package/bug.json +419 -0
- package/chatGPT.md +235 -0
- package/chatGPT.md~ +119 -0
- package/code-resolution.md +121 -0
- package/code-resolution.mjs +51 -0
- package/codes.mjs +59 -4
- package/filters.mjs +59 -0
- package/hash.mjs +39 -0
- package/index.mjs +55 -12
- package/package.json +2 -2
- package/parser.jison +111 -44
- package/parser.mjs +146 -88
- package/patterns.mjs +601 -0
- package/pretty.mjs +27 -0
- package/repl.mjs +6 -3
- package/run.mjs +4 -1
- package/symbol-table.mjs +1 -1
- package/test-filters.mjs +45 -0
- package/test-fingerprint.mjs +38 -0
- package/test.mjs +1 -43
package/bug.json
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
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
|
+
}
|
package/chatGPT.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# Key Concepts and Constructs of Kernel/Core
|
|
2
|
+
|
|
3
|
+
1. **Program Structure**:
|
|
4
|
+
- Consists of a possibly empty list of statements, each ending with a semicolon (`;`), followed by an expression.
|
|
5
|
+
- Statements can be:
|
|
6
|
+
- **Code Definitions**: Define data types and start with a dollar sign (`$`).
|
|
7
|
+
- **Relation Definitions**: Define partial functions for data transformations.
|
|
8
|
+
|
|
9
|
+
2. **Code Definitions (Data Types)**:
|
|
10
|
+
- **Union Types**: Defined using angle brackets (`<...>`).
|
|
11
|
+
|
|
12
|
+
```kernelcore
|
|
13
|
+
$ bool = <{} true, {} false>;
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- **Product Types**: Defined using curly braces (`{...}`).
|
|
17
|
+
|
|
18
|
+
```kernelcore
|
|
19
|
+
$ pair_of_bools = {bool x, bool y};
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
3. **Relation Definitions (Partial Functions)**:
|
|
23
|
+
- **Projection (Field Extraction)**: Partial functions that extract fields from product types or check for specific variants in union types.
|
|
24
|
+
|
|
25
|
+
```kernelcore
|
|
26
|
+
// Extract the `x` field from a pair_of_bools (product type)
|
|
27
|
+
extract_x = $pair_of_bools .x;
|
|
28
|
+
|
|
29
|
+
// Extract the `y` field from a pair_of_bools (product type)
|
|
30
|
+
extract_y = $pair_of_bools .y;
|
|
31
|
+
|
|
32
|
+
// Check if a bool is the `true` variant (union type)
|
|
33
|
+
check_true = $bool .true;
|
|
34
|
+
|
|
35
|
+
// Check if a bool is the `false` variant (union type)
|
|
36
|
+
check_false = $bool .false;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- **Sequential (Functional) Composition**: Sequential application of partial functions.
|
|
40
|
+
|
|
41
|
+
```kernelcore
|
|
42
|
+
is_x_true = $pair_of_bools .x .true;
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- **Parallel (Product) Composition**: Combine multiple partial functions to construct a new product type.
|
|
46
|
+
|
|
47
|
+
```kernelcore
|
|
48
|
+
extract_both = $pair_of_bools {.x x_value, .y y_value};
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- **Concurrent (Union) Composition**: Try different functions in sequence, returning the first successful result.
|
|
52
|
+
|
|
53
|
+
```kernelcore
|
|
54
|
+
is_any_true = $pair_of_bools <.x .true true_bool, .y .true true_bool, false_bool>;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
4. **Constants**:
|
|
58
|
+
- Constants are partial functions that ignore their input.
|
|
59
|
+
|
|
60
|
+
```kernelcore
|
|
61
|
+
true_bool = {{} true};
|
|
62
|
+
false_bool = {{} false};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
5. **Names and Labels**:
|
|
66
|
+
- Names and labels are alphanumerical sequences of ASCII characters, following the convention `[a-zA-Z_][a-zA-Z0-9_]*`.
|
|
67
|
+
|
|
68
|
+
6. **Final Expression**:
|
|
69
|
+
- A final expression evaluates usage examples and collects results in a single product.
|
|
70
|
+
|
|
71
|
+
```kernelcore
|
|
72
|
+
{pair1 is_x_true result1,
|
|
73
|
+
pair2 is_x_true result2,
|
|
74
|
+
pair1 extract_both both_values,
|
|
75
|
+
pair1 is_any_true any_true1,
|
|
76
|
+
pair2 is_any_true any_true2,
|
|
77
|
+
pair3 is_any_true any_true3}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Complete Example Program
|
|
81
|
+
|
|
82
|
+
```kernelcore
|
|
83
|
+
// Define a boolean type as a union of true and false
|
|
84
|
+
$ bool = <{} true, {} false>;
|
|
85
|
+
|
|
86
|
+
// Define a pair of booleans as a product of two booleans
|
|
87
|
+
$ pair_of_bools = {bool x, bool y};
|
|
88
|
+
|
|
89
|
+
// Projection (Field Extraction)
|
|
90
|
+
// Extract the `x` field from a pair_of_bools (product type)
|
|
91
|
+
extract_x = $pair_of_bools .x;
|
|
92
|
+
|
|
93
|
+
// Extract the `y` field from a pair_of_bools (product type)
|
|
94
|
+
extract_y = $pair_of_bools .y;
|
|
95
|
+
|
|
96
|
+
// Check if a bool is the `true` variant (union type)
|
|
97
|
+
check_true = $bool .true;
|
|
98
|
+
|
|
99
|
+
// Check if a bool is the `false` variant (union type)
|
|
100
|
+
check_false = $bool .false;
|
|
101
|
+
|
|
102
|
+
// Check if the `x` field is `true`
|
|
103
|
+
is_x_true = $pair_of_bools .x .true;
|
|
104
|
+
|
|
105
|
+
// Extract both `x` and `y` fields into a new product
|
|
106
|
+
extract_both = $pair_of_bools {.x x_value, .y y_value};
|
|
107
|
+
|
|
108
|
+
// Check if either `x` or `y` is `true`
|
|
109
|
+
is_any_true = $pair_of_bools <.x .true true_bool, .y .true true_bool, false_bool>;
|
|
110
|
+
|
|
111
|
+
// Define constants
|
|
112
|
+
true_bool = {{} true};
|
|
113
|
+
false_bool = {{} false};
|
|
114
|
+
|
|
115
|
+
// Create instances of `pair_of_bools`
|
|
116
|
+
pair1 = {true_bool x, true_bool y};
|
|
117
|
+
pair2 = {true_bool x, false_bool y};
|
|
118
|
+
pair3 = {false_bool x, false_bool y};
|
|
119
|
+
|
|
120
|
+
// Final expression to evaluate usage examples
|
|
121
|
+
{pair1 is_x_true result1,
|
|
122
|
+
pair2 is_x_true result2,
|
|
123
|
+
pair1 extract_both both_values,
|
|
124
|
+
pair1 is_any_true any_true1,
|
|
125
|
+
pair2 is_any_true any_true2,
|
|
126
|
+
pair3 is_any_true any_true3}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Kernel/Core Programming Language Overview
|
|
132
|
+
|
|
133
|
+
**Goal**: To establish a minimal set of orthogonal constructs for describing data transformations as partial functions.
|
|
134
|
+
|
|
135
|
+
### Basic Concepts
|
|
136
|
+
|
|
137
|
+
1. **Data Types (Codes)**: Defined using tagged unions and product types.
|
|
138
|
+
- Union: `<>` denotes a union.
|
|
139
|
+
- Product: `{}` denotes a product.
|
|
140
|
+
|
|
141
|
+
2. **Partial Functions (Relations)**: Defined for data transformations.
|
|
142
|
+
- Projection: Extract the value of a given field from product types or variant from union types, `.field_name`.
|
|
143
|
+
- Sequential Composition: sequence of partial function applications (`r1 r2 r3 ...`).
|
|
144
|
+
- Parallel Composition: `{r1 f1, r2 f2, ...}`.
|
|
145
|
+
- Concurrent Composition: `<r1, r2, ...>`.
|
|
146
|
+
|
|
147
|
+
### Syntax
|
|
148
|
+
|
|
149
|
+
- **Program Structure**: Consists of code and relation definitions, ending with a semicolon `;`, followed by an expression which defines the relation (i.e., the desired data transformation).
|
|
150
|
+
|
|
151
|
+
- **Code Definition**: Introduces union or product types.
|
|
152
|
+
|
|
153
|
+
```plaintext
|
|
154
|
+
$bool = <{} true, {} false>;
|
|
155
|
+
$pair_of_bools = {bool x, bool y};
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
- **Code annotations**:
|
|
159
|
+
Any code expression (prefixed by `$`) within a relation definition acts as a type annotation and can be seen as a partial identity function that copies its input to the output as long as the input value is of the type defined by the code expression.
|
|
160
|
+
|
|
161
|
+
- **Constants**:
|
|
162
|
+
Constants are partial functions (relations) that ignore their input. E.g., `{}` ignores the input and produces the empty product (unit). Any value (data point) will be represented by an expression defining the constant (i.e., the relation which ignores its input and returns the value). For representing a value of a union type we use the singleton parallel (product) composition with the only field corresponding to the variant. For example, `{{} true}` could represent the `true` variant of the `$bool`. For a product type, we naturally use the parallel (product) composition, e.g., `{{{} true} x, {{} false} y}` could represent a data point of type `$pair_of_bools`.
|
|
163
|
+
|
|
164
|
+
Singleton type definitions, by union or product, should be avoided as they do not bring any additional information and they cannot be distinguished from the variant or field they represent. E.g.:
|
|
165
|
+
|
|
166
|
+
```plaintext
|
|
167
|
+
$unit_by_union = <{} unit>;
|
|
168
|
+
$unit_by_product = {{} unit};
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
are equivalent to the empty product type `{}`.
|
|
172
|
+
|
|
173
|
+
- **Relation Definition**: Defines helper relations.
|
|
174
|
+
|
|
175
|
+
```plaintext
|
|
176
|
+
true_bool = {{} true} $bool;
|
|
177
|
+
false_bool = {{} false} $bool;
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Example Program
|
|
181
|
+
|
|
182
|
+
```plaintext
|
|
183
|
+
// Define data types
|
|
184
|
+
$bool = <{} true, {} false>;
|
|
185
|
+
$pair_of_bools = {bool x, bool y};
|
|
186
|
+
|
|
187
|
+
// Define relations
|
|
188
|
+
true_bool = {{} true} $bool;
|
|
189
|
+
false_bool = {{} false} $bool;
|
|
190
|
+
|
|
191
|
+
is_x_true = $pair_of_bools .x .true;
|
|
192
|
+
is_y_true = $pair_of_bools .y .true;
|
|
193
|
+
extract_both = $pair_of_bools {.x x_value, .y y_value};
|
|
194
|
+
|
|
195
|
+
is_any_true = $pair_of_bools <.x .true true_bool, .y .true true_bool, false_bool>;
|
|
196
|
+
|
|
197
|
+
// Create instances of pair_of_bools
|
|
198
|
+
pair1 = {true_bool x, true_bool y};
|
|
199
|
+
pair2 = {true_bool x, false_bool y};
|
|
200
|
+
|
|
201
|
+
// Example usage of the functions
|
|
202
|
+
{
|
|
203
|
+
(pair1 is_x_true) pair1_x_true,
|
|
204
|
+
(pair1 is_y_true) pair1_y_true,
|
|
205
|
+
(pair2 is_x_true) pair2_x_true,
|
|
206
|
+
(pair2 is_y_true) pair2_y_true,
|
|
207
|
+
(pair1 is_any_true) pair1_any_true,
|
|
208
|
+
(pair2 is_any_true) pair2_any_true,
|
|
209
|
+
(pair1 extract_both) extracted1,
|
|
210
|
+
(pair2 extract_both) extracted2
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Key Concepts
|
|
215
|
+
|
|
216
|
+
1. **Projections**: Partial functions for field extraction.
|
|
217
|
+
|
|
218
|
+
```plaintext
|
|
219
|
+
.x, .y // For product types
|
|
220
|
+
.true, .false // For union types (act as checks)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
2. **Constants**: Defined as partial functions that ignore their input.
|
|
224
|
+
|
|
225
|
+
```plaintext
|
|
226
|
+
zero = {{} zero} $nat;
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
3. **Error Handling**: Kernel/core defines partial functions and does not have a notion of errors within the language. Execution errors (e.g., OOM, stack overflow) are handled by the operating system.
|
|
230
|
+
|
|
231
|
+
4. **Global Names**: All names for relations and codes are global. Relation names and code names do not clash.
|
|
232
|
+
|
|
233
|
+
5. **Gradual Typing**: Expressions cannot always be fully type-annotated, e.g., `.true` can be used where the input value has a union or product type with the variant/field 'true'.
|
|
234
|
+
|
|
235
|
+
6. **Performance Considerations**: Partial functions can be optimized into "sequential transducers," "sequential functions," or a dynamic network of these. Full optimization is possible for the first two classes, with heuristics used for general cases.
|