lawspec 0.27.0 → 0.28.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 +112 -1
- package/bin/lawspec.mjs +28 -8
- package/build.json +137 -119
- package/builtin-data-names.mjs +4 -4
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -5
- package/examples/native-payments/elixir/lib/payments_domain.ex +1 -1
- package/examples/native-payments/erlang/src/payments_domain.erl +1 -1
- package/examples/rc1/bit-codec.lawspec +6 -6
- package/examples/rc1/native-payments.lawspec +6 -6
- package/examples/rc1/nesting/rrr.lawspec +2 -2
- package/examples/rc1/nesting/rru.lawspec +4 -4
- package/examples/rc1/nesting/rur.lawspec +4 -4
- package/examples/rc1/nesting/ruu.lawspec +5 -5
- package/examples/rc1/nesting/urr.lawspec +4 -4
- package/examples/rc1/nesting/uru.lawspec +5 -5
- package/examples/rc1/nesting/uur.lawspec +5 -5
- package/examples/rc1/nesting/uuu.lawspec +6 -6
- package/examples/rc1/recursive-records.lawspec +5 -5
- package/examples/rc1/refund-policy.lawspec +4 -0
- package/examples/specs/builtins.lawspec +2 -2
- package/examples/specs/collections.lawspec +8 -8
- package/examples/specs/composition.lawspec +10 -10
- package/examples/specs/contracts.lawspec +2 -2
- package/examples/specs/crypto.lawspec +2 -2
- package/examples/specs/flow_stack.lawspec +4 -4
- package/examples/specs/generation.lawspec +2 -2
- package/examples/specs/list_contracts.lawspec +3 -3
- package/examples/specs/lists.lawspec +6 -6
- package/examples/specs/matching.lawspec +8 -8
- package/examples/specs/payments.lawspec +5 -5
- package/examples/specs/records.lawspec +4 -4
- package/examples/specs/refinements.lawspec +4 -0
- package/examples/specs/resources.lawspec +5 -5
- package/examples/specs/sequences.lawspec +1 -1
- package/examples/specs/sum_refinements.lawspec +11 -11
- package/index.d.ts +154 -3
- package/package.json +1 -1
- package/proof.d.ts +57 -12
- package/proof.mjs +277 -13
package/builtin-data-names.mjs
CHANGED
|
@@ -31,13 +31,13 @@ export const builtinDataNames =
|
|
|
31
31
|
"name": "Maybe",
|
|
32
32
|
"constructors": [
|
|
33
33
|
{
|
|
34
|
-
"id": "Maybe::
|
|
35
|
-
"name": "
|
|
34
|
+
"id": "Maybe::Absent",
|
|
35
|
+
"name": "Absent",
|
|
36
36
|
"fields": []
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
|
-
"id": "Maybe::
|
|
40
|
-
"name": "
|
|
39
|
+
"id": "Maybe::Present",
|
|
40
|
+
"name": "Present",
|
|
41
41
|
"fields": [
|
|
42
42
|
{
|
|
43
43
|
"name": "value"
|
package/core.wasm
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/core.wasm
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 76208086 bytes
|
|
4
|
+
sha256: d991fd3b5d54e86d4bb516d0cf46adc94f17e13647d7cb207f4364c51c7f77fb
|
package/core_jsffi.js
CHANGED
|
@@ -92,11 +92,11 @@ newJSVal: (v) => __ghc_wasm_jsffi_jsval_manager.newJSVal(v),
|
|
|
92
92
|
getJSVal: (k) => __ghc_wasm_jsffi_jsval_manager.getJSVal(k),
|
|
93
93
|
freeJSVal: (k) => __ghc_wasm_jsffi_jsval_manager.freeJSVal(k),
|
|
94
94
|
scheduleWork: () => setImmediate(__exports.rts_schedulerLoop),
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
ZC1ZClawspeczmwasmzm0zi28zi0zminplacezmlawspeczmwasmZCMainZC: ($1) => (($1.parts.push($1.decoder.decode()), $1.parts.join(''))),
|
|
96
|
+
ZC2ZClawspeczmwasmzm0zi28zi0zminplacezmlawspeczmwasmZCMainZC: ($1,$2,$3) => ($1.parts.push($1.decoder.decode(new Uint8Array(__exports.memory.buffer, $2 >>> 0, $3), {stream: true}))),
|
|
97
|
+
ZC3ZClawspeczmwasmzm0zi28zi0zminplacezmlawspeczmwasmZCMainZC: () => (({decoder: new TextDecoder('utf-8', {fatal: true}), parts: []})),
|
|
98
|
+
ZC4ZClawspeczmwasmzm0zi28zi0zminplacezmlawspeczmwasmZCMainZC: ($1,$2,$3) => ((new TextEncoder()).encodeInto($1, new Uint8Array(__exports.memory.buffer, $2 >>> 0, $3)).written),
|
|
99
|
+
ZC5ZClawspeczmwasmzm0zi28zi0zminplacezmlawspeczmwasmZCMainZC: ($1) => ($1.length),
|
|
100
100
|
ZC0ZCghczminternalZCGHCziInternalziWasmziPrimziExportsZC: ($1,$2) => ($1.reject(new WebAssembly.RuntimeError($2))),
|
|
101
101
|
ZC18ZCghczminternalZCGHCziInternalziWasmziPrimziExportsZC: ($1,$2) => ($1.resolve($2)),
|
|
102
102
|
ZC20ZCghczminternalZCGHCziInternalziWasmziPrimziExportsZC: ($1) => {$1.throwTo = () => {};},
|
|
@@ -49,6 +49,6 @@ defmodule PaymentsDomain do
|
|
|
49
49
|
@spec restore(PaymentStatus.t()) :: PaymentStatus.t()
|
|
50
50
|
def restore(payment), do: payment
|
|
51
51
|
|
|
52
|
-
@spec store([:
|
|
52
|
+
@spec store([:absent | {:present, PaymentStatus.t()}]) :: [:absent | {:present, PaymentStatus.t()}]
|
|
53
53
|
def store(payments), do: payments
|
|
54
54
|
end
|
|
@@ -17,5 +17,5 @@ apply_fee(#price{major = Amount} = Price) ->
|
|
|
17
17
|
-spec restore(payment_status()) -> payment_status().
|
|
18
18
|
restore(Payment) -> Payment.
|
|
19
19
|
|
|
20
|
-
-spec store([
|
|
20
|
+
-spec store([absent | {present, payment_status()}]) -> [absent | {present, payment_status()}].
|
|
21
21
|
store(Payments) -> Payments.
|
|
@@ -11,15 +11,15 @@ end function
|
|
|
11
11
|
|
|
12
12
|
function "|decode with zero default| (text of type Text) -> Bool is
|
|
13
13
|
first matching case of decodeBit text:
|
|
14
|
-
when
|
|
15
|
-
when
|
|
14
|
+
when Present bit then bit
|
|
15
|
+
when Absent then false
|
|
16
16
|
end case
|
|
17
17
|
end function
|
|
18
18
|
|
|
19
19
|
law "|each bit is recovered| is
|
|
20
20
|
definition:
|
|
21
21
|
for all (bit of type Bool) =>
|
|
22
|
-
decodeBit (bitText bit) must be
|
|
22
|
+
decodeBit (bitText bit) must be Present bit
|
|
23
23
|
end for all
|
|
24
24
|
end definition
|
|
25
25
|
|
|
@@ -30,8 +30,8 @@ law "|each bit is recovered| is
|
|
|
30
30
|
expect bitText bit = encoded
|
|
31
31
|
expect decodeBit encoded = decoded
|
|
32
32
|
in table (bit, encoded, decoded):
|
|
33
|
-
row false, "0",
|
|
34
|
-
row true, "1",
|
|
33
|
+
row false, "0", Present false
|
|
34
|
+
row true, "1", Present true
|
|
35
35
|
end table
|
|
36
36
|
end law
|
|
37
37
|
|
|
@@ -47,7 +47,7 @@ end law
|
|
|
47
47
|
|
|
48
48
|
law "|other text has no bit| is
|
|
49
49
|
definition:
|
|
50
|
-
decodeBit "01" must be
|
|
50
|
+
decodeBit "01" must be Absent
|
|
51
51
|
end definition
|
|
52
52
|
|
|
53
53
|
description:
|
|
@@ -94,14 +94,14 @@ law "|archives preserve order duplicates and absence| is
|
|
|
94
94
|
|
|
95
95
|
example "|missing is different from a declined payment|:
|
|
96
96
|
payments = [
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
Absent, Present (Declined ""),
|
|
98
|
+
Present (Paid (Money record{amount = 0.1, currency = USD})),
|
|
99
|
+
Present (Paid (Money record{amount = 0.1, currency = USD}))
|
|
100
100
|
]
|
|
101
101
|
expect archive payments = [
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
Absent, Present (Declined ""),
|
|
103
|
+
Present (Paid (Money record{amount = 0.1, currency = USD})),
|
|
104
|
+
Present (Paid (Money record{amount = 0.1, currency = USD}))
|
|
105
105
|
]
|
|
106
106
|
end example
|
|
107
107
|
end law
|
|
@@ -12,7 +12,7 @@ function "|email invoice PDF file name|
|
|
|
12
12
|
(delivery of type EmailDelivery) -> Maybe Text is
|
|
13
13
|
first matching case of delivery:
|
|
14
14
|
when record{document = record{file = record{fileName = name}}}
|
|
15
|
-
then
|
|
15
|
+
then Present name
|
|
16
16
|
end case
|
|
17
17
|
end function
|
|
18
18
|
|
|
@@ -27,7 +27,7 @@ law "|emailPdfInvoice result| is
|
|
|
27
27
|
"PDF invoices sent by email retain their file names."
|
|
28
28
|
end description
|
|
29
29
|
definition:
|
|
30
|
-
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be
|
|
30
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Present
|
|
31
31
|
"invoice.pdf"
|
|
32
32
|
end definition
|
|
33
33
|
end law
|
|
@@ -17,8 +17,8 @@ function "|email invoice PDF file name|
|
|
|
17
17
|
(delivery of type EmailDelivery) -> Maybe Text is
|
|
18
18
|
first matching case of delivery:
|
|
19
19
|
when record{document = record{file = Pdf record{fileName = name}}}
|
|
20
|
-
then
|
|
21
|
-
otherwise
|
|
20
|
+
then Present name
|
|
21
|
+
otherwise Absent
|
|
22
22
|
end case
|
|
23
23
|
end function
|
|
24
24
|
|
|
@@ -34,7 +34,7 @@ law "|emailPdfInvoice result| is
|
|
|
34
34
|
"PDF invoices sent by email retain their file names."
|
|
35
35
|
end description
|
|
36
36
|
definition:
|
|
37
|
-
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be
|
|
37
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Present
|
|
38
38
|
"invoice.pdf"
|
|
39
39
|
end definition
|
|
40
40
|
end law
|
|
@@ -51,7 +51,7 @@ law "|emailPlainTextInvoice result| is
|
|
|
51
51
|
end description
|
|
52
52
|
definition:
|
|
53
53
|
"|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
|
|
54
|
-
|
|
54
|
+
Absent
|
|
55
55
|
end definition
|
|
56
56
|
end law
|
|
57
57
|
end unit
|
|
@@ -19,8 +19,8 @@ function "|email invoice PDF file name|
|
|
|
19
19
|
(delivery of type EmailDelivery) -> Maybe Text is
|
|
20
20
|
first matching case of delivery:
|
|
21
21
|
when record{document = Invoice record{file = record{fileName = name}}}
|
|
22
|
-
then
|
|
23
|
-
otherwise
|
|
22
|
+
then Present name
|
|
23
|
+
otherwise Absent
|
|
24
24
|
end case
|
|
25
25
|
end function
|
|
26
26
|
|
|
@@ -35,7 +35,7 @@ law "|emailPdfInvoice result| is
|
|
|
35
35
|
"PDF invoices sent by email retain their file names."
|
|
36
36
|
end description
|
|
37
37
|
definition:
|
|
38
|
-
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be
|
|
38
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Present
|
|
39
39
|
"invoice.pdf"
|
|
40
40
|
end definition
|
|
41
41
|
end law
|
|
@@ -52,7 +52,7 @@ law "|emailPdfLetter result| is
|
|
|
52
52
|
end description
|
|
53
53
|
definition:
|
|
54
54
|
"|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
|
|
55
|
-
|
|
55
|
+
Absent
|
|
56
56
|
end definition
|
|
57
57
|
end law
|
|
58
58
|
end unit
|
|
@@ -23,8 +23,8 @@ function "|email invoice PDF file name|
|
|
|
23
23
|
(delivery of type EmailDelivery) -> Maybe Text is
|
|
24
24
|
first matching case of delivery:
|
|
25
25
|
when record{document = Invoice record{file = Pdf record{fileName = name}}}
|
|
26
|
-
then
|
|
27
|
-
otherwise
|
|
26
|
+
then Present name
|
|
27
|
+
otherwise Absent
|
|
28
28
|
end case
|
|
29
29
|
end function
|
|
30
30
|
|
|
@@ -39,7 +39,7 @@ law "|emailPdfInvoice result| is
|
|
|
39
39
|
"PDF invoices sent by email retain their file names."
|
|
40
40
|
end description
|
|
41
41
|
definition:
|
|
42
|
-
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be
|
|
42
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Present
|
|
43
43
|
"invoice.pdf"
|
|
44
44
|
end definition
|
|
45
45
|
end law
|
|
@@ -56,7 +56,7 @@ law "|emailPlainTextInvoice result| is
|
|
|
56
56
|
end description
|
|
57
57
|
definition:
|
|
58
58
|
"|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
|
|
59
|
-
|
|
59
|
+
Absent
|
|
60
60
|
end definition
|
|
61
61
|
end law
|
|
62
62
|
|
|
@@ -72,7 +72,7 @@ law "|emailPdfLetter result| is
|
|
|
72
72
|
end description
|
|
73
73
|
definition:
|
|
74
74
|
"|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
|
|
75
|
-
|
|
75
|
+
Absent
|
|
76
76
|
end definition
|
|
77
77
|
end law
|
|
78
78
|
end unit
|
|
@@ -14,8 +14,8 @@ function "|email invoice PDF file name|
|
|
|
14
14
|
(delivery of type Delivery) -> Maybe Text is
|
|
15
15
|
first matching case of delivery:
|
|
16
16
|
when Email record{document = record{file = record{fileName = name}}}
|
|
17
|
-
then
|
|
18
|
-
otherwise
|
|
17
|
+
then Present name
|
|
18
|
+
otherwise Absent
|
|
19
19
|
end case
|
|
20
20
|
end function
|
|
21
21
|
|
|
@@ -31,7 +31,7 @@ law "|emailPdfInvoice result| is
|
|
|
31
31
|
"PDF invoices sent by email retain their file names."
|
|
32
32
|
end description
|
|
33
33
|
definition:
|
|
34
|
-
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be
|
|
34
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Present
|
|
35
35
|
"invoice.pdf"
|
|
36
36
|
end definition
|
|
37
37
|
end law
|
|
@@ -47,7 +47,7 @@ law "|downloadPdfInvoice result| is
|
|
|
47
47
|
end description
|
|
48
48
|
definition:
|
|
49
49
|
"|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
|
|
50
|
-
|
|
50
|
+
Absent
|
|
51
51
|
end definition
|
|
52
52
|
end law
|
|
53
53
|
end unit
|
|
@@ -18,8 +18,8 @@ function "|email invoice PDF file name|
|
|
|
18
18
|
(delivery of type Delivery) -> Maybe Text is
|
|
19
19
|
first matching case of delivery:
|
|
20
20
|
when Email record{document = record{file = Pdf record{fileName = name}}}
|
|
21
|
-
then
|
|
22
|
-
otherwise
|
|
21
|
+
then Present name
|
|
22
|
+
otherwise Absent
|
|
23
23
|
end case
|
|
24
24
|
end function
|
|
25
25
|
|
|
@@ -34,7 +34,7 @@ law "|emailPdfInvoice result| is
|
|
|
34
34
|
"PDF invoices sent by email retain their file names."
|
|
35
35
|
end description
|
|
36
36
|
definition:
|
|
37
|
-
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be
|
|
37
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Present
|
|
38
38
|
"invoice.pdf"
|
|
39
39
|
end definition
|
|
40
40
|
end law
|
|
@@ -51,7 +51,7 @@ law "|emailPlainTextInvoice result| is
|
|
|
51
51
|
end description
|
|
52
52
|
definition:
|
|
53
53
|
"|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
|
|
54
|
-
|
|
54
|
+
Absent
|
|
55
55
|
end definition
|
|
56
56
|
end law
|
|
57
57
|
|
|
@@ -67,7 +67,7 @@ law "|downloadPdfInvoice result| is
|
|
|
67
67
|
end description
|
|
68
68
|
definition:
|
|
69
69
|
"|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
|
|
70
|
-
|
|
70
|
+
Absent
|
|
71
71
|
end definition
|
|
72
72
|
end law
|
|
73
73
|
end unit
|
|
@@ -19,8 +19,8 @@ function "|email invoice PDF file name|
|
|
|
19
19
|
(delivery of type Delivery) -> Maybe Text is
|
|
20
20
|
first matching case of delivery:
|
|
21
21
|
when Email record{document = Invoice record{file = record{fileName = name}}}
|
|
22
|
-
then
|
|
23
|
-
otherwise
|
|
22
|
+
then Present name
|
|
23
|
+
otherwise Absent
|
|
24
24
|
end case
|
|
25
25
|
end function
|
|
26
26
|
|
|
@@ -35,7 +35,7 @@ law "|emailPdfInvoice result| is
|
|
|
35
35
|
"PDF invoices sent by email retain their file names."
|
|
36
36
|
end description
|
|
37
37
|
definition:
|
|
38
|
-
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be
|
|
38
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Present
|
|
39
39
|
"invoice.pdf"
|
|
40
40
|
end definition
|
|
41
41
|
end law
|
|
@@ -52,7 +52,7 @@ law "|emailPdfLetter result| is
|
|
|
52
52
|
end description
|
|
53
53
|
definition:
|
|
54
54
|
"|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
|
|
55
|
-
|
|
55
|
+
Absent
|
|
56
56
|
end definition
|
|
57
57
|
end law
|
|
58
58
|
|
|
@@ -68,7 +68,7 @@ law "|downloadPdfInvoice result| is
|
|
|
68
68
|
end description
|
|
69
69
|
definition:
|
|
70
70
|
"|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
|
|
71
|
-
|
|
71
|
+
Absent
|
|
72
72
|
end definition
|
|
73
73
|
end law
|
|
74
74
|
end unit
|
|
@@ -24,8 +24,8 @@ function "|email invoice PDF file name|
|
|
|
24
24
|
first matching case of delivery:
|
|
25
25
|
when Email record{document = Invoice record{file = Pdf record{fileName =
|
|
26
26
|
name}}}
|
|
27
|
-
then
|
|
28
|
-
otherwise
|
|
27
|
+
then Present name
|
|
28
|
+
otherwise Absent
|
|
29
29
|
end case
|
|
30
30
|
end function
|
|
31
31
|
|
|
@@ -40,7 +40,7 @@ law "|emailPdfInvoice result| is
|
|
|
40
40
|
"PDF invoices sent by email retain their file names."
|
|
41
41
|
end description
|
|
42
42
|
definition:
|
|
43
|
-
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be
|
|
43
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Present
|
|
44
44
|
"invoice.pdf"
|
|
45
45
|
end definition
|
|
46
46
|
end law
|
|
@@ -57,7 +57,7 @@ law "|emailPlainTextInvoice result| is
|
|
|
57
57
|
end description
|
|
58
58
|
definition:
|
|
59
59
|
"|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
|
|
60
|
-
|
|
60
|
+
Absent
|
|
61
61
|
end definition
|
|
62
62
|
end law
|
|
63
63
|
|
|
@@ -73,7 +73,7 @@ law "|emailPdfLetter result| is
|
|
|
73
73
|
end description
|
|
74
74
|
definition:
|
|
75
75
|
"|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
|
|
76
|
-
|
|
76
|
+
Absent
|
|
77
77
|
end definition
|
|
78
78
|
end law
|
|
79
79
|
|
|
@@ -90,7 +90,7 @@ law "|downloadPdfInvoice result| is
|
|
|
90
90
|
end description
|
|
91
91
|
definition:
|
|
92
92
|
"|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
|
|
93
|
-
|
|
93
|
+
Absent
|
|
94
94
|
end definition
|
|
95
95
|
end law
|
|
96
96
|
end unit
|
|
@@ -26,8 +26,8 @@ end type
|
|
|
26
26
|
|
|
27
27
|
function chainLength (chain of type ApprovalChain) -> Whole is
|
|
28
28
|
first matching case of chain:
|
|
29
|
-
when record{next =
|
|
30
|
-
when record{next =
|
|
29
|
+
when record{next = Absent} then 0
|
|
30
|
+
when record{next = Present rest} then 1 + chainLength rest
|
|
31
31
|
end case
|
|
32
32
|
end function
|
|
33
33
|
|
|
@@ -49,15 +49,15 @@ end law
|
|
|
49
49
|
|
|
50
50
|
law "|a completed chain has no remaining approval| is
|
|
51
51
|
definition:
|
|
52
|
-
chainLength (ApprovalChain record{next =
|
|
52
|
+
chainLength (ApprovalChain record{next = Absent}) must be 0
|
|
53
53
|
end definition
|
|
54
54
|
end law
|
|
55
55
|
|
|
56
56
|
law "|a pending chain counts each remaining approval| is
|
|
57
57
|
definition:
|
|
58
58
|
chainLength (ApprovalChain record{
|
|
59
|
-
next =
|
|
60
|
-
next =
|
|
59
|
+
next = Present (ApprovalChain record{
|
|
60
|
+
next = Present (ApprovalChain record{next = Absent})
|
|
61
61
|
})
|
|
62
62
|
}) must be 2
|
|
63
63
|
end definition
|
|
@@ -86,4 +86,8 @@ law "|an eligible unflagged refund is approved| is
|
|
|
86
86
|
= 9007199254740993, flagged = false}, Rejected
|
|
87
87
|
end table
|
|
88
88
|
end law
|
|
89
|
+
|
|
90
|
+
laws for refund are
|
|
91
|
+
overlap allowed because "a zero unflagged refund is approved by two laws that agree"
|
|
92
|
+
end laws
|
|
89
93
|
end unit
|
|
@@ -91,11 +91,11 @@ procedure remember (note :: Bytes) -> Maybe Bytes uses FileSystem is
|
|
|
91
91
|
end procedure
|
|
92
92
|
|
|
93
93
|
law "|a remembered note reads back| is
|
|
94
|
-
definition : for all (note :: Bytes) => remember note =
|
|
94
|
+
definition : for all (note :: Bytes) => remember note = Present note end for all end definition
|
|
95
95
|
end law
|
|
96
96
|
|
|
97
97
|
law "|an empty environment has no variables| using emptyEnvironment is
|
|
98
|
-
definition : for all (name :: Text) => environmentVariable name =
|
|
98
|
+
definition : for all (name :: Text) => environmentVariable name = Absent end for all end definition
|
|
99
99
|
end law
|
|
100
100
|
|
|
101
101
|
listening :: Int32 -> Bool uses Ports
|
|
@@ -22,16 +22,16 @@ function countWords (words :: List Text) (counts :: KeyVal Text Integer) -> KeyV
|
|
|
22
22
|
first matching case of words :
|
|
23
23
|
when Nil then counts
|
|
24
24
|
when Cons w rest then first matching case of prelude.lookup w counts :
|
|
25
|
-
when
|
|
26
|
-
when
|
|
25
|
+
when Absent then countWords rest (prelude.put w 1 counts)
|
|
26
|
+
when Present n then countWords rest (prelude.put w ((n + 1) :: Integer) counts)
|
|
27
27
|
end case
|
|
28
28
|
end case
|
|
29
29
|
end function
|
|
30
30
|
|
|
31
31
|
function rotated (d :: Deque Int8) -> Deque Int8 is
|
|
32
32
|
first matching case of prelude.peekFront d :
|
|
33
|
-
when
|
|
34
|
-
when
|
|
33
|
+
when Absent then d
|
|
34
|
+
when Present x then prelude.pushBack x (prelude.popFront d)
|
|
35
35
|
end case
|
|
36
36
|
end function
|
|
37
37
|
|
|
@@ -51,13 +51,13 @@ end law
|
|
|
51
51
|
|
|
52
52
|
law "|the queue's front is the first value| is
|
|
53
53
|
definition :
|
|
54
|
-
for all (x :: Int8) (xs :: List Int8) => prelude.front (fifo (Cons x xs)) =
|
|
54
|
+
for all (x :: Int8) (xs :: List Int8) => prelude.front (fifo (Cons x xs)) = Present x end for all
|
|
55
55
|
end definition
|
|
56
56
|
end law
|
|
57
57
|
|
|
58
58
|
law "|the stack's top is the last value| is
|
|
59
59
|
definition :
|
|
60
|
-
for all (x :: Int8) (xs :: List Int8) => prelude.peek (lifo [x]) =
|
|
60
|
+
for all (x :: Int8) (xs :: List Int8) => prelude.peek (lifo [x]) = Present x end for all
|
|
61
61
|
end definition
|
|
62
62
|
end law
|
|
63
63
|
|
|
@@ -97,13 +97,13 @@ end law
|
|
|
97
97
|
law "|the latest put wins| is
|
|
98
98
|
definition :
|
|
99
99
|
for all (k :: Text) (v :: Integer) (w :: Integer) (m :: KeyVal Text Integer) =>
|
|
100
|
-
prelude.lookup k (prelude.put k w (prelude.put k v m)) =
|
|
100
|
+
prelude.lookup k (prelude.put k w (prelude.put k v m)) = Present w end for all
|
|
101
101
|
end definition
|
|
102
102
|
end law
|
|
103
103
|
|
|
104
104
|
law "|a deleted key is absent| is
|
|
105
105
|
definition :
|
|
106
|
-
for all (k :: Text) (m :: KeyVal Text Integer) => prelude.lookup k (prelude.delete k m) =
|
|
106
|
+
for all (k :: Text) (m :: KeyVal Text Integer) => prelude.lookup k (prelude.delete k m) = Absent end for all
|
|
107
107
|
end definition
|
|
108
108
|
end law
|
|
109
109
|
|
|
@@ -40,7 +40,7 @@ ability Reader with Store is
|
|
|
40
40
|
size :: Text -> Maybe Int64
|
|
41
41
|
laws
|
|
42
42
|
law "|an unknown log has no size| is
|
|
43
|
-
definition : for all (t :: Text) => size t =
|
|
43
|
+
definition : for all (t :: Text) => size t = Absent end for all end definition
|
|
44
44
|
end law
|
|
45
45
|
end laws
|
|
46
46
|
end ability
|
|
@@ -52,7 +52,7 @@ ability Writer with Store is
|
|
|
52
52
|
laws
|
|
53
53
|
law "|a write to a new log is read back| is
|
|
54
54
|
definition :
|
|
55
|
-
for all (t :: Text) (r :: Text where r != "") => (create t; write t r; size t) =
|
|
55
|
+
for all (t :: Text) (r :: Text where r != "") => (create t; write t r; size t) = Present 1 end for all
|
|
56
56
|
end definition
|
|
57
57
|
end law
|
|
58
58
|
end laws
|
|
@@ -66,8 +66,8 @@ handler store for Logs, Reader with state logs :: KeyVal Text Log start empty un
|
|
|
66
66
|
operation create t is ~logs := prelude.put t (Log record{ records = [] , appends = 0}) logs; unitValue end operation
|
|
67
67
|
operation append t r is
|
|
68
68
|
first matching case of prelude.lookup t logs :
|
|
69
|
-
when
|
|
70
|
-
when
|
|
69
|
+
when Absent then raise UnknownLog
|
|
70
|
+
when Present log then
|
|
71
71
|
if r = "" then raise EmptyRecord else
|
|
72
72
|
(~logs := prelude.put t (log with records = Cons r log.records, appends = prelude.saturating (log.appends + 1)) logs;
|
|
73
73
|
log.appends) end if
|
|
@@ -75,8 +75,8 @@ handler store for Logs, Reader with state logs :: KeyVal Text Log start empty un
|
|
|
75
75
|
end operation
|
|
76
76
|
operation size t is
|
|
77
77
|
first matching case of prelude.lookup t logs :
|
|
78
|
-
when
|
|
79
|
-
when
|
|
78
|
+
when Absent then Absent
|
|
79
|
+
when Present log then Present log.appends
|
|
80
80
|
end case
|
|
81
81
|
end operation
|
|
82
82
|
end handler
|
|
@@ -85,13 +85,13 @@ end handler
|
|
|
85
85
|
procedure writeTo (t :: Text) (r :: Text) (last :: Maybe Int64) -> Pair Bool (Maybe Int64) uses Logs is
|
|
86
86
|
first matching case of prelude.attempt (append t r) :
|
|
87
87
|
when Left problem then Pair false last
|
|
88
|
-
when Right offset then Pair true (
|
|
88
|
+
when Right offset then Pair true (Present offset)
|
|
89
89
|
end case
|
|
90
90
|
end procedure
|
|
91
91
|
|
|
92
92
|
function lastOf (last :: Maybe Int64) -> Pair (Maybe Int64) (Maybe Int64) is Pair last last end function
|
|
93
93
|
|
|
94
|
-
handler logWriter for Writer with state last :: Maybe Int64 start
|
|
94
|
+
handler logWriter for Writer with state last :: Maybe Int64 start Absent is
|
|
95
95
|
operation write by writeTo end operation
|
|
96
96
|
operation lastOffset by lastOf end operation
|
|
97
97
|
end handler
|
|
@@ -102,13 +102,13 @@ handlers reference is store, logWriter end handlers
|
|
|
102
102
|
law "|sizes count records| is
|
|
103
103
|
definition :
|
|
104
104
|
for all (t :: Text) (a :: Text where a != "") (b :: Text where b != "") =>
|
|
105
|
-
(create t; append t a; append t b; size t) =
|
|
105
|
+
(create t; append t a; append t b; size t) = Present 2 end for all
|
|
106
106
|
end definition
|
|
107
107
|
end law
|
|
108
108
|
|
|
109
109
|
law "|a writer remembers where it wrote| is
|
|
110
110
|
definition :
|
|
111
|
-
for all (t :: Text) (r :: Text where r != "") => (create t; write t r; lastOffset) =
|
|
111
|
+
for all (t :: Text) (r :: Text where r != "") => (create t; write t r; lastOffset) = Present 0 end for all
|
|
112
112
|
end definition
|
|
113
113
|
end law
|
|
114
114
|
end unit
|
|
@@ -109,13 +109,13 @@ type Badge is a record{
|
|
|
109
109
|
label :: (v :: Text where validName v)}
|
|
110
110
|
end type
|
|
111
111
|
|
|
112
|
-
function withId (body :: Pet) (key :: Int64) -> Pet is body with id =
|
|
112
|
+
function withId (body :: Pet) (key :: Int64) -> Pet is body with id = Present key end function
|
|
113
113
|
|
|
114
114
|
function validPet (p :: Pet) -> Bool is p.name matches regex "[a-z]{2,8}" end function
|
|
115
115
|
|
|
116
116
|
law "|an id is set by a record update| is
|
|
117
117
|
definition :
|
|
118
|
-
for all (p :: Pet where validPet p) (key :: Int64) => (withId p key).id =
|
|
118
|
+
for all (p :: Pet where validPet p) (key :: Int64) => (withId p key).id = Present key and (withId p key).name = p.name end for all
|
|
119
119
|
end definition
|
|
120
120
|
end law
|
|
121
121
|
|
|
@@ -22,13 +22,13 @@ procedure handshake (message :: Bytes) (context :: Bytes) -> Maybe Bytes uses Ke
|
|
|
22
22
|
let server = deriveAeadKey (decapsulate secret sent) context in
|
|
23
23
|
unseal server (seal client message context) context end let end let)
|
|
24
24
|
end case)
|
|
25
|
-
else
|
|
25
|
+
else Absent end if end let)
|
|
26
26
|
end case)
|
|
27
27
|
end case
|
|
28
28
|
end procedure
|
|
29
29
|
|
|
30
30
|
law "|a handshake carries the message| is
|
|
31
|
-
definition : for all (message :: Bytes) (context :: Bytes) => handshake message context =
|
|
31
|
+
definition : for all (message :: Bytes) (context :: Bytes) => handshake message context = Present message end for all end definition
|
|
32
32
|
end law
|
|
33
33
|
|
|
34
34
|
-- A native adapter: a short fingerprint of a public key, from its SHA3-256
|
|
@@ -83,11 +83,11 @@ law "|a push chosen by a match| is
|
|
|
83
83
|
definition :
|
|
84
84
|
for all (m :: Maybe Int8) (s :: Stack n) =>
|
|
85
85
|
((first matching case of m :
|
|
86
|
-
when
|
|
87
|
-
when
|
|
86
|
+
when Present v then push v ~s
|
|
87
|
+
when Absent then push 0 ~s
|
|
88
88
|
end case); pop ~s) = (first matching case of m :
|
|
89
|
-
when
|
|
90
|
-
when
|
|
89
|
+
when Present v then v
|
|
90
|
+
when Absent then prelude.Int8 0
|
|
91
91
|
end case) end for all
|
|
92
92
|
end definition
|
|
93
93
|
end law
|
|
@@ -101,8 +101,8 @@ law "|maybe| is
|
|
|
101
101
|
end definition
|
|
102
102
|
example "|seed 5| :
|
|
103
103
|
seed = 5
|
|
104
|
-
expect generated "(maybe (bool))" seed 4 4 = ["
|
|
105
|
-
expect shrunk "(maybe (bool))" seed 4 = ["
|
|
104
|
+
expect generated "(maybe (bool))" seed 4 4 = ["Present(false)", "Present(true)", "Present(false)", "Present(true)"]
|
|
105
|
+
expect shrunk "(maybe (bool))" seed 4 = ["Absent"]
|
|
106
106
|
end example
|
|
107
107
|
end law
|
|
108
108
|
|
|
@@ -115,14 +115,14 @@ is value end function
|
|
|
115
115
|
|
|
116
116
|
function wrapnonzero (value :: Int8 where value != 0)
|
|
117
117
|
-> Maybe (result :: Int8 where result != 0)
|
|
118
|
-
is
|
|
118
|
+
is Present value end function
|
|
119
119
|
|
|
120
120
|
function unwrapnonzero (value :: Maybe (element :: Int8 where element != 0))
|
|
121
121
|
-> Rational
|
|
122
122
|
is
|
|
123
123
|
first matching case of value :
|
|
124
|
-
when
|
|
125
|
-
when
|
|
124
|
+
when Absent then 0
|
|
125
|
+
when Present element then selectnonzero (Left element)
|
|
126
126
|
end case
|
|
127
127
|
end function
|
|
128
128
|
|