lawspec 0.24.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.
- package/CHANGELOG.md +109 -1
- package/README.md +34 -26
- package/UNICODE-LICENSE.txt +39 -0
- package/api.mjs +6 -23
- package/bin/lawspec.mjs +148 -65
- package/build.json +245 -177
- package/builtin-data-names.mjs +73 -0
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- package/examples/native-payments/clojure/lawspec.json +13 -2
- package/examples/native-payments/csharp/lawspec.json +13 -2
- package/examples/native-payments/elixir/lawspec.json +14 -3
- package/examples/native-payments/erlang/lawspec.json +14 -3
- package/examples/native-payments/fsharp/lawspec.json +14 -3
- package/examples/native-payments/gleam/lawspec.json +14 -3
- package/examples/native-payments/go/lawspec.json +14 -3
- package/examples/native-payments/groovy/lawspec.json +14 -3
- package/examples/native-payments/haskell/lawspec.json +14 -3
- package/examples/native-payments/java/lawspec.json +14 -3
- package/examples/native-payments/javascript/lawspec.json +14 -3
- package/examples/native-payments/kotlin/lawspec.json +14 -3
- package/examples/native-payments/python/lawspec.json +14 -3
- package/examples/native-payments/rust/lawspec.json +14 -3
- package/examples/native-payments/scala/lawspec.json +14 -3
- package/examples/native-payments/swift/lawspec.json +14 -3
- package/examples/native-payments/typescript/lawspec.json +14 -3
- package/examples/packages/orders/lawspec.json +25 -5
- package/examples/packages/orders/orders.lawspec +57 -53
- package/examples/packages/shop-domain/src/domain.lawspec +36 -33
- package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-1/src/rates.lawspec +5 -4
- package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/rates.lawspec +6 -4
- package/examples/rc1/authorization-snapshots.lawspec +113 -0
- package/examples/rc1/banner-filenames.lawspec +64 -0
- package/examples/rc1/bit-codec.lawspec +57 -0
- package/examples/rc1/bounded-witness-search.lawspec +151 -0
- package/examples/rc1/conflicting-requirements.lawspec +31 -0
- package/examples/rc1/constructive-witnesses.lawspec +120 -0
- package/examples/rc1/documentary-review.lawspec +43 -0
- package/examples/rc1/empty-domains.lawspec +47 -0
- package/examples/rc1/finite-integer-domains.lawspec +76 -0
- package/examples/rc1/law-metadata.lawspec +30 -0
- package/examples/rc1/native-payments.lawspec +108 -0
- package/examples/rc1/nesting/rrr.lawspec +34 -0
- package/examples/rc1/nesting/rru.lawspec +57 -0
- package/examples/rc1/nesting/rur.lawspec +58 -0
- package/examples/rc1/nesting/ruu.lawspec +78 -0
- package/examples/rc1/nesting/urr.lawspec +53 -0
- package/examples/rc1/nesting/uru.lawspec +73 -0
- package/examples/rc1/nesting/uur.lawspec +74 -0
- package/examples/rc1/nesting/uuu.lawspec +96 -0
- package/examples/rc1/order-workflow.lawspec +127 -0
- package/examples/rc1/parcel-measurements.lawspec +93 -0
- package/examples/rc1/picture-records.lawspec +52 -0
- package/examples/rc1/picture-tuples.lawspec +48 -0
- package/examples/rc1/record-payloads.lawspec +57 -0
- package/examples/rc1/recursive-records.lawspec +65 -0
- package/examples/rc1/refund-conformance.lawspec +45 -0
- package/examples/rc1/refund-policy.lawspec +89 -0
- package/examples/rc1/requirement-composition.lawspec +90 -0
- package/examples/rc1/structural-records.lawspec +54 -0
- package/examples/rc1-authoring.lawspec +57 -0
- package/examples/specs/abilities.lawspec +67 -65
- package/examples/specs/ability_imports.lawspec +58 -57
- package/examples/specs/actors.lawspec +23 -22
- package/examples/specs/algebra.lawspec +142 -141
- package/examples/specs/approvals.lawspec +16 -15
- package/examples/specs/async_bindings.lawspec +10 -9
- package/examples/specs/async_fetch.lawspec +12 -11
- package/examples/specs/atoi_codec.lawspec +16 -15
- package/examples/specs/boolean_flags.lawspec +10 -9
- package/examples/specs/builtins.lawspec +73 -72
- package/examples/specs/canonical_url.lawspec +14 -13
- package/examples/specs/collections.lawspec +153 -154
- package/examples/specs/composition.lawspec +70 -66
- package/examples/specs/concurrent_collections.lawspec +8 -7
- package/examples/specs/consistency.lawspec +4 -3
- package/examples/specs/contracts.lawspec +80 -79
- package/examples/specs/crypto.lawspec +26 -25
- package/examples/specs/ctc.lawspec +148 -0
- package/examples/specs/currying.lawspec +32 -31
- package/examples/specs/data_types.lawspec +50 -49
- package/examples/specs/distribution.lawspec +57 -56
- package/examples/specs/domain_modeling.lawspec +48 -47
- package/examples/specs/durations.lawspec +39 -38
- package/examples/specs/equivalent.lawspec +25 -24
- package/examples/specs/failures.lawspec +64 -63
- package/examples/specs/finite_data.lawspec +32 -31
- package/examples/specs/flow_stack.lawspec +64 -63
- package/examples/specs/gadt_expressions.lawspec +50 -49
- package/examples/specs/generation.lawspec +115 -114
- package/examples/specs/handler_bindings.lawspec +42 -40
- package/examples/specs/handles.lawspec +2 -1
- package/examples/specs/harness.lawspec +45 -43
- package/examples/specs/harness_testing.lawspec +18 -13
- package/examples/specs/indexed_arithmetic.lawspec +401 -126
- package/examples/specs/indexed_families.lawspec +182 -66
- package/examples/specs/keywords.lawspec +22 -21
- package/examples/specs/limits.lawspec +6 -5
- package/examples/specs/list_contracts.lawspec +121 -120
- package/examples/specs/list_refinements.lawspec +43 -42
- package/examples/specs/lists.lawspec +45 -44
- package/examples/specs/matchers.lawspec +79 -78
- package/examples/specs/matching.lawspec +43 -42
- package/examples/specs/mixed_inputs.lawspec +25 -24
- package/examples/specs/models.lawspec +44 -43
- package/examples/specs/parse_port.lawspec +28 -27
- package/examples/specs/payments.lawspec +55 -54
- package/examples/specs/railway.lawspec +59 -58
- package/examples/specs/records.lawspec +149 -148
- package/examples/specs/records_inner.lawspec +5 -4
- package/examples/specs/recursive_refinements.lawspec +30 -29
- package/examples/specs/refined_definitions.lawspec +24 -23
- package/examples/specs/refinements.lawspec +58 -57
- package/examples/specs/resilience.lawspec +159 -158
- package/examples/specs/resources.lawspec +61 -60
- package/examples/specs/scalar_adapters.lawspec +60 -59
- package/examples/specs/scalar_catalog.lawspec +165 -164
- package/examples/specs/scalars.lawspec +78 -77
- package/examples/specs/scheduling_order.lawspec +8 -7
- package/examples/specs/scheduling_overlap.lawspec +5 -4
- package/examples/specs/sequences.lawspec +66 -65
- package/examples/specs/sessions.lawspec +13 -12
- package/examples/specs/slug.lawspec +16 -15
- package/examples/specs/sum_refinements.lawspec +42 -41
- package/examples/specs/tables.lawspec +29 -28
- package/examples/specs/total_functions.lawspec +71 -70
- package/examples/specs/workflows.lawspec +101 -100
- package/examples-command.mjs +8 -4
- package/explain.mjs +114 -0
- package/expression-presentation.mjs +333 -0
- package/files.mjs +16 -0
- package/index.d.ts +406 -11
- package/launcher.mjs +9 -2
- package/lsp.mjs +235 -0
- package/native-evidence.mjs +187 -0
- package/native-examples.mjs +8 -1
- package/node-events-reporter.mjs +23 -0
- package/package.json +8 -1
- package/positional-fields.mjs +13 -0
- package/proof.d.ts +35 -0
- package/proof.mjs +174 -0
- package/starter-rc1.lawspec +26 -0
- package/starter.lawspec +16 -15
- package/templates.mjs +6 -4
- package/test-command.mjs +107 -35
- package/typed-presentation.mjs +165 -0
|
@@ -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 ::
|
|
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 ::
|
|
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 =
|
|
14
|
-
|
|
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 ::
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|
63
|
-
definition
|
|
64
|
-
|
|
65
|
-
nOfVec (append xs ys) = n + m
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
--
|
|
70
|
-
law
|
|
71
|
-
definition
|
|
72
|
-
|
|
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
|
|
78
|
-
definition
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 ::
|
|
16
|
+
class :: Integer -> Integer
|
|
17
17
|
|
|
18
|
-
law
|
|
19
|
-
definition
|
|
20
|
-
|
|
21
|
-
double x - x + lambda x + fun x + loop x + deriving x + delete x = 6 * x + 15
|
|
22
|
-
end
|
|
23
|
-
example
|
|
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
|
|
30
|
-
definition
|
|
31
|
-
|
|
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
|
|
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
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
11
|
+
function positive (value :: a) -> Bool requires Integer a is value > 0 end function
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
17
|
+
function reuse (xs :: List (value :: Int8 where positive value)) -> List Int8 is
|
|
18
18
|
keephelper xs
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
is [value] end
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
law
|
|
29
|
-
definition
|
|
30
|
-
stronger xs = xs
|
|
31
|
-
end
|
|
32
|
-
example
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
law
|
|
36
|
-
definition
|
|
37
|
-
reuse xs = xs
|
|
38
|
-
end
|
|
39
|
-
example
|
|
40
|
-
example
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
law
|
|
44
|
-
definition
|
|
45
|
-
example
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
law
|
|
49
|
-
definition
|
|
50
|
-
example
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
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
|
-
|
|
75
|
-
|
|
74
|
+
function positivefirst (xs :: List (value :: Int8 where value > 0))
|
|
75
|
+
-> (result :: Int8 where result > 0)
|
|
76
76
|
is
|
|
77
|
-
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
law
|
|
82
|
-
definition
|
|
83
|
-
sumreciprocal [value] = 1 / value
|
|
84
|
-
end
|
|
85
|
-
example
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
law
|
|
89
|
-
definition
|
|
90
|
-
sumrows [[], [value]] = 1 / value
|
|
91
|
-
end
|
|
92
|
-
example
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
law
|
|
96
|
-
definition
|
|
97
|
-
(second :: Int8 where second > 0)
|
|
98
|
-
end
|
|
99
|
-
example
|
|
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
|
-
|
|
104
|
-
|
|
103
|
+
function copypositive (xs :: List (value :: Int8 where value > 0))
|
|
104
|
+
-> List (value :: Int8 where value > 0)
|
|
105
105
|
is
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
is value end
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
is Just value end
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|