lawspec 0.26.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 +178 -1
- package/NORMALIZATION-LICENSES.txt +296 -0
- package/README.md +8 -0
- package/bin/lawspec.mjs +126 -33
- package/build.json +159 -131
- package/builtin-data-names.mjs +4 -4
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -5
- package/doctor.mjs +14 -4
- package/examples/native-payments/elixir/lib/payments_domain.ex +1 -1
- package/examples/native-payments/erlang/src/payments_domain.erl +1 -1
- package/examples/native-payments/prolog/lawspec.json +20 -0
- package/examples/native-payments/prolog/src/domain/payments.pl +23 -0
- package/examples/native-payments/prolog/tests/domain/payment_generators.pl +17 -0
- 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/approvals.lawspec +3 -3
- 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/domain_modeling.lawspec +20 -0
- package/examples/specs/flow_stack.lawspec +4 -4
- package/examples/specs/generation.lawspec +2 -2
- package/examples/specs/limits.lawspec +1 -1
- 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/resilience.lawspec +2 -2
- package/examples/specs/resources.lawspec +5 -5
- package/examples/specs/sequences.lawspec +1 -1
- package/examples/specs/sum_refinements.lawspec +11 -11
- package/examples-command.mjs +3 -1
- package/index.d.ts +160 -4
- package/native-evidence.mjs +25 -12
- package/native-examples.mjs +1 -1
- package/package.json +2 -1
- package/proof.d.ts +57 -12
- package/proof.mjs +277 -13
- package/templates.mjs +84 -3
- package/test-command.mjs +40 -4
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 = () => {};},
|
package/doctor.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { createRequire } from "node:module";
|
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
import os from "node:os";
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
|
-
import { setup } from "./templates.mjs";
|
|
16
|
+
import { setup, artifactTargets } from "./templates.mjs";
|
|
17
17
|
import { beamDoctor } from "./beam-doctor.mjs";
|
|
18
18
|
const exec = promisify(execFile);
|
|
19
19
|
const profiles = JSON.parse(
|
|
@@ -71,6 +71,8 @@ async function installed(req, name) {
|
|
|
71
71
|
}
|
|
72
72
|
export async function doctor(target, root, plannedArtifacts = []) {
|
|
73
73
|
const name = target.language;
|
|
74
|
+
if (artifactTargets.includes(name))
|
|
75
|
+
return {target: name, ok: true, versions: {}, kind: "artifact", instructions: setup[name]};
|
|
74
76
|
const defaults =
|
|
75
77
|
name === "java"
|
|
76
78
|
? ["src/main/java", "src/test/java"]
|
|
@@ -82,7 +84,7 @@ export async function doctor(target, root, plannedArtifacts = []) {
|
|
|
82
84
|
? ["src/main/groovy", "src/test/groovy"]
|
|
83
85
|
: name === "clojure"
|
|
84
86
|
? ["src", "test"]
|
|
85
|
-
: ["src", ["python", "rust", "fsharp", "csharp", "swift"].includes(name) ? "tests" : "test"];
|
|
87
|
+
: ["src", ["python", "prolog", "rust", "fsharp", "csharp", "swift"].includes(name) ? "tests" : "test"];
|
|
86
88
|
const sourceDir = target.sourceDir ?? defaults[0];
|
|
87
89
|
const testDir = target.testDir ?? defaults[1];
|
|
88
90
|
try {
|
|
@@ -149,8 +151,8 @@ export async function doctor(target, root, plannedArtifacts = []) {
|
|
|
149
151
|
"@types/node 22+ is required",
|
|
150
152
|
);
|
|
151
153
|
}
|
|
152
|
-
} else if (name === "python") {
|
|
153
|
-
const script = `import sys,json,importlib.metadata as m,tomllib,pathlib\np=tomllib.loads(pathlib.Path('pyproject.toml').read_text())\nprint(json.dumps({'python':'.'.join(map(str,sys.version_info[:3])),'pytest':m.version('pytest'),'hypothesis':m.version('hypothesis'),'config':p.get('tool',{}).get('pytest',{}).get('ini_options',{})}))`;
|
|
154
|
+
} else if (name === "python" || name === "prolog") {
|
|
155
|
+
const script = `import sys,json,importlib.metadata as m,tomllib,pathlib\np=tomllib.loads(pathlib.Path('pyproject.toml').read_text())\nprint(json.dumps({'python':'.'.join(map(str,sys.version_info[:3])),'optimization':sys.flags.optimize,'pytest':m.version('pytest'),'hypothesis':m.version('hypothesis'),'config':p.get('tool',{}).get('pytest',{}).get('ini_options',{})}))`;
|
|
154
156
|
Object.assign(
|
|
155
157
|
versions,
|
|
156
158
|
JSON.parse(await run(target.python || "python3", ["-c", script], root)),
|
|
@@ -180,6 +182,14 @@ export async function doctor(target, root, plannedArtifacts = []) {
|
|
|
180
182
|
"Clear PYTEST_ADDOPTS before compatibility checks",
|
|
181
183
|
);
|
|
182
184
|
delete versions.config;
|
|
185
|
+
if (name === "prolog") {
|
|
186
|
+
requireThat(versions.optimization === 0,
|
|
187
|
+
"Prolog host tests require enabled Python assertions; remove -O/PYTHONOPTIMIZE");
|
|
188
|
+
const probe = "import json,importlib.metadata as m,janus_swi as j; v=j.query_once('current_prolog_flag(version_data,swi(Major,Minor,Patch,_)),use_module(library(plunit)),current_prolog_flag(determinism_error,error)'); print(json.dumps({'janus':m.version('janus-swi'),'swi':[v['Major'],v['Minor'],v['Patch']],'ready':v['truth']}))";
|
|
189
|
+
Object.assign(versions, JSON.parse(await run(target.python || "python3", ["-c", probe], root)));
|
|
190
|
+
requireThat(versions.janus === "1.5.3" && versions.swi[0] === 10 && versions.ready === true,
|
|
191
|
+
"Prolog requires janus-swi 1.5.3, SWI-Prolog 10.x, PLUnit and determinism guards");
|
|
192
|
+
}
|
|
183
193
|
} else if (name === "go") {
|
|
184
194
|
versions.go = (await run("go", ["version"], root)).match(
|
|
185
195
|
/go(\d+\.\d+(?:\.\d+)?)/,
|
|
@@ -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.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"languageProfile": "1.0-rc.2",
|
|
4
|
+
"sources": ["laws"],
|
|
5
|
+
"machineBits": 64,
|
|
6
|
+
"verification": {"layers": ["proof", "exhaustive", "property", "examples", "runtime", "model"]},
|
|
7
|
+
"targets": [{
|
|
8
|
+
"language": "prolog", "root": ".",
|
|
9
|
+
"nativeBindings": {
|
|
10
|
+
"functions": [
|
|
11
|
+
{"declaration": "example.payments::addFee", "native": ["domain", "payments", "apply_fee"]},
|
|
12
|
+
{"declaration": "example.payments::roundTrip", "native": ["domain", "payments", "restore"]},
|
|
13
|
+
{"declaration": "example.payments::archive", "native": ["domain", "payments", "store"]}
|
|
14
|
+
],
|
|
15
|
+
"generators": [
|
|
16
|
+
{"type": "example.payments::type::Money", "factory": ["domain", "payment_generators", "prices"]}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}]
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** <module> Application-owned payments over canonical constructor terms.
|
|
2
|
+
|
|
3
|
+
The fee uses Prolog integer arithmetic, independently of the checked model's
|
|
4
|
+
decimal arithmetic. Aligning decimal exponents preserves every input digit.
|
|
5
|
+
*/
|
|
6
|
+
:- module('domain.payments', [apply_fee/2, restore/2, store/2]).
|
|
7
|
+
|
|
8
|
+
apply_fee(value(Tag, [decimal(Sign, Digits, Exponent), Currency]),
|
|
9
|
+
value(Tag, [decimal(ResultSign, ResultDigits, Scale), Currency])) :-
|
|
10
|
+
foldl(decimal_digit, Digits, 0, Magnitude),
|
|
11
|
+
Coefficient is (1 - 2*Sign)*Magnitude,
|
|
12
|
+
Scale is min(Exponent, -1),
|
|
13
|
+
Sum is Coefficient*10**(Exponent-Scale) + 2*10**(-1-Scale),
|
|
14
|
+
( Sum < 0 -> ResultSign=1 ; ResultSign=0 ),
|
|
15
|
+
Absolute is abs(Sum),
|
|
16
|
+
number_codes(Absolute, Codes),
|
|
17
|
+
maplist(digit_code, ResultDigits, Codes).
|
|
18
|
+
|
|
19
|
+
decimal_digit(Digit, Previous, Result) :- Result is Previous*10 + Digit.
|
|
20
|
+
digit_code(Digit, Code) :- Digit is Code - 0'0.
|
|
21
|
+
|
|
22
|
+
restore(Payment, Payment).
|
|
23
|
+
store(Payments, Payments).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** <module> Native strategy factory with Hypothesis's ordinary shrinker.
|
|
2
|
+
|
|
3
|
+
Janus retains child and result strategies as Python objects. The generated
|
|
4
|
+
schema validates every generated native value and every candidate shrink.
|
|
5
|
+
*/
|
|
6
|
+
:- module('domain.payment_generators', [prices/1]).
|
|
7
|
+
:- use_module(library(janus)).
|
|
8
|
+
|
|
9
|
+
prices(Strategy) :-
|
|
10
|
+
py_call('hypothesis.strategies':integers(100, 200), Cents, [py_object(true)]),
|
|
11
|
+
py_call('hypothesis.strategies':just(-2), Exponent, [py_object(true)]),
|
|
12
|
+
py_call(lawspec_runtime:make_decimal, Decimal, [py_object(true)]),
|
|
13
|
+
py_call('hypothesis.strategies':builds(Decimal, Cents, Exponent), Amounts, [py_object(true)]),
|
|
14
|
+
py_call(lawspec_data:'CurrencyEUR'(), Euro, [py_object(true)]),
|
|
15
|
+
py_call('hypothesis.strategies':just(Euro), Currencies, [py_object(true)]),
|
|
16
|
+
py_call(lawspec_data:'Money', Money, [py_object(true)]),
|
|
17
|
+
py_call('hypothesis.strategies':builds(Money, Amounts, Currencies), Strategy, [py_object(true)]).
|
|
@@ -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
|
|
@@ -4,9 +4,9 @@ unit example.approvals
|
|
|
4
4
|
-- own unit, so the adapters can call the workflow on every target (a Haskell
|
|
5
5
|
-- workflow imports its steps' module).
|
|
6
6
|
|
|
7
|
-
-- Approves order n under the real clock: whether
|
|
8
|
-
--
|
|
9
|
-
--
|
|
7
|
+
-- Approves order n under the real clock: whether the slow order's two checks
|
|
8
|
+
-- overlapped in time, which they do only when they run at the same time. Run
|
|
9
|
+
-- one after the other they cannot overlap, however loaded the machine is.
|
|
10
10
|
async approvedQuickly :: Int64 -> Bool
|
|
11
11
|
|
|
12
12
|
law "|an all group's checks run at the same time| is
|
|
@@ -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
|
|