@fraczak/k 6.10.5 → 7.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/CLAUDE.md +1 -1
  3. package/DOCS/BIG_PICTURE.md +156 -172
  4. package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +3 -3
  5. package/DOCS/CODEC_ARCHITECTURE.md +2 -2
  6. package/DOCS/DICTIONARY.md +243 -250
  7. package/DOCS/DIVERGENCE_DETECTION.md +0 -1
  8. package/DOCS/FILE_FORMATS.md +5 -5
  9. package/DOCS/KIR_SPECIALIZATION_DESIGN.md +1 -1
  10. package/DOCS/OBJECT_FILE_AND_PATTERN.md +12 -12
  11. package/DOCS/PATTERNS.md +17 -17
  12. package/DOCS/PATTERNS_AND_TYPED_VALUES.md +1 -1
  13. package/DOCS/REPL.md +9 -19
  14. package/DOCS/TYPE_DERIVATION.md +2 -8
  15. package/DOCS/WEB_REPL_REQUIREMENTS.md +8 -8
  16. package/DOCS/book/01-introduction.md +8 -11
  17. package/DOCS/book/02-syntax-and-values.md +19 -20
  18. package/DOCS/book/03-types-as-finite-automata.md +42 -43
  19. package/DOCS/book/04-partial-functions-and-composition.md +2 -3
  20. package/DOCS/book/05-typing-filters-and-normalization.md +44 -46
  21. package/DOCS/book/06-values-in-memory.md +10 -10
  22. package/DOCS/book/08-operational-semantics-and-execution.md +21 -26
  23. package/DOCS/book/09-compiler-architecture.md +11 -11
  24. package/DOCS/book/10-from-ast-to-intermediate-representation.md +6 -7
  25. package/DOCS/book/14-canonical-serialization.md +2 -2
  26. package/DOCS/book/appendix-b-incorporating-external-predefined-types-and-functions.md +17 -17
  27. package/DOCS/book.md +5 -5
  28. package/Examples/arithmetics.k +49 -153
  29. package/Examples/bnat.k +13 -13
  30. package/Examples/byte.k +2 -50
  31. package/Examples/ieee.k +408 -423
  32. package/Examples/karatsuba-mult.k +30 -34
  33. package/Examples/nat.k +5 -6
  34. package/README.md +54 -49
  35. package/TODO.md +13 -18
  36. package/browser/repl-browser.mjs +40 -22
  37. package/browser/shims/fs.mjs +7 -10
  38. package/browser/vfs-data.mjs +12 -12
  39. package/codecs/BINARY_FORMAT.md +4 -4
  40. package/codecs/POLYMORPHIC_BINARY_FORMAT.md +4 -4
  41. package/codecs/README.md +6 -6
  42. package/codecs/ieee.mjs +15 -11
  43. package/codecs/int.mjs +9 -5
  44. package/codecs/string-codec.mjs +46 -47
  45. package/core.k +124 -175
  46. package/object.mjs +0 -7
  47. package/package.json +5 -2
  48. package/parser.jison +2 -41
  49. package/parser.mjs +55 -95
  50. package/pretty.mjs +11 -4
  51. package/repl.mjs +8 -63
  52. package/scripts/build-repl-html.mjs +18 -49
  53. package/tests/code-derivation/blowup.mjs +2 -4
  54. package/tests/code-derivation/bnat.mjs +2 -3
  55. package/tests/code-derivation/dot.mjs +5 -11
  56. package/tests/code-derivation/nat.mjs +2 -2
  57. package/tests/code-derivation/not-not.mjs +6 -6
  58. package/tests/code-derivation/pattern-envelope.mjs +4 -6
  59. package/tests/code-derivation/product.mjs +3 -6
  60. package/tests/code-derivation/rlz.mjs +4 -5
  61. package/tests/test-codecs.mjs +1 -1
  62. package/tests/test-fingerprint.mjs +36 -41
  63. package/tests/test-hash-normalization.mjs +4 -6
  64. package/tests/test-ieee-arithmetic.mjs +6 -7
  65. package/tests/test-k-object.mjs +11 -15
  66. package/tests/test-kir.mjs +0 -1
  67. package/tests/test-kvm-polymorphic.mjs +1 -2
  68. package/tests/test-kvm.mjs +8 -11
  69. package/tests/test-repl-html.mjs +86 -9
  70. package/tests/test-repl.mjs +38 -53
  71. package/tests/test.mjs +2 -3
@@ -16,7 +16,6 @@ Define `HEAD` as the set of direct first ref calls:
16
16
  ```
17
17
  HEAD(ref(X)) = {X}
18
18
  HEAD(?F E) = HEAD(E)
19
- HEAD($T E) = HEAD(E)
20
19
  HEAD((E1 E2 ...)) = HEAD(E1)
21
20
  HEAD({ E1 f1, E2 f2, ... }) = HEAD(E1) union HEAD(E2) union ...
22
21
  HEAD(<E1, E2, ...>) = {} -- the head of a union is the empty set
@@ -397,13 +397,13 @@ hash without `--export`.
397
397
  In `k`, there are no primitive numerical types or built-in integer
398
398
  literals. Identifiers such as `5` or `10` are not language keywords;
399
399
  they are defined relations (aliases) in `Examples/arithmetics.k`:
400
- - `5` and `10` are nullary relations (constants) of type `${} -> $bits`,
401
- defined as binary digit trees over `$bits = < {} _, bits 0, bits 1 >`.
400
+ - `5` and `10` are nullary relations (constants) of type `{} -> bits`,
401
+ defined as binary digit trees over `bits = ?< {} _, bits 0, bits 1 > = bits;`.
402
402
  - Arithmetic operations (`plus`, `minus`, `times`, `inc`) operate on
403
- signed integers (`$int = < bits "+", bits "-" >`).
403
+ signed integers (`int = < <bits 0, bits 1, {} _>=bits "+", bits "-" >`).
404
404
  - Passing a bit-representation like `5` to an integer relation requires
405
405
  applying the `int` constructor (`5 int`), producing a constant
406
- relation of type `${} -> $int`.
406
+ relation of type `{} -> int`.
407
407
 
408
408
  ### 3. Constant Expressions vs. Stream Transformers
409
409
  - **Stream Transformers:** An expression using the identity relation `()`
@@ -412,7 +412,7 @@ they are defined relations (aliases) in `Examples/arithmetics.k`:
412
412
  `./codecs/int.mjs --parse`).
413
413
  - **Closed Constant Relations:** A relation with no free inputs (such
414
414
  as `{10 int x, 5 int y} plus`) is a constant relation with input
415
- type of unit `${}`. When executed through `./k.mjs`, it expects
415
+ type of unit `{}`. When executed through `./k.mjs`, it expects
416
416
  an empty unit `{}` on `stdin`:
417
417
  ```bash
418
418
  echo "{}" | node codecs/k-parse.mjs | \
@@ -396,7 +396,7 @@ Runtime:
396
396
 
397
397
  Typing and patterns:
398
398
 
399
- - `$type` filter;
399
+ - `?filter` expression;
400
400
  - open product filter;
401
401
  - open union filter;
402
402
  - recursive list/tree filter;
@@ -5,7 +5,7 @@ The codec boundary is no longer a JSON object. A serialized value is one binary
5
5
  stream:
6
6
 
7
7
  ```text
8
- encode($pattern_value : $pattern) encode(value : decoded_pattern)
8
+ encode(pattern_value : pattern) encode(value : decoded_pattern)
9
9
  ```
10
10
 
11
11
  The pattern is the framing protocol. There is no separate envelope type.
@@ -15,10 +15,10 @@ The pattern is the framing protocol. There is no separate envelope type.
15
15
  [`core.k`](../core.k) defines the canonical self-hosted pattern type:
16
16
 
17
17
  ```k
18
- $ edge = { string label, bits target };
19
- $ edges = < {} nil, { edge car, edges cdr } cons >;
18
+ edge = ?{ string label, bits target };
19
+ edges = ?< {} nil, { edge car, E cdr } cons > = E;
20
20
 
21
- $ pattern-node = <
21
+ pattern-node = ?<
22
22
  {} any,
23
23
  edges open-product,
24
24
  edges open-union,
@@ -26,24 +26,24 @@ $ pattern-node = <
26
26
  edges closed-union
27
27
  >;
28
28
 
29
- $ pattern = < {} nil, { pattern-node car, pattern cdr } cons >;
29
+ pattern = ?< {} nil, { pattern-node car, P cdr } cons > = P;
30
30
  ```
31
31
 
32
32
  This does not mean `core.k` is pre-loaded into ordinary program execution. The
33
33
  special role of `core.k` here is that the wire codec relies on the canonical
34
- `$pattern` definition from that file.
34
+ `pattern` definition from that file.
35
35
 
36
36
  In this schema:
37
37
 
38
38
  - the first pattern-list element is node `0`, the root,
39
- - an edge target is a node index encoded as `$bits`,
40
- - labels are `$string` values and therefore Unicode scalar-value strings,
39
+ - an edge target is a node index encoded as `bits`,
40
+ - labels are `string` values and therefore Unicode scalar-value strings,
41
41
  - edge lists are sorted by label,
42
42
  - `any` carries no edges,
43
43
  - the four product/union node kinds carry their edge list directly.
44
44
 
45
- The fixed singleton pattern of `$pattern` is the first decoder context for all
46
- k wire values. Decoding any value first decodes a `$pattern` value under that
45
+ The fixed singleton pattern of `pattern` is the first decoder context for all
46
+ k wire values. Decoding any value first decodes a `pattern` value under that
47
47
  constant, then decodes the remaining bits under the pattern just obtained.
48
48
 
49
49
  ## Debug Notation
@@ -69,7 +69,7 @@ The parser plus type-derivation phase should eventually emit an object value
69
69
  rather than executable JavaScript structures. A minimal first object shape is:
70
70
 
71
71
  ```k
72
- $ object-file = {
72
+ object-file = ?{
73
73
  pattern input-pattern,
74
74
  pattern output-pattern,
75
75
  pattern value-pattern
@@ -274,7 +274,7 @@ For a definitions-only source file:
274
274
 
275
275
  ```k
276
276
  -- defs.k
277
- $ nat = <{} zero, nat succ>;
277
+ nat = ?< {} zero, N succ > = N;
278
278
  succ = |succ;
279
279
  ```
280
280
 
package/DOCS/PATTERNS.md CHANGED
@@ -1,12 +1,13 @@
1
- # Patterns
1
+ # Schemas and Pattern Graphs
2
2
 
3
- A pattern describes the shape of values that may flow through a k
4
- expression. Patterns are used by:
3
+ In `k`, an algebraic **schema** describes the shape of payload trees that may flow
4
+ through a relation. In compiler artifacts and serialization, schemas are represented
5
+ as property-list arrays of automata nodes. Schemas are used by:
5
6
 
6
- - the type-derivation engine
7
+ - the contract-derivation engine
7
8
  - the binary codec
8
- - runtime values carried by the codec pipeline
9
- - filter expressions
9
+ - runtime framed values `(schema, payload)`
10
+ - filter expressions (`?schema`)
10
11
 
11
12
  ## Pattern Kinds
12
13
 
@@ -49,19 +50,19 @@ This is not the wire format. It is the canonical readable export form.
49
50
 
50
51
  A k script can describe a pattern through:
51
52
 
52
- - a type name in terminal position
53
+ - a relation in terminal position
53
54
  - a filter expression in terminal position
54
55
 
55
56
  Examples:
56
57
 
57
58
  ```k
58
- $ bits = < {} _, bits 0, bits 1 >;
59
- $ list = < {} nil, { bits car, list cdr } cons >;
59
+ bits = ?< {} _, bits 0, bits 1 > = bits;
60
+ list = ?< {} nil, { < {} _, B 0, B 1 >=B car, L cdr } cons > = L;
60
61
  list
61
62
  ```
62
63
 
63
64
  ```k
64
- ?< {} nil, { $bits car, X cdr } cons > = X
65
+ ?< {} nil, { < {} _, B 0, B 1 >=B car, X cdr } cons > = X
65
66
  ```
66
67
 
67
68
  In both cases, the compiler derives a root pattern from `__main__`.
@@ -78,14 +79,14 @@ It:
78
79
  3. resolves `__main__`
79
80
  4. requires `__main__` to be either:
80
81
  - a filter expression
81
- - a type name
82
+ - a relation name
82
83
  5. exports the corresponding root pattern
83
84
  6. prints it as the canonical property-list array
84
85
 
85
86
  Example:
86
87
 
87
88
  ```bash
88
- echo '?< {} nil, { $bits car, X cdr } cons > = X' | node ./patterns/from-k.mjs
89
+ echo '?< {} nil, { < {} _, B 0, B 1 >=B car, X cdr } cons > = X' | node ./patterns/from-k.mjs
89
90
  ```
90
91
 
91
92
  Typical output:
@@ -94,20 +95,19 @@ Typical output:
94
95
  [["closed-union",[["nil",1],["cons",2]]],["closed-product",[]],["closed-product",[["car",3],["cdr",0]]],["closed-union",[["_",1],["0",3],["1",3]]]]
95
96
  ```
96
97
 
97
- ## Patterns in the Codec
98
+ ## Schemas in the Codec
98
99
 
99
100
  The active wire format is:
100
101
 
101
102
  ```text
102
- encode($pattern_value : $pattern) encode(value : decoded_pattern)
103
+ encode(schema_value : schema) encode(payload : decoded_schema)
103
104
  ```
104
105
 
105
106
  So the property-list array printed by `patterns/from-k.mjs` is a
106
- readable externalization of the same pattern information carried in the
107
+ readable externalization of the same schema information carried in the
107
108
  wire stream.
108
109
 
109
- `k-parse --input-pattern ...` and `k-parse --input-type ...` both
110
- ultimately produce the same kind of root pattern used to interpret
110
+ `k-parse --input-pattern ...` produces the root schema used to interpret
111
111
  textual values.
112
112
 
113
113
  ## See Also
@@ -243,7 +243,7 @@ PolyVal(P) = { (P, (T, t)) : T ⊨ P and t ∈ Tree(T) }.
243
243
  In the current JavaScript implementation, this semantic pair is represented
244
244
  directly in memory: `Product` and `Variant` carry the witness tree, and every
245
245
  `Value` may also carry the root pattern as `value.pattern`. The codec stream is
246
- the serialized form of the same object: an encoded `$pattern` value followed by
246
+ the serialized form of the same object: an encoded `pattern` value followed by
247
247
  the value payload interpreted under that pattern.
248
248
 
249
249
  So a pattern does not denote a set of raw trees.
package/DOCS/REPL.md CHANGED
@@ -7,7 +7,7 @@ The interpreter keeps a live `.klib`-style state in memory:
7
7
 
8
8
  - registered codes
9
9
  - compiled relations
10
- - human aliases for both
10
+ - human aliases for relations
11
11
  - metadata origins used to recover aliases
12
12
  - the current value flowing through the session
13
13
 
@@ -33,14 +33,10 @@ is complete.
33
33
  | Command | Meaning |
34
34
  | --- | --- |
35
35
  | `:help` | Show command summary |
36
- | `:engine [wasm\|js]` | Display or switch evaluation engine (`wasm` or `js`) |
36
+ | `:engine [wasm|js]` | Display or switch evaluation engine (`wasm` or `js`) |
37
37
  | `:wasm` / `:js` | Shortcut to switch engine |
38
38
  | `:rel name` | Show relation definition |
39
- | `:type name` | Show the canonical definition of a type |
40
- | `:types` | List type aliases |
41
39
  | `:rels` | List relation aliases |
42
- | `:code name` | Alias for `:C name` |
43
- | `:C name` | Show canonical code definition |
44
40
  | `:codec load file` | Load a codec from an ES module file (e.g. `:codec load codecs/int.mjs`) |
45
41
  | `:codec unload name` | Unload a registered codec |
46
42
  | `:codec list` | List loaded REPL codecs (alias: `:codecs`) |
@@ -62,13 +58,12 @@ Examples:
62
58
  ```
63
59
 
64
60
  ```k
65
- > $ bool = <{} true, {} false>;
61
+ > bool = ?<{} true, {} false>;
66
62
  ```
67
63
 
68
64
  ```k
69
- > $ bool = <{} true, {} false>
70
- ; not = $bool </true | false, {} | true >
71
- ; {} |true not
65
+ > not = ?<{} true, {} false> < /true | false, /false | true >;
66
+ {} |true not
72
67
  ```
73
68
 
74
69
  The interpreter uses these rules, in order:
@@ -95,9 +90,7 @@ growing the live library context.
95
90
 
96
91
  The interpreter keeps:
97
92
 
98
- - `codes`: canonical code definitions
99
93
  - `rels`: canonical compiled relations
100
- - `typeAliases`: human type names to canonical hashes
101
94
  - `relAliases`: human relation names to canonical hashes
102
95
  - `value`: current value, initially `{}`
103
96
 
@@ -113,12 +106,12 @@ Before compiling user input, the interpreter injects an alias preamble
113
106
  so human names can be reused naturally:
114
107
 
115
108
  ```k
116
- $ nat = @...;
109
+ nat = @...;
117
110
  succ = @...;
118
111
  <user snippet>
119
112
  ```
120
113
 
121
- Type aliases use `$ name = @hash;`. Relation aliases use `name = @hash;`.
114
+ Relation aliases use `name = @hash;`.
122
115
 
123
116
  Diagnostic locations are remapped back to the visible user snippet, so
124
117
  error line numbers do not count the hidden preamble.
@@ -129,12 +122,9 @@ Tab completion covers:
129
122
 
130
123
  - command names after `:`
131
124
  - file paths for `:load`, `:klib`, and `:ko`
132
- - type aliases
133
125
  - relation aliases
134
126
  - canonical names beginning with `@`
135
127
 
136
- Type aliases also complete in `$name` position inside raw k input.
137
-
138
128
  For codec commands, completion covers `:codec load`, `:codec unload`,
139
129
  `:codec list`, file paths after `:codec load`, and codec names after
140
130
  `:input`.
@@ -157,7 +147,7 @@ aliases, and metadata into the session. Aliases are recovered from
157
147
 
158
148
  In `k`, there are no primitive numbers or built-in numerical literals.
159
149
  Values such as integers are represented as algebraic bit trees (e.g.
160
- `$bits = < {} _, bits 0, bits 1 >`).
150
+ `bits = ?< {} _, B 0, B 1 > = B;`).
161
151
 
162
152
  A codec translates between external text and enveloped *k* values:
163
153
  - `parse(text)`: parses an external string into an enveloped *k* value.
@@ -319,7 +309,7 @@ Evaluated values print in k syntax together with the inferred envelope:
319
309
  ## Example Session
320
310
 
321
311
  ```text
322
- > $ nat = < {} 0, nat +1 >;
312
+ > nat = ?< {} 0, N +1 > = N;
323
313
  > inc = | +1;
324
314
  > {} | 0
325
315
  {}|0 ?<{} 0, ...>
@@ -142,19 +142,13 @@ out(f) = LOOKUP(out(f))
142
142
  Once the type derivation for the defining expression for `f` is done, the
143
143
  input and output patterns are stored and will be used.
144
144
 
145
- ### Type `$ T`
146
-
147
- ```text
148
- in(T) = out(T) = pattern(T)
149
- ```
150
-
151
145
  ### Filter `? F`
152
146
 
153
147
  ```text
154
- see patterns.filterToPattern(F)
148
+ in(? F) = out(? F) = pattern(F)
155
149
  ```
156
150
 
157
- A filter expression is syntax for describing pattern graphs.
151
+ A filter expression `? F` describes pattern graphs, acting as an identity filter that constrains inputs and outputs to pattern `F`.
158
152
 
159
153
  ## 6. Global Algorithm
160
154
 
@@ -16,7 +16,7 @@ The scope encompasses four primary objectives:
16
16
  3. **Curate VFS Files**: Restrict the bundled Virtual File System (VFS) to verified, useful `.k` files (`core.k`, `Examples/arithmetics.k`, `Examples/ieee.k`, `Examples/poly.k`), auditing and verifying types used by REPL codecs.
17
17
  4. **Automatic Dependency Loading & Type Aliasing for Codecs**:
18
18
  - Automatically load the required `.k` source file whenever a codec is loaded, ensuring that necessary type aliases, canonical codes, and operational relations are present before the user attempts `:input` or evaluations.
19
- - Establish bidirectional type alias naming so codec names are direct aliases to the underlying type hashes (e.g. `$ieee` and `$float64` both point to `@AR4s...`, `$utf8` and `$string` both point to `@Pt3Mw...`, and `$int` points to `@Nws3v...`).
19
+ - Establish bidirectional type alias naming so codec names are direct aliases to the underlying type hashes (e.g. `ieee` and `float64` both point to `@AR4s...`, `utf8` and `string` both point to `@Pt3Mw...`, and `int` points to `@Nws3v...`).
20
20
 
21
21
  ---
22
22
 
@@ -57,7 +57,7 @@ The scope encompasses four primary objectives:
57
57
  #### Requirements
58
58
  1. **Dropdown Ordering**: In `#example-select`, `core.k` must be the top-most option under standard examples.
59
59
  2. **Onboarding Banner**: The welcome message and quick-start hints in `browser/repl-browser.mjs` must showcase `:load core.k` as the primary recommended action.
60
- 3. **Quick Expressions**: Ensure the quick expressions section provides expressions compatible with `core.k` out-of-the-box (e.g. `1 succ`, `10`, `$bits`, `$string`).
60
+ 3. **Quick Expressions**: Ensure the quick expressions section provides expressions compatible with `core.k` out-of-the-box (e.g. `1 succ`, `10`, `bits`, `string`).
61
61
 
62
62
  ---
63
63
 
@@ -65,9 +65,9 @@ The scope encompasses four primary objectives:
65
65
 
66
66
  #### Curated File Set
67
67
  The bundled VFS and UI examples must include only verified useful files:
68
- - `core.k` — The foundational standard library (bits, arithmetic on bits, Unicode `$unicode`, `$string`, `$pattern`).
69
- - `Examples/arithmetics.k` — Arbitrary-precision signed integers (`$int`), rationals (`$rat`), GCD/LCM, factorial, Fibonacci.
70
- - `Examples/ieee.k` — IEEE-754 double-precision floating point type (`$float64`) and arithmetic operations.
68
+ - `core.k` — The foundational standard library (bits, arithmetic on bits, Unicode `unicode`, `string`, `pattern`).
69
+ - `Examples/arithmetics.k` — Arbitrary-precision signed integers (`int`), rationals (`rat`), GCD/LCM, factorial, Fibonacci.
70
+ - `Examples/ieee.k` — IEEE-754 double-precision floating point type (`float64`) and arithmetic operations.
71
71
  - `Examples/poly.k` — Polymorphic list functions (`concat`, `reverse`, `length`, `get_nth`, `split_by`, `take`, `drop`, `zip`).
72
72
 
73
73
  #### Dependency Management for `poly.k`
@@ -93,13 +93,13 @@ The bundled VFS and UI examples must include only verified useful files:
93
93
  Establish code aliasing so that codec names and their standard type names are both valid aliases pointing to the same canonical type hash:
94
94
  - **IEEE / Float64**:
95
95
  - Canonical Hash: `@AR4sFGMwXgjj5p7dhi8sJKDWNbrXxLefQUCBRNm5fP6t`
96
- - Aliases: `$float64` and `$ieee`
96
+ - Aliases: `float64` and `ieee`
97
97
  - **UTF-8 / String**:
98
98
  - Canonical Hash: `@Pt3MwQwzUPxQKu58zXR3qUBHWTzfycx5bSZGzcK6EZQK`
99
- - Aliases: `$string` and `$utf8`
99
+ - Aliases: `string` and `utf8`
100
100
  - **Int**:
101
101
  - Canonical Hash: `@Nws3vysWqC9PznraTP4kWPp44Rd77NAqrx9dgbtHAjGA`
102
- - Alias: `$int`
102
+ - Alias: `int`
103
103
  This guarantees that both `:input utf8` and `:input string`, as well as `:input ieee` and `:input float64`, work seamlessly.
104
104
 
105
105
  3. **Idempotence**:
@@ -33,19 +33,16 @@ We call such mappings **partial functions**.
33
33
 
34
34
  ## **1.4 Simplicity over features**
35
35
 
36
- `k` avoids most language constructs: no *variables* and no *control statements*.
37
- It has only:
36
+ `k` avoids most traditional language constructs: no *variables*, no *loops*, and no *control flow keywords*.
37
+ In `k`, programs are built from:
38
38
 
39
- 1. **types** (which describe tree shapes), and
40
- 2. **partial functions** (which transform one tree into another).
39
+ 1. **schemas** (finite tree automata describing acceptable tree payloads), and
40
+ 2. **relations** (partial mappings that transform one tree into another).
41
41
 
42
- These two ingredients are sufficient and powerful enough to express structured
43
- computation in a concise and understandable way.
42
+ Schemas and transformations share the exact same syntax: a schema definition is simply a relation acting as a partial identity.
44
43
 
45
- There is another concept in the language, called **filters**.
46
- Filters play a role in the process of reasoning about types of partial functions.
47
- Filters have been added to the syntax of the language because they allow explicit annotations
48
- of "polymorphic" expressions, i.e., expressions that make sense in different contexts.
49
- Filters are similar to *type classes* in other languages.
44
+ The language also provides **filters** (`?schema`). Syntactically, a filter acts as a partial identity relation on payloads conforming to the schema. Semantically, filters act as **inductive termination witnesses** during contract derivation for recursive relations, while also enabling polymorphic generic programming.
45
+
46
+ When analyzing a relation, the compiler derives its **contract**: a connected $(input, output)$ schema graph where shared vertices ($=X$) prove structure preservation from input through to output.
50
47
 
51
48
  ---
@@ -3,33 +3,33 @@
3
3
  ## **2.1 Language fragments**
4
4
 
5
5
  The `k` language has only one kind of program element: a **definition**.
6
- A program is a sequence of definitions of two kinds:
6
+ A program is a sequence of definitions:
7
7
 
8
8
  ```k-lang
9
- $ type_name = ...type_expression... ;
10
- function_name = ...expression... ;
9
+ relation_name = ...expression... ;
11
10
  ```
12
11
 
13
12
  The definitions are followed in the file by the *main expression*, which represents the partial function defined by the program as a whole.
13
+ There is no separate syntax for type declarations. Data shapes are defined by the relations and pattern filters (`? ...`) that manipulate them.
14
14
 
15
15
  There is no syntax for values.
16
16
  Every syntactic form in an expression describes a **function** -- possibly a constant function that always returns the same value.
17
17
 
18
18
  ---
19
19
 
20
- ## **2.2 Types**
20
+ ## **2.2 Schemas**
21
21
 
22
- A type describes the possible **tree shapes** of values.
23
- Types are formed from two constructors:
22
+ A schema describes the possible **tree shapes** of payload values.
23
+ Schemas are formed from two constructors:
24
24
 
25
- 1. **Product** – written `{ T₁ l₁, T₂ l₂, … }`
25
+ 1. **Product** – written `{ S₁ l₁, S₂ l₂, … }`
26
26
  represents records with fixed labeled fields.
27
27
 
28
- 2. **Union** – written `< T₁ l₁, T₂ l₂, … >`
28
+ 2. **Union** – written `< S₁ l₁, S₂ l₂, … >`
29
29
  represents a choice between labeled alternatives.
30
30
 
31
31
  Both are finite and fully explicit.
32
- Every type denotes a finite tree automaton whose accepted trees are the possible values of that type.
32
+ Every schema denotes a finite tree automaton whose accepted trees are the possible payload values of that schema.
33
33
 
34
34
  ---
35
35
 
@@ -37,12 +37,12 @@ Every type denotes a finite tree automaton whose accepted trees are the possible
37
37
 
38
38
  1. **Empty product**
39
39
  `{}` has no fields.
40
- It represents the type that admits exactly one value, called *unit*.
41
- There is nothing exceptional about the type and its value; it is simply the degenerate case of a product with zero fields.
40
+ It represents the unit schema that admits exactly one value, called *unit*.
41
+ There is nothing exceptional about the unit schema and its value; it is simply the degenerate case of a product with zero fields.
42
42
 
43
43
  2. **Empty union**
44
44
  `<>` has no variants.
45
- It represents a type with no possible values.
45
+ It represents a schema with no possible values.
46
46
 
47
47
  ---
48
48
 
@@ -92,20 +92,19 @@ It is important to notice that after the three markers `dot (.)`, `div (/)`, or
92
92
  ## **2.6 Example**
93
93
 
94
94
  ```k-lang
95
- $ bool = < {} true, {} false >;
96
- true = {} |true $ bool;
97
- false = {} |false $ bool;
98
- neg = $ bool < /true false, /false true >;
95
+ true = {} |true;
96
+ false = {} |false;
97
+ neg = < /true false, /false true >;
99
98
  ```
100
99
 
101
- This defines a "two-variant" union type and three functions: two constants and one transformation exchanging the variants.
100
+ This defines three relations: two constants and one transformation exchanging the variants `/true` and `/false`. The contracts of their inputs and outputs are derived automatically by the compiler.
102
101
 
103
102
  ---
104
103
 
105
104
  ## **2.7 Summary**
106
105
 
107
- * All types describe tree shapes.
108
- * As a type expression, `{}` is the empty product type (with one value, called *unit*).
109
- * Functions, not values, are the only expressions in `k`.
106
+ * All schemas describe payload tree shapes.
107
+ * As an expression, `{}` is the empty product (with one value, called *unit*).
108
+ * Relations, not values, are the only expressions in `k`.
110
109
 
111
110
  ---