lawspec 0.25.0 → 0.26.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 (149) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/README.md +5 -4
  3. package/api.mjs +0 -8
  4. package/bin/lawspec.mjs +14 -52
  5. package/build.json +77 -105
  6. package/core.wasm +2 -2
  7. package/core_jsffi.js +5 -0
  8. package/examples/native-payments/clojure/lawspec.json +1 -1
  9. package/examples/native-payments/csharp/lawspec.json +1 -1
  10. package/examples/native-payments/elixir/lawspec.json +1 -1
  11. package/examples/native-payments/erlang/lawspec.json +1 -1
  12. package/examples/native-payments/fsharp/lawspec.json +1 -1
  13. package/examples/native-payments/gleam/lawspec.json +1 -1
  14. package/examples/native-payments/go/lawspec.json +1 -1
  15. package/examples/native-payments/groovy/lawspec.json +1 -1
  16. package/examples/native-payments/haskell/lawspec.json +1 -1
  17. package/examples/native-payments/java/lawspec.json +1 -1
  18. package/examples/native-payments/javascript/lawspec.json +1 -1
  19. package/examples/native-payments/kotlin/lawspec.json +1 -1
  20. package/examples/native-payments/python/lawspec.json +1 -1
  21. package/examples/native-payments/rust/lawspec.json +1 -1
  22. package/examples/native-payments/scala/lawspec.json +1 -1
  23. package/examples/native-payments/swift/lawspec.json +1 -1
  24. package/examples/native-payments/typescript/lawspec.json +1 -1
  25. package/examples/packages/orders/lawspec.json +1 -1
  26. package/examples/packages/orders/orders.lawspec +27 -25
  27. package/examples/packages/shop-domain/src/domain.lawspec +15 -14
  28. package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
  29. package/examples/packages/shop-tax-1/src/rates.lawspec +1 -0
  30. package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
  31. package/examples/packages/shop-tax-2/src/rates.lawspec +1 -0
  32. package/examples/rc1/authorization-snapshots.lawspec +24 -23
  33. package/examples/rc1/banner-filenames.lawspec +7 -6
  34. package/examples/rc1/bit-codec.lawspec +12 -11
  35. package/examples/rc1/bounded-witness-search.lawspec +52 -45
  36. package/examples/rc1/conflicting-requirements.lawspec +8 -7
  37. package/examples/rc1/constructive-witnesses.lawspec +40 -33
  38. package/examples/rc1/documentary-review.lawspec +9 -8
  39. package/examples/rc1/empty-domains.lawspec +16 -15
  40. package/examples/rc1/finite-integer-domains.lawspec +24 -23
  41. package/examples/rc1/law-metadata.lawspec +6 -5
  42. package/examples/rc1/native-payments.lawspec +17 -16
  43. package/examples/rc1/nesting/rrr.lawspec +4 -3
  44. package/examples/rc1/nesting/rru.lawspec +7 -6
  45. package/examples/rc1/nesting/rur.lawspec +7 -6
  46. package/examples/rc1/nesting/ruu.lawspec +10 -9
  47. package/examples/rc1/nesting/urr.lawspec +7 -6
  48. package/examples/rc1/nesting/uru.lawspec +10 -9
  49. package/examples/rc1/nesting/uur.lawspec +10 -9
  50. package/examples/rc1/nesting/uuu.lawspec +13 -12
  51. package/examples/rc1/order-workflow.lawspec +18 -17
  52. package/examples/rc1/parcel-measurements.lawspec +14 -13
  53. package/examples/rc1/picture-records.lawspec +6 -5
  54. package/examples/rc1/picture-tuples.lawspec +6 -5
  55. package/examples/rc1/record-payloads.lawspec +12 -11
  56. package/examples/rc1/recursive-records.lawspec +11 -10
  57. package/examples/rc1/refund-conformance.lawspec +7 -6
  58. package/examples/rc1/refund-policy.lawspec +15 -14
  59. package/examples/rc1/requirement-composition.lawspec +26 -25
  60. package/examples/rc1/structural-records.lawspec +13 -12
  61. package/examples/rc1-authoring.lawspec +6 -5
  62. package/examples/specs/abilities.lawspec +67 -65
  63. package/examples/specs/ability_imports.lawspec +58 -57
  64. package/examples/specs/actors.lawspec +23 -22
  65. package/examples/specs/algebra.lawspec +142 -141
  66. package/examples/specs/approvals.lawspec +16 -15
  67. package/examples/specs/async_bindings.lawspec +10 -9
  68. package/examples/specs/async_fetch.lawspec +12 -11
  69. package/examples/specs/atoi_codec.lawspec +16 -15
  70. package/examples/specs/boolean_flags.lawspec +10 -9
  71. package/examples/specs/builtins.lawspec +73 -72
  72. package/examples/specs/canonical_url.lawspec +14 -13
  73. package/examples/specs/collections.lawspec +153 -154
  74. package/examples/specs/composition.lawspec +70 -66
  75. package/examples/specs/concurrent_collections.lawspec +8 -7
  76. package/examples/specs/consistency.lawspec +4 -3
  77. package/examples/specs/contracts.lawspec +80 -79
  78. package/examples/specs/crypto.lawspec +26 -25
  79. package/examples/specs/ctc.lawspec +148 -0
  80. package/examples/specs/currying.lawspec +32 -31
  81. package/examples/specs/data_types.lawspec +50 -49
  82. package/examples/specs/distribution.lawspec +57 -56
  83. package/examples/specs/domain_modeling.lawspec +48 -47
  84. package/examples/specs/durations.lawspec +39 -38
  85. package/examples/specs/equivalent.lawspec +25 -24
  86. package/examples/specs/failures.lawspec +64 -63
  87. package/examples/specs/finite_data.lawspec +32 -31
  88. package/examples/specs/flow_stack.lawspec +64 -63
  89. package/examples/specs/gadt_expressions.lawspec +50 -49
  90. package/examples/specs/generation.lawspec +115 -114
  91. package/examples/specs/handler_bindings.lawspec +42 -40
  92. package/examples/specs/handles.lawspec +2 -1
  93. package/examples/specs/harness.lawspec +45 -43
  94. package/examples/specs/harness_testing.lawspec +18 -13
  95. package/examples/specs/indexed_arithmetic.lawspec +401 -126
  96. package/examples/specs/indexed_families.lawspec +182 -66
  97. package/examples/specs/keywords.lawspec +22 -21
  98. package/examples/specs/limits.lawspec +6 -5
  99. package/examples/specs/list_contracts.lawspec +121 -120
  100. package/examples/specs/list_refinements.lawspec +43 -42
  101. package/examples/specs/lists.lawspec +45 -44
  102. package/examples/specs/matchers.lawspec +79 -78
  103. package/examples/specs/matching.lawspec +43 -42
  104. package/examples/specs/mixed_inputs.lawspec +25 -24
  105. package/examples/specs/models.lawspec +44 -43
  106. package/examples/specs/parse_port.lawspec +28 -27
  107. package/examples/specs/payments.lawspec +55 -54
  108. package/examples/specs/railway.lawspec +59 -58
  109. package/examples/specs/records.lawspec +149 -148
  110. package/examples/specs/records_inner.lawspec +5 -4
  111. package/examples/specs/recursive_refinements.lawspec +30 -29
  112. package/examples/specs/refined_definitions.lawspec +24 -23
  113. package/examples/specs/refinements.lawspec +58 -57
  114. package/examples/specs/resilience.lawspec +159 -158
  115. package/examples/specs/resources.lawspec +61 -60
  116. package/examples/specs/scalar_adapters.lawspec +60 -59
  117. package/examples/specs/scalar_catalog.lawspec +165 -164
  118. package/examples/specs/scalars.lawspec +78 -77
  119. package/examples/specs/scheduling_order.lawspec +8 -7
  120. package/examples/specs/scheduling_overlap.lawspec +5 -4
  121. package/examples/specs/sequences.lawspec +66 -65
  122. package/examples/specs/sessions.lawspec +13 -12
  123. package/examples/specs/slug.lawspec +16 -15
  124. package/examples/specs/sum_refinements.lawspec +42 -41
  125. package/examples/specs/tables.lawspec +29 -28
  126. package/examples/specs/total_functions.lawspec +71 -70
  127. package/examples/specs/workflows.lawspec +101 -100
  128. package/examples-command.mjs +4 -6
  129. package/explain.mjs +6 -4
  130. package/expression-presentation.mjs +8 -8
  131. package/files.mjs +1 -1
  132. package/index.d.ts +4 -527
  133. package/launcher.mjs +9 -2
  134. package/lsp.mjs +10 -6
  135. package/native-examples.mjs +2 -2
  136. package/package.json +1 -1
  137. package/starter-rc1.lawspec +6 -5
  138. package/starter.lawspec +16 -15
  139. package/templates.mjs +4 -2
  140. package/migrate.mjs +0 -135
  141. package/migration-bindings.mjs +0 -86
  142. package/migration-cases.mjs +0 -45
  143. package/migration-collections.mjs +0 -54
  144. package/migration-correspondence.mjs +0 -275
  145. package/migration-generation.mjs +0 -99
  146. package/migration-laws.mjs +0 -102
  147. package/migration-records.mjs +0 -166
  148. package/migration-source.mjs +0 -247
  149. package/migration-write.mjs +0 -156
@@ -2,19 +2,20 @@ unit example.indexed
2
2
 
3
3
  -- A list indexed by its length. Each constructor states how it changes the
4
4
  -- index; nOfVec is the checked measure that recomputes it from a value.
5
- type Vec (n :: Natural) (a :: Type) is
5
+ type Vec (n :: Whole) (a :: Type) is one of
6
6
  | VNil where n = 0
7
- | VCons head :: a tail :: Vec m a where n = m + 1
8
- end
7
+ | VCons of type record{ head :: a tail :: Vec m a} where n = m + 1
8
+ end type
9
9
 
10
10
  -- A binary tree indexed by its number of values.
11
- type Tree (n :: Natural) (a :: Type) is
11
+ type Tree (n :: Whole) (a :: Type) is one of
12
12
  | Tip where n = 0
13
- | Bin left :: Tree l a value :: a right :: Tree r a where n = l + r + 1
14
- end
13
+ | Bin of type record{ left :: Tree l a value :: a right :: Tree r a} where n =
14
+ l + r + 1
15
+ end type
15
16
 
16
17
  -- Result indices are checked contracts over the native implementations.
17
- replicate :: (n :: Natural where n < 64) -> (x :: Int8) -> (r :: Vec n Int8)
18
+ replicate :: (n :: Whole where n < 64) -> (x :: Int8) -> (r :: Vec n Int8)
18
19
  append :: (xs :: Vec n Int8) -> (ys :: Vec m Int8) -> (r :: Vec (n + m) Int8)
19
20
  zip :: (xs :: Vec n Int8) -> (ys :: Vec n Bool) -> (r :: Vec n Bool)
20
21
  flatten :: (tree :: Tree n Int8) -> (r :: Vec n Int8)
@@ -22,67 +23,182 @@ flatten :: (tree :: Tree n Int8) -> (r :: Vec n Int8)
22
23
  -- Checked definitions whose result indices are proved statically, by
23
24
  -- structural induction over the constructor equations. They need no runtime
24
25
  -- postcondition, and serve as reference models for the native adapters.
25
- definition concatV (xs :: Vec n Int8) (ys :: Vec m Int8) :: Vec (n + m) Int8 is
26
- match xs with
27
- | VNil -> ys
28
- | VCons h t -> VCons h (concatV t ys)
29
- end
30
- end
31
-
32
- definition flattenV (tree :: Tree n Int8) :: Vec n Int8 is
33
- match tree with
34
- | Tip -> VNil
35
- | Bin l v r -> concatV (flattenV l) (VCons v (flattenV r))
36
- end
37
- end
38
-
39
- law `append agrees with the proved definition` is
40
- definition is
41
- `for all` (xs :: Vec n Int8) (ys :: Vec m Int8) . append xs ys = concatV xs ys
42
- end
43
- end
44
-
45
- law `flatten agrees with the proved definition` is
46
- definition is
47
- `for all` (tree :: Tree 4 Int8) . flatten tree = flattenV tree
48
- end
49
- end
50
-
51
- law `replicate has the requested length` is
52
- definition is
53
- `for all` (n :: Natural where n < 16) (x :: Int8) . nOfVec (replicate n x) = n
54
- end
55
- example `three copies` is
26
+ function concatV (xs :: Vec n Int8) (ys :: Vec m Int8) -> Vec (n + m) Int8 is
27
+ first matching case of xs :
28
+ when VNil then ys
29
+ when VCons record{ head = h , tail = t} then VCons record{ head = h , tail =
30
+ (concatV t ys)}
31
+ end case
32
+ end function
33
+
34
+ function flattenV (tree :: Tree n Int8) -> Vec n Int8 is
35
+ first matching case of tree :
36
+ when Tip then VNil
37
+ when Bin record{ left = l , value = v , right = r} then concatV (flattenV l)
38
+ (VCons record{ head = v , tail = (flattenV r)})
39
+ end case
40
+ end function
41
+
42
+ law "|append agrees with the proved definition| is
43
+ definition :
44
+ for all (xs :: Vec n Int8) (ys :: Vec m Int8) => append xs ys = concatV xs
45
+ ys end for all
46
+ end definition
47
+ end law
48
+
49
+ law "|flatten agrees with the proved definition| is
50
+ definition :
51
+ for all (tree :: Tree 4 Int8) => flatten tree = flattenV tree end for all
52
+ end definition
53
+ end law
54
+
55
+ law "|replicate has the requested length| is
56
+ definition :
57
+ for all (n :: Whole where n < 16) (x :: Int8) => nOfVec (replicate n x) = n
58
+ end for all
59
+ end definition
60
+ example "|three copies| :
56
61
  n = 3
57
62
  x = 7
58
63
  expect nOfVec (replicate n x) = 3
59
- end
60
- end
61
-
62
- law `append adds lengths` is
63
- definition is
64
- `for all` (xs :: Vec n Int8) (ys :: Vec m Int8) .
65
- nOfVec (append xs ys) = n + m
66
- end
67
- end
68
-
69
- -- A fixed index is generated directly rather than filtered.
70
- law `vectors of three elements` is
71
- definition is
72
- `for all` (xs :: Vec 3 Int8) . nOfVec (append xs xs) = 6
73
- end
74
- end
64
+ end example
65
+ end law
66
+
67
+ law "|append adds lengths| is
68
+ definition :
69
+ for all (xs :: Vec n Int8) (ys :: Vec m Int8) =>
70
+ nOfVec (append xs ys) = n + m end for all
71
+ end definition
72
+ end law
73
+
74
+ -- The harness constructs the fixed shape with independent scalar draws.
75
+ law "|vectors of three elements| is
76
+ definition :
77
+ for all (xs :: Vec 3 Int8) => nOfVec (append xs xs) = 6 end for all
78
+ end definition
79
+ end law
75
80
 
76
81
  -- A shared index constrains the second input by the first.
77
- law `zip preserves a shared length` is
78
- definition is
79
- `for all` (xs :: Vec n Int8) (ys :: Vec n Bool) . nOfVec (zip xs ys) = n
80
- end
81
- end
82
-
83
- -- Generation splits the remaining index across both subtrees.
84
- law `flattening five values` is
85
- definition is
86
- `for all` (tree :: Tree 5 Int8) . nOfVec (flatten tree) = 5
87
- end
88
- end
82
+ law "|zip preserves a shared length| is
83
+ definition :
84
+ for all (xs :: Vec n Int8) (ys :: Vec n Bool) => nOfVec (zip xs ys) = n
85
+ end for all
86
+ end definition
87
+ end law
88
+
89
+ -- The harness samples every binary shape of this fixed size.
90
+ law "|flattening five values| is
91
+ definition :
92
+ for all (tree :: Tree 5 Int8) => nOfVec (flatten tree) = 5 end for all
93
+ end definition
94
+ end law
95
+
96
+ function branch (left of type Tree n Int8) (item of type Int8)
97
+ (right of type Tree m Int8) -> Tree (n + m + 1) Int8 is
98
+ Bin record{left = left, value = item, right = right}
99
+ end function
100
+
101
+ harness example.indexed.shapes for example.indexed is
102
+
103
+ strategy threeValues of type Vec 3 Int8 is
104
+ bind value0 of type Int8 from any in
105
+ bind value1 of type Int8 from any in
106
+ bind value2 of type Int8 from any in
107
+ one of (VCons record{head = value0, tail = (VCons record{head = value1, tail = (VCons record{head = value2, tail = VNil})})})
108
+ end bind
109
+ end bind
110
+ end bind
111
+ end strategy
112
+
113
+ strategy tree4 of type Tree 4 Int8 is
114
+ bind value0 of type Int8 from any in
115
+ bind value1 of type Int8 from any in
116
+ bind value2 of type Int8 from any in
117
+ bind value3 of type Int8 from any in
118
+ one of (branch Tip value0 (branch Tip value1 (branch Tip value2 (branch Tip value3 Tip)))),
119
+ (branch Tip value0 (branch Tip value1 (branch (branch Tip value3 Tip) value2 Tip))),
120
+ (branch Tip value0 (branch (branch Tip value2 Tip) value1 (branch Tip value3 Tip))),
121
+ (branch Tip value0 (branch (branch Tip value2 (branch Tip value3 Tip)) value1 Tip)),
122
+ (branch Tip value0 (branch (branch (branch Tip value3 Tip) value2 Tip) value1 Tip)),
123
+ (branch (branch Tip value1 Tip) value0 (branch Tip value2 (branch Tip value3 Tip))),
124
+ (branch (branch Tip value1 Tip) value0 (branch (branch Tip value3 Tip) value2 Tip)),
125
+ (branch (branch Tip value1 (branch Tip value2 Tip)) value0 (branch Tip value3 Tip)),
126
+ (branch (branch (branch Tip value2 Tip) value1 Tip) value0 (branch Tip value3 Tip)),
127
+ (branch (branch Tip value1 (branch Tip value2 (branch Tip value3 Tip))) value0 Tip),
128
+ (branch (branch Tip value1 (branch (branch Tip value3 Tip) value2 Tip)) value0 Tip),
129
+ (branch (branch (branch Tip value2 Tip) value1 (branch Tip value3 Tip)) value0 Tip),
130
+ (branch (branch (branch Tip value2 (branch Tip value3 Tip)) value1 Tip) value0 Tip),
131
+ (branch (branch (branch (branch Tip value3 Tip) value2 Tip) value1 Tip) value0 Tip)
132
+ end bind
133
+ end bind
134
+ end bind
135
+ end bind
136
+ end strategy
137
+
138
+ strategy tree5 of type Tree 5 Int8 is
139
+ bind value0 of type Int8 from any in
140
+ bind value1 of type Int8 from any in
141
+ bind value2 of type Int8 from any in
142
+ bind value3 of type Int8 from any in
143
+ bind value4 of type Int8 from any in
144
+ one of (branch Tip value0 (branch Tip value1 (branch Tip value2 (branch Tip value3 (branch Tip value4 Tip))))),
145
+ (branch Tip value0 (branch Tip value1 (branch Tip value2 (branch (branch Tip value4 Tip) value3 Tip)))),
146
+ (branch Tip value0 (branch Tip value1 (branch (branch Tip value3 Tip) value2 (branch Tip value4 Tip)))),
147
+ (branch Tip value0 (branch Tip value1 (branch (branch Tip value3 (branch Tip value4 Tip)) value2 Tip))),
148
+ (branch Tip value0 (branch Tip value1 (branch (branch (branch Tip value4 Tip) value3 Tip) value2 Tip))),
149
+ (branch Tip value0 (branch (branch Tip value2 Tip) value1 (branch Tip value3 (branch Tip value4 Tip)))),
150
+ (branch Tip value0 (branch (branch Tip value2 Tip) value1 (branch (branch Tip value4 Tip) value3 Tip))),
151
+ (branch Tip value0 (branch (branch Tip value2 (branch Tip value3 Tip)) value1 (branch Tip value4 Tip))),
152
+ (branch Tip value0 (branch (branch (branch Tip value3 Tip) value2 Tip) value1 (branch Tip value4 Tip))),
153
+ (branch Tip value0 (branch (branch Tip value2 (branch Tip value3 (branch Tip value4 Tip))) value1 Tip)),
154
+ (branch Tip value0 (branch (branch Tip value2 (branch (branch Tip value4 Tip) value3 Tip)) value1 Tip)),
155
+ (branch Tip value0 (branch (branch (branch Tip value3 Tip) value2 (branch Tip value4 Tip)) value1 Tip)),
156
+ (branch Tip value0 (branch (branch (branch Tip value3 (branch Tip value4 Tip)) value2 Tip) value1 Tip)),
157
+ (branch Tip value0 (branch (branch (branch (branch Tip value4 Tip) value3 Tip) value2 Tip) value1 Tip)),
158
+ (branch (branch Tip value1 Tip) value0 (branch Tip value2 (branch Tip value3 (branch Tip value4 Tip)))),
159
+ (branch (branch Tip value1 Tip) value0 (branch Tip value2 (branch (branch Tip value4 Tip) value3 Tip))),
160
+ (branch (branch Tip value1 Tip) value0 (branch (branch Tip value3 Tip) value2 (branch Tip value4 Tip))),
161
+ (branch (branch Tip value1 Tip) value0 (branch (branch Tip value3 (branch Tip value4 Tip)) value2 Tip)),
162
+ (branch (branch Tip value1 Tip) value0 (branch (branch (branch Tip value4 Tip) value3 Tip) value2 Tip)),
163
+ (branch (branch Tip value1 (branch Tip value2 Tip)) value0 (branch Tip value3 (branch Tip value4 Tip))),
164
+ (branch (branch Tip value1 (branch Tip value2 Tip)) value0 (branch (branch Tip value4 Tip) value3 Tip)),
165
+ (branch (branch (branch Tip value2 Tip) value1 Tip) value0 (branch Tip value3 (branch Tip value4 Tip))),
166
+ (branch (branch (branch Tip value2 Tip) value1 Tip) value0 (branch (branch Tip value4 Tip) value3 Tip)),
167
+ (branch (branch Tip value1 (branch Tip value2 (branch Tip value3 Tip))) value0 (branch Tip value4 Tip)),
168
+ (branch (branch Tip value1 (branch (branch Tip value3 Tip) value2 Tip)) value0 (branch Tip value4 Tip)),
169
+ (branch (branch (branch Tip value2 Tip) value1 (branch Tip value3 Tip)) value0 (branch Tip value4 Tip)),
170
+ (branch (branch (branch Tip value2 (branch Tip value3 Tip)) value1 Tip) value0 (branch Tip value4 Tip)),
171
+ (branch (branch (branch (branch Tip value3 Tip) value2 Tip) value1 Tip) value0 (branch Tip value4 Tip)),
172
+ (branch (branch Tip value1 (branch Tip value2 (branch Tip value3 (branch Tip value4 Tip)))) value0 Tip),
173
+ (branch (branch Tip value1 (branch Tip value2 (branch (branch Tip value4 Tip) value3 Tip))) value0 Tip),
174
+ (branch (branch Tip value1 (branch (branch Tip value3 Tip) value2 (branch Tip value4 Tip))) value0 Tip),
175
+ (branch (branch Tip value1 (branch (branch Tip value3 (branch Tip value4 Tip)) value2 Tip)) value0 Tip),
176
+ (branch (branch Tip value1 (branch (branch (branch Tip value4 Tip) value3 Tip) value2 Tip)) value0 Tip),
177
+ (branch (branch (branch Tip value2 Tip) value1 (branch Tip value3 (branch Tip value4 Tip))) value0 Tip),
178
+ (branch (branch (branch Tip value2 Tip) value1 (branch (branch Tip value4 Tip) value3 Tip)) value0 Tip),
179
+ (branch (branch (branch Tip value2 (branch Tip value3 Tip)) value1 (branch Tip value4 Tip)) value0 Tip),
180
+ (branch (branch (branch (branch Tip value3 Tip) value2 Tip) value1 (branch Tip value4 Tip)) value0 Tip),
181
+ (branch (branch (branch Tip value2 (branch Tip value3 (branch Tip value4 Tip))) value1 Tip) value0 Tip),
182
+ (branch (branch (branch Tip value2 (branch (branch Tip value4 Tip) value3 Tip)) value1 Tip) value0 Tip),
183
+ (branch (branch (branch (branch Tip value3 Tip) value2 (branch Tip value4 Tip)) value1 Tip) value0 Tip),
184
+ (branch (branch (branch (branch Tip value3 (branch Tip value4 Tip)) value2 Tip) value1 Tip) value0 Tip),
185
+ (branch (branch (branch (branch (branch Tip value4 Tip) value3 Tip) value2 Tip) value1 Tip) value0 Tip)
186
+ end bind
187
+ end bind
188
+ end bind
189
+ end bind
190
+ end bind
191
+ end strategy
192
+
193
+ for law "|vectors of three elements|
194
+ use threeValues for xs
195
+ end for law
196
+ for law "|flatten agrees with the proved definition|
197
+ use tree4 for tree
198
+ end for law
199
+ for law "|flattening five values|
200
+ use tree5 for tree
201
+ end for law
202
+
203
+ end harness
204
+ end unit
@@ -4,30 +4,31 @@ unit example.keywords
4
4
  -- leading underscore: short is _short in Java, lambda is _lambda in Python,
5
5
  -- and class is _class wherever class is reserved. Other targets keep the name.
6
6
 
7
- definition short (x :: BigInt) :: Bool is x < 10 end
8
- definition double (x :: BigInt) :: BigInt is x + x end
9
- definition lambda (x :: BigInt) :: BigInt is x + 1 end
10
- definition fun (x :: BigInt) :: BigInt is x + 2 end
11
- definition loop (x :: BigInt) :: BigInt is x + 3 end
12
- definition deriving (x :: BigInt) :: BigInt is x + 4 end
13
- definition delete (x :: BigInt) :: BigInt is x + 5 end
7
+ function short (x :: Integer) -> Bool is x < 10 end function
8
+ function double (x :: Integer) -> Integer is x + x end function
9
+ function lambda (x :: Integer) -> Integer is x + 1 end function
10
+ function fun (x :: Integer) -> Integer is x + 2 end function
11
+ function loop (x :: Integer) -> Integer is x + 3 end function
12
+ function deriving (x :: Integer) -> Integer is x + 4 end function
13
+ function delete (x :: Integer) -> Integer is x + 5 end function
14
14
 
15
15
  -- An adapter, written by hand on each target as _class or class.
16
- class :: BigInt -> BigInt
16
+ class :: Integer -> Integer
17
17
 
18
- law `keyword names are callable` is
19
- definition is
20
- `for all` (x :: BigInt) .
21
- double x - x + lambda x + fun x + loop x + deriving x + delete x = 6 * x + 15
22
- end
23
- example `short` is
18
+ law "|keyword names are callable| is
19
+ definition :
20
+ for all (x :: Integer) =>
21
+ double x - x + lambda x + fun x + loop x + deriving x + delete x = 6 * x + 15 end for all
22
+ end definition
23
+ example "|short| :
24
24
  x = 3
25
25
  expect short x = true
26
- end
27
- end
26
+ end example
27
+ end law
28
28
 
29
- law `the class adapter doubles` is
30
- definition is
31
- `for all` (x :: BigInt) . class x = double x
32
- end
33
- end
29
+ law "|the class adapter doubles| is
30
+ definition :
31
+ for all (x :: Integer) => class x = double x end for all
32
+ end definition
33
+ end law
34
+ end unit
@@ -3,14 +3,14 @@ unit example.limits
3
3
  -- A workflow with a rate limit, for the resilience suite: two calls per
4
4
  -- second, rejecting the rest. Its own unit, so the suite's checks can call it
5
5
  -- on every target (a Haskell workflow imports its steps' module).
6
- type Ticket is Ticket number :: Int64 end
6
+ type Ticket is a record{ number :: Int64} end type
7
7
 
8
8
  admitTicket :: Ticket -> Either Text Ticket
9
9
 
10
10
  workflow limited :: Ticket -> Either _ Ticket is
11
11
  admitTicket :: Ticket -> Either Text Ticket
12
12
  rateLimit tokenBucket 2 1s reject
13
- end
13
+ end workflow
14
14
 
15
15
  -- A workflow that compensates: when charging fails, the reserved seat is
16
16
  -- released.
@@ -22,7 +22,7 @@ workflow book :: Ticket -> Either _ Ticket is
22
22
  reserveSeat :: Ticket -> Either Text Ticket
23
23
  compensate releaseSeat
24
24
  chargeCard :: Ticket -> Either Text Ticket
25
- end
25
+ end workflow
26
26
 
27
27
  -- An asynchronous step within a timeout: the quote for ticket -1 is slow
28
28
  -- (600ms), so its stage times out.
@@ -31,7 +31,7 @@ async fetchQuote :: Ticket -> Either Text Ticket
31
31
  workflow quoted :: Ticket -> Either _ Ticket is
32
32
  fetchQuote :: Ticket -> Either Text Ticket
33
33
  timeout 200ms
34
- end
34
+ end workflow
35
35
 
36
36
  -- An asynchronous step with a hedge: ticket -2's first quote stalls (600ms),
37
37
  -- so a second starts after 50ms and answers first.
@@ -40,4 +40,5 @@ async hedgeQuote :: Ticket -> Either Text Ticket
40
40
  workflow hedged :: Ticket -> Either _ Ticket is
41
41
  hedgeQuote :: Ticket -> Either Text Ticket
42
42
  hedge 50ms
43
- end
43
+ end workflow
44
+ end unit
@@ -1,136 +1,137 @@
1
1
  unit example.list_contracts
2
2
 
3
- definition keep (xs :: List (value :: Int8 where value > 0))
4
- :: List (value :: Int8 where value > 0)
5
- is xs end
3
+ function keep (xs :: List (value :: Int8 where value > 0))
4
+ -> List (value :: Int8 where value > 0)
5
+ is xs end function
6
6
 
7
- definition stronger (xs :: List (value :: Int8 where value > 10)) :: List Int8 is
7
+ function stronger (xs :: List (value :: Int8 where value > 10)) -> List Int8 is
8
8
  keep (copypositive xs)
9
- end
9
+ end function
10
10
 
11
- definition positive (value :: a) :: Bool requires Integer a is value > 0 end
11
+ function positive (value :: a) -> Bool requires Integer a is value > 0 end function
12
12
 
13
- definition keephelper (xs :: List (value :: a where positive value))
14
- :: List a requires Integer a
15
- is xs end
13
+ function keephelper (xs :: List (value :: a where positive value))
14
+ -> List a requires Integer a
15
+ is xs end function
16
16
 
17
- definition reuse (xs :: List (value :: Int8 where positive value)) :: List Int8 is
17
+ function reuse (xs :: List (value :: Int8 where positive value)) -> List Int8 is
18
18
  keephelper xs
19
- end
20
-
21
- definition empty (value :: Int8) :: List (element :: Int8 where false) is [] end
22
-
23
- definition singleton (value :: Int8 where value > 0)
24
- :: List (element :: Int8 where element > 0)
25
- is [value] end
26
-
27
-
28
- law `stronger domains satisfy the callee` is
29
- definition is `for all` (xs :: List (value :: Int8 where value > 10)) .
30
- stronger xs = xs
31
- end
32
- example `positive input` is xs = [11, 127] expect stronger xs = [11, 127] end
33
- end
34
-
35
- law `generic predicates keep their scope` is
36
- definition is `for all` (xs :: List (value :: Int8 where value > 0)) .
37
- reuse xs = xs
38
- end
39
- example `empty` is xs = [] expect reuse xs = [] end
40
- example `nonempty` is xs = [1, 2] expect reuse xs = [1, 2] end
41
- end
42
-
43
- law `empty output satisfies an impossible element domain` is
44
- definition is `for all` (value :: Int8) . empty value = [] end
45
- example `zero` is value = 0 expect empty value = [] end
46
- end
47
-
48
- law `constructed output satisfies its contract` is
49
- definition is `for all` (value :: Int8 where value > 0) . singleton value = [value] end
50
- example `maximum` is value = 127 expect singleton value = [127] end
51
- end
52
-
53
-
54
- definition sumreciprocal (xs :: List (value :: Int8 where value != 0)) :: Rational is
55
- match xs with
56
- | Nil -> 0
57
- | Cons first rest -> unwrapnonzero (wrapnonzero (nonzero first)) + sumreciprocal rest
58
- end
59
- end
60
-
61
- definition sumrows (rows :: List (List (value :: Int8 where value != 0))) :: Rational is
62
- match rows with
63
- | Nil -> 0
64
- | Cons first rest -> sumreciprocal first + sumrows rest
65
- end
66
- end
67
-
68
- definition positivetail (xs :: List (value :: Int8 where value > 0))
69
- :: List (value :: Int8 where value > 0)
19
+ end function
20
+
21
+ function empty (value :: Int8) -> List (element :: Int8 where false) is [] end function
22
+
23
+ function singleton (value :: Int8 where value > 0)
24
+ -> List (element :: Int8 where element > 0)
25
+ is [value] end function
26
+
27
+
28
+ law "|stronger domains satisfy the callee| is
29
+ definition : for all (xs :: List (value :: Int8 where value > 10)) =>
30
+ stronger xs = xs end for all
31
+ end definition
32
+ example "|positive input| : xs = [11, 127] expect stronger xs = [11, 127] end example
33
+ end law
34
+
35
+ law "|generic predicates keep their scope| is
36
+ definition : for all (xs :: List (value :: Int8 where value > 0)) =>
37
+ reuse xs = xs end for all
38
+ end definition
39
+ example "|empty| : xs = [] expect reuse xs = [] end example
40
+ example "|nonempty| : xs = [1, 2] expect reuse xs = [1, 2] end example
41
+ end law
42
+
43
+ law "|empty output satisfies an impossible element domain| is
44
+ definition : for all (value :: Int8) => empty value = [] end for all end definition
45
+ example "|zero| : value = 0 expect empty value = [] end example
46
+ end law
47
+
48
+ law "|constructed output satisfies its contract| is
49
+ definition : for all (value :: Int8 where value > 0) => singleton value = [value] end for all end definition
50
+ example "|maximum| : value = 127 expect singleton value = [127] end example
51
+ end law
52
+
53
+
54
+ function sumreciprocal (xs :: List (value :: Int8 where value != 0)) -> Rational is
55
+ first matching case of xs :
56
+ when Nil then 0
57
+ when Cons first rest then unwrapnonzero (wrapnonzero (nonzero first)) + sumreciprocal rest
58
+ end case
59
+ end function
60
+
61
+ function sumrows (rows :: List (List (value :: Int8 where value != 0))) -> Rational is
62
+ first matching case of rows :
63
+ when Nil then 0
64
+ when Cons first rest then sumreciprocal first + sumrows rest
65
+ end case
66
+ end function
67
+
68
+ function positivetail (xs :: List (value :: Int8 where value > 0))
69
+ -> List (value :: Int8 where value > 0)
70
70
  is
71
- match xs with | Nil -> [] | Cons first rest -> rest end
72
- end
71
+ first matching case of xs : when Nil then [] when Cons first rest then rest end case
72
+ end function
73
73
 
74
- definition positivefirst (xs :: List (value :: Int8 where value > 0))
75
- :: (result :: Int8 where result > 0)
74
+ function positivefirst (xs :: List (value :: Int8 where value > 0))
75
+ -> (result :: Int8 where result > 0)
76
76
  is
77
- match xs with | Nil -> 1 | Cons first rest -> first end
78
- end
79
-
80
-
81
- law `reciprocal sum uses each nonzero head` is
82
- definition is `for all` (value :: Int8 where value != 0) .
83
- sumreciprocal [value] = 1 / value
84
- end
85
- example `half` is value = 2 expect sumreciprocal [value] = rational(1, 2) end
86
- end
87
-
88
- law `nested membership keeps row contracts` is
89
- definition is `for all` (value :: Int8 where value != 0) .
90
- sumrows [[], [value]] = 1 / value
91
- end
92
- example `negative half` is value = -2 expect sumrows [[], [value]] = rational(-1, 2) end
93
- end
94
-
95
- law `tail preserves its positive elements` is
96
- definition is `for all` (first :: Int8 where first > 0)
97
- (second :: Int8 where second > 0) . positivetail [first, second] = [second]
98
- end
99
- example `two values` is first = 1 second = 2 expect positivetail [first, second] = [2] end
100
- end
77
+ first matching case of xs : when Nil then 1 when Cons first rest then first end case
78
+ end function
79
+
80
+
81
+ law "|reciprocal sum uses each nonzero head| is
82
+ definition : for all (value :: Int8 where value != 0) =>
83
+ sumreciprocal [value] = 1 / value end for all
84
+ end definition
85
+ example "|half| : value = 2 expect sumreciprocal [value] = rational(1, 2) end example
86
+ end law
87
+
88
+ law "|nested membership keeps row contracts| is
89
+ definition : for all (value :: Int8 where value != 0) =>
90
+ sumrows [[], [value]] = 1 / value end for all
91
+ end definition
92
+ example "|negative half| : value = -2 expect sumrows [[], [value]] = rational(-1, 2) end example
93
+ end law
94
+
95
+ law "|tail preserves its positive elements| is
96
+ definition : for all (first :: Int8 where first > 0)
97
+ (second :: Int8 where second > 0) => positivetail [first, second] = [second] end for all
98
+ end definition
99
+ example "|two values| : first = 1 second = 2 expect positivetail [first, second] = [2] end example
100
+ end law
101
101
 
102
102
  -- Recursive calls supply their verified result contract by structural induction.
103
- definition copypositive (xs :: List (value :: Int8 where value > 0))
104
- :: List (value :: Int8 where value > 0)
103
+ function copypositive (xs :: List (value :: Int8 where value > 0))
104
+ -> List (value :: Int8 where value > 0)
105
105
  is
106
- match xs with
107
- | Nil -> []
108
- | Cons first rest -> Cons first (copypositive rest)
109
- end
110
- end
111
-
112
- definition nonzero (value :: Int8 where value != 0)
113
- :: (result :: Int8 where result != 0)
114
- is value end
115
-
116
- definition wrapnonzero (value :: Int8 where value != 0)
117
- :: Maybe (result :: Int8 where result != 0)
118
- is Just value end
119
-
120
- definition unwrapnonzero (value :: Maybe (element :: Int8 where element != 0))
121
- :: Rational
106
+ first matching case of xs :
107
+ when Nil then []
108
+ when Cons first rest then Cons first (copypositive rest)
109
+ end case
110
+ end function
111
+
112
+ function nonzero (value :: Int8 where value != 0)
113
+ -> (result :: Int8 where result != 0)
114
+ is value end function
115
+
116
+ function wrapnonzero (value :: Int8 where value != 0)
117
+ -> Maybe (result :: Int8 where result != 0)
118
+ is Just value end function
119
+
120
+ function unwrapnonzero (value :: Maybe (element :: Int8 where element != 0))
121
+ -> Rational
122
122
  is
123
- match value with
124
- | Nothing -> 0
125
- | Just element -> selectnonzero (Left element)
126
- end
127
- end
128
-
129
- definition selectnonzero (value :: Either (element :: Int8 where element != 0) Bool)
130
- :: Rational
123
+ first matching case of value :
124
+ when Nothing then 0
125
+ when Just element then selectnonzero (Left element)
126
+ end case
127
+ end function
128
+
129
+ function selectnonzero (value :: Either (element :: Int8 where element != 0) Bool)
130
+ -> Rational
131
131
  is
132
- match value with
133
- | Left element -> 1 / element
134
- | Right ignored -> 0
135
- end
136
- end
132
+ first matching case of value :
133
+ when Left element then 1 / element
134
+ when Right ignored then 0
135
+ end case
136
+ end function
137
+ end unit