lawspec 0.25.0 → 0.27.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 (156) hide show
  1. package/CHANGELOG.md +109 -1
  2. package/NORMALIZATION-LICENSES.txt +296 -0
  3. package/README.md +13 -4
  4. package/api.mjs +0 -8
  5. package/bin/lawspec.mjs +114 -79
  6. package/build.json +99 -117
  7. package/core.wasm +2 -2
  8. package/core_jsffi.js +5 -0
  9. package/doctor.mjs +14 -4
  10. package/examples/native-payments/clojure/lawspec.json +1 -1
  11. package/examples/native-payments/csharp/lawspec.json +1 -1
  12. package/examples/native-payments/elixir/lawspec.json +1 -1
  13. package/examples/native-payments/erlang/lawspec.json +1 -1
  14. package/examples/native-payments/fsharp/lawspec.json +1 -1
  15. package/examples/native-payments/gleam/lawspec.json +1 -1
  16. package/examples/native-payments/go/lawspec.json +1 -1
  17. package/examples/native-payments/groovy/lawspec.json +1 -1
  18. package/examples/native-payments/haskell/lawspec.json +1 -1
  19. package/examples/native-payments/java/lawspec.json +1 -1
  20. package/examples/native-payments/javascript/lawspec.json +1 -1
  21. package/examples/native-payments/kotlin/lawspec.json +1 -1
  22. package/examples/native-payments/prolog/lawspec.json +20 -0
  23. package/examples/native-payments/prolog/src/domain/payments.pl +23 -0
  24. package/examples/native-payments/prolog/tests/domain/payment_generators.pl +17 -0
  25. package/examples/native-payments/python/lawspec.json +1 -1
  26. package/examples/native-payments/rust/lawspec.json +1 -1
  27. package/examples/native-payments/scala/lawspec.json +1 -1
  28. package/examples/native-payments/swift/lawspec.json +1 -1
  29. package/examples/native-payments/typescript/lawspec.json +1 -1
  30. package/examples/packages/orders/lawspec.json +1 -1
  31. package/examples/packages/orders/orders.lawspec +27 -25
  32. package/examples/packages/shop-domain/src/domain.lawspec +15 -14
  33. package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
  34. package/examples/packages/shop-tax-1/src/rates.lawspec +1 -0
  35. package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
  36. package/examples/packages/shop-tax-2/src/rates.lawspec +1 -0
  37. package/examples/rc1/authorization-snapshots.lawspec +24 -23
  38. package/examples/rc1/banner-filenames.lawspec +7 -6
  39. package/examples/rc1/bit-codec.lawspec +12 -11
  40. package/examples/rc1/bounded-witness-search.lawspec +52 -45
  41. package/examples/rc1/conflicting-requirements.lawspec +8 -7
  42. package/examples/rc1/constructive-witnesses.lawspec +40 -33
  43. package/examples/rc1/documentary-review.lawspec +9 -8
  44. package/examples/rc1/empty-domains.lawspec +16 -15
  45. package/examples/rc1/finite-integer-domains.lawspec +24 -23
  46. package/examples/rc1/law-metadata.lawspec +6 -5
  47. package/examples/rc1/native-payments.lawspec +17 -16
  48. package/examples/rc1/nesting/rrr.lawspec +4 -3
  49. package/examples/rc1/nesting/rru.lawspec +7 -6
  50. package/examples/rc1/nesting/rur.lawspec +7 -6
  51. package/examples/rc1/nesting/ruu.lawspec +10 -9
  52. package/examples/rc1/nesting/urr.lawspec +7 -6
  53. package/examples/rc1/nesting/uru.lawspec +10 -9
  54. package/examples/rc1/nesting/uur.lawspec +10 -9
  55. package/examples/rc1/nesting/uuu.lawspec +13 -12
  56. package/examples/rc1/order-workflow.lawspec +18 -17
  57. package/examples/rc1/parcel-measurements.lawspec +14 -13
  58. package/examples/rc1/picture-records.lawspec +6 -5
  59. package/examples/rc1/picture-tuples.lawspec +6 -5
  60. package/examples/rc1/record-payloads.lawspec +12 -11
  61. package/examples/rc1/recursive-records.lawspec +11 -10
  62. package/examples/rc1/refund-conformance.lawspec +7 -6
  63. package/examples/rc1/refund-policy.lawspec +15 -14
  64. package/examples/rc1/requirement-composition.lawspec +26 -25
  65. package/examples/rc1/structural-records.lawspec +13 -12
  66. package/examples/rc1-authoring.lawspec +6 -5
  67. package/examples/specs/abilities.lawspec +67 -65
  68. package/examples/specs/ability_imports.lawspec +58 -57
  69. package/examples/specs/actors.lawspec +23 -22
  70. package/examples/specs/algebra.lawspec +142 -141
  71. package/examples/specs/approvals.lawspec +19 -18
  72. package/examples/specs/async_bindings.lawspec +10 -9
  73. package/examples/specs/async_fetch.lawspec +12 -11
  74. package/examples/specs/atoi_codec.lawspec +16 -15
  75. package/examples/specs/boolean_flags.lawspec +10 -9
  76. package/examples/specs/builtins.lawspec +73 -72
  77. package/examples/specs/canonical_url.lawspec +14 -13
  78. package/examples/specs/collections.lawspec +153 -154
  79. package/examples/specs/composition.lawspec +70 -66
  80. package/examples/specs/concurrent_collections.lawspec +8 -7
  81. package/examples/specs/consistency.lawspec +4 -3
  82. package/examples/specs/contracts.lawspec +80 -79
  83. package/examples/specs/crypto.lawspec +26 -25
  84. package/examples/specs/ctc.lawspec +148 -0
  85. package/examples/specs/currying.lawspec +32 -31
  86. package/examples/specs/data_types.lawspec +50 -49
  87. package/examples/specs/distribution.lawspec +57 -56
  88. package/examples/specs/domain_modeling.lawspec +68 -47
  89. package/examples/specs/durations.lawspec +39 -38
  90. package/examples/specs/equivalent.lawspec +25 -24
  91. package/examples/specs/failures.lawspec +64 -63
  92. package/examples/specs/finite_data.lawspec +32 -31
  93. package/examples/specs/flow_stack.lawspec +64 -63
  94. package/examples/specs/gadt_expressions.lawspec +50 -49
  95. package/examples/specs/generation.lawspec +115 -114
  96. package/examples/specs/handler_bindings.lawspec +42 -40
  97. package/examples/specs/handles.lawspec +2 -1
  98. package/examples/specs/harness.lawspec +45 -43
  99. package/examples/specs/harness_testing.lawspec +18 -13
  100. package/examples/specs/indexed_arithmetic.lawspec +401 -126
  101. package/examples/specs/indexed_families.lawspec +182 -66
  102. package/examples/specs/keywords.lawspec +22 -21
  103. package/examples/specs/limits.lawspec +7 -6
  104. package/examples/specs/list_contracts.lawspec +121 -120
  105. package/examples/specs/list_refinements.lawspec +43 -42
  106. package/examples/specs/lists.lawspec +45 -44
  107. package/examples/specs/matchers.lawspec +79 -78
  108. package/examples/specs/matching.lawspec +43 -42
  109. package/examples/specs/mixed_inputs.lawspec +25 -24
  110. package/examples/specs/models.lawspec +44 -43
  111. package/examples/specs/parse_port.lawspec +28 -27
  112. package/examples/specs/payments.lawspec +55 -54
  113. package/examples/specs/railway.lawspec +59 -58
  114. package/examples/specs/records.lawspec +149 -148
  115. package/examples/specs/records_inner.lawspec +5 -4
  116. package/examples/specs/recursive_refinements.lawspec +30 -29
  117. package/examples/specs/refined_definitions.lawspec +24 -23
  118. package/examples/specs/refinements.lawspec +58 -57
  119. package/examples/specs/resilience.lawspec +161 -160
  120. package/examples/specs/resources.lawspec +61 -60
  121. package/examples/specs/scalar_adapters.lawspec +60 -59
  122. package/examples/specs/scalar_catalog.lawspec +165 -164
  123. package/examples/specs/scalars.lawspec +78 -77
  124. package/examples/specs/scheduling_order.lawspec +8 -7
  125. package/examples/specs/scheduling_overlap.lawspec +5 -4
  126. package/examples/specs/sequences.lawspec +66 -65
  127. package/examples/specs/sessions.lawspec +13 -12
  128. package/examples/specs/slug.lawspec +16 -15
  129. package/examples/specs/sum_refinements.lawspec +42 -41
  130. package/examples/specs/tables.lawspec +29 -28
  131. package/examples/specs/total_functions.lawspec +71 -70
  132. package/examples/specs/workflows.lawspec +101 -100
  133. package/examples-command.mjs +7 -7
  134. package/explain.mjs +6 -4
  135. package/expression-presentation.mjs +8 -8
  136. package/files.mjs +1 -1
  137. package/index.d.ts +10 -528
  138. package/launcher.mjs +9 -2
  139. package/lsp.mjs +10 -6
  140. package/native-evidence.mjs +25 -12
  141. package/native-examples.mjs +3 -3
  142. package/package.json +2 -1
  143. package/starter-rc1.lawspec +6 -5
  144. package/starter.lawspec +16 -15
  145. package/templates.mjs +88 -5
  146. package/test-command.mjs +40 -4
  147. package/migrate.mjs +0 -135
  148. package/migration-bindings.mjs +0 -86
  149. package/migration-cases.mjs +0 -45
  150. package/migration-collections.mjs +0 -54
  151. package/migration-correspondence.mjs +0 -275
  152. package/migration-generation.mjs +0 -99
  153. package/migration-laws.mjs +0 -102
  154. package/migration-records.mjs +0 -166
  155. package/migration-source.mjs +0 -247
  156. package/migration-write.mjs +0 -156
@@ -8,10 +8,10 @@ law "|each item has a match| (relation of type a -> b -> Bool) is
8
8
  for all (item of type b) =>
9
9
  there exists (witness of type a) such that
10
10
  relation witness item
11
- end
12
- end
13
- end
14
- end
11
+ end exists
12
+ end for all
13
+ end definition
14
+ end law
15
15
 
16
16
  function revokedMatch (authorization of type Authorization)
17
17
  (payment of type Payment) -> Bool is
@@ -26,25 +26,25 @@ law "|matching and readiness agree| is
26
26
  there exists (authorization of type Authorization
27
27
  where active Ready authorization) such that
28
28
  authorizes authorization payment
29
- end
30
- end)
31
- end
29
+ end exists
30
+ end for all)
31
+ end definition
32
32
 
33
33
  description:
34
34
  "Every payment has a matching identity and an active approval when ready."
35
- end
36
- end
35
+ end description
36
+ end law
37
37
 
38
38
  law "|revocation or matching has a complete explanation| is
39
39
  definition:
40
40
  (must not apply law "|each item has a match| revokedMatch)
41
41
  or apply law "|each item has a match| authorizes
42
- end
42
+ end definition
43
43
 
44
44
  description:
45
45
  "Either revoked approvals cannot cover every payment, or matching succeeds."
46
- end
47
- end
46
+ end description
47
+ end law
48
48
 
49
49
  law "|matching implies ready approval coverage| is
50
50
  definition:
@@ -54,36 +54,37 @@ law "|matching implies ready approval coverage| is
54
54
  there exists (authorization of type Authorization
55
55
  where active Ready authorization) such that
56
56
  authorizes authorization payment
57
- end
58
- end)
59
- end
60
- end
57
+ end exists
58
+ end for all)
59
+ end definition
60
+ end law
61
61
 
62
62
  law "|payment and approval identities have separate scopes| is
63
63
  definition:
64
64
  (for all (value of type Payment) =>
65
65
  value = FirstPayment or value = SecondPayment
66
- end)
66
+ end for all)
67
67
  and
68
68
  (for all (value of type Authorization) =>
69
69
  value = FirstApproval or value = SecondApproval
70
- end)
71
- end
72
- end
70
+ end for all)
71
+ end definition
72
+ end law
73
73
 
74
74
  law "|an empty condition does not hide required coverage| is
75
75
  definition:
76
76
  (for all (authorization of type Authorization where false) =>
77
77
  false
78
- end)
78
+ end for all)
79
79
  and
80
80
  (there exists (authorization of type Authorization
81
81
  where active Ready authorization) such that
82
82
  authorizes authorization FirstPayment
83
- end)
84
- end
83
+ end exists)
84
+ end definition
85
85
 
86
86
  rationale:
87
87
  "A vacuous first clause leaves the approval requirement in force."
88
- end
89
- end
88
+ end rationale
89
+ end law
90
+ end unit
@@ -17,37 +17,38 @@ law doubles is
17
17
  definition:
18
18
  for all (value of type record{count of type Integer}) =>
19
19
  (double value).count must be value.count + value.count
20
- end
21
- end
20
+ end for all
21
+ end definition
22
22
 
23
23
  expect double value = expected
24
24
  in table (value, expected):
25
25
  row record{count = -1}, record{count = -2}
26
26
  row record{count = 0}, record{count = 0}
27
27
  row record{count = 1}, record{count = 2}
28
- end
29
- end
28
+ end table
29
+ end law
30
30
 
31
31
  law wraps is
32
32
  definition:
33
33
  (wrap true).wrapped must be true
34
- end
35
- end
34
+ end definition
35
+ end law
36
36
 
37
37
  law ordered is
38
38
  definition:
39
39
  record{a = 1, b = true} must be record{b = true, a = 1}
40
- end
41
- end
40
+ end definition
41
+ end law
42
42
 
43
43
  law nested is
44
44
  definition:
45
45
  record{inner = record{count = 4}}.inner.count must be 4
46
- end
47
- end
46
+ end definition
47
+ end law
48
48
 
49
49
  law empty is
50
50
  definition:
51
51
  record{} must be record{}
52
- end
53
- end
52
+ end definition
53
+ end law
54
+ end unit
@@ -7,21 +7,21 @@ end function
7
7
  law "|addition preserves the inputs| is
8
8
  description:
9
9
  "Adding two amounts gives their mathematical sum."
10
- end
10
+ end description
11
11
 
12
12
  definition:
13
13
  for all (a of type Integer) (b of type Integer) =>
14
14
  a `|adds the values| b must be a + b
15
- end
16
- end
15
+ end for all
16
+ end definition
17
17
 
18
18
  expect "|adds the values| a b = expected
19
19
  in table (a, b, expected):
20
20
  row -1, 1, 0
21
21
  row 0, 0, 0
22
22
  row 1, 2, 3
23
- end
24
- end
23
+ end table
24
+ end law
25
25
 
26
26
  type Picture is a record{
27
27
  fileName of type Text
@@ -54,3 +54,4 @@ function "|picture category| (width of type Nat) -> Text is
54
54
  otherwise "large"
55
55
  end case
56
56
  end function
57
+ end unit
@@ -5,9 +5,9 @@ unit example.abilities
5
5
  -- Gateway says so, and every law about it holds for every lawful handler:
6
6
  -- the native one written by hand, and each spec handler below.
7
7
 
8
- type Payment is | Approved cents :: Int32 | Declined end
9
- type Receipt is Receipt cents :: Int32 end
10
- type PaymentError is | Refused | TooLarge end
8
+ type Payment is one of | Approved of type Int32 | Declined end type
9
+ type Receipt is a record{ cents :: Int32} end type
10
+ type PaymentError is one of | Refused | TooLarge end type
11
11
 
12
12
  -- A payment gateway. Its laws are obligations on every handler.
13
13
  ability Gateway is
@@ -15,89 +15,91 @@ ability Gateway is
15
15
  capture :: Int32 -> Receipt
16
16
  fee :: Int32
17
17
  laws
18
- law `a receipt is for the amount captured` is
19
- definition is `for all` (cents :: Int32) . capture cents = Receipt cents end
20
- end
21
- law `an approval is for the amount asked` is
22
- definition is
23
- `for all` (cents :: Int32) .
24
- (match authorize cents with
25
- | Approved approved -> approved == cents
26
- | Declined -> true
27
- end) = true
28
- end
29
- end
30
- law `the fee is never negative` is
31
- definition is fee >= 0 end
32
- end
33
- end
18
+ law "|a receipt is for the amount captured| is
19
+ definition : for all (cents :: Int32) => capture cents = Receipt record{ cents = cents} end for all end definition
20
+ end law
21
+ law "|an approval is for the amount asked| is
22
+ definition :
23
+ for all (cents :: Int32) =>
24
+ (first matching case of authorize cents :
25
+ when Approved approved then approved = cents
26
+ when Declined then true
27
+ end case) = true end for all
28
+ end definition
29
+ end law
30
+ law "|the fee is never negative| is
31
+ definition : fee >= 0 end definition
32
+ end law
33
+ end laws
34
+ end ability
34
35
 
35
36
  -- A fake for tests: it approves small amounts.
36
37
  handler fakeGateway for Gateway is
37
- authorize cents is if cents <= 10000 then Approved cents else Declined end
38
- capture cents is Receipt cents end
39
- fee is 30 end
40
- end
38
+ operation authorize cents is if cents <= 10000 then Approved cents else Declined end if end operation
39
+ operation capture cents is Receipt record{ cents = cents} end operation
40
+ operation fee is 30 end operation
41
+ end handler
41
42
 
42
43
  -- A handler with state: it keeps every amount it captured.
43
44
  handler keepingGateway for Gateway with state captured :: List Int32 start [] is
44
- authorize cents is Approved cents end
45
- capture cents is ~captured := Cons cents captured; Receipt cents end
46
- fee is 0 end
47
- end
45
+ operation authorize cents is Approved cents end operation
46
+ operation capture cents is ~captured := Cons cents captured; Receipt record{ cents = cents} end operation
47
+ operation fee is 0 end operation
48
+ end handler
48
49
 
49
50
  -- A checked definition that uses Gateway. Its row, {Gateway}, is inferred.
50
- definition checkout (cents :: Int32) :: Bool is
51
- match authorize cents with
52
- | Approved amount -> (match capture amount with | Receipt paid -> paid == cents end)
53
- | Declined -> false
54
- end
55
- end
51
+ procedure checkout (cents :: Int32) -> Bool is
52
+ first matching case of authorize cents :
53
+ when Approved amount then (first matching case of capture amount : when Receipt record{ cents = paid} then paid = cents end case)
54
+ when Declined then false
55
+ end case
56
+ end procedure
56
57
 
57
58
  -- A native adapter that uses Gateway: it gets a handler as its first
58
59
  -- argument.
59
60
  charge :: Int32 -> Bool uses Gateway
60
61
 
61
62
  -- A definition that can fail says what it fails with.
62
- definition pay (cents :: Int32) :: Receipt uses Gateway fails with PaymentError is
63
+ procedure pay (cents :: Int32) -> Receipt uses Gateway fails with PaymentError is
63
64
  if cents > 100000 then raise TooLarge else
64
- match authorize cents with
65
- | Approved amount -> capture amount
66
- | Declined -> raise Refused
67
- end
68
- end
65
+ first matching case of authorize cents :
66
+ when Approved amount then capture amount
67
+ when Declined then raise Refused
68
+ end case end if
69
+ end procedure
69
70
 
70
71
  -- Counting calls is part of the claim, so the law names a recording
71
72
  -- handler. Which gateway it records is left to the harness: each lawful one.
72
- law `checkout captures once, and only when it succeeds` using recording Gateway is
73
- definition is
74
- `for all` (cents :: Int32) .
75
- (if checkout cents then calls of capture with (cents) == 1 else calls of capture == 0) = true
76
- end
77
- end
73
+ law "|checkout captures once, and only when it succeeds| using recording Gateway is
74
+ definition :
75
+ for all (cents :: Int32) =>
76
+ (if checkout cents then calls of capture with (cents) = 1 else calls of capture = 0 end if) = true end for all
77
+ end definition
78
+ end law
78
79
 
79
- law `charge captures once, and only when it succeeds` using recording Gateway is
80
- definition is
81
- `for all` (cents :: Int32) .
82
- (if charge cents then calls of capture with (cents) == 1 else calls of capture == 0) = true
83
- end
84
- end
80
+ law "|charge captures once, and only when it succeeds| using recording Gateway is
81
+ definition :
82
+ for all (cents :: Int32) =>
83
+ (if charge cents then calls of capture with (cents) = 1 else calls of capture = 0 end if) = true end for all
84
+ end definition
85
+ end law
85
86
 
86
87
  -- This law needs the fake's limit, so the fake is part of the claim.
87
- law `large payments fail` using fakeGateway is
88
- definition is
89
- `for all` (cents :: Int32 where cents > 100000) . prelude.attempt (pay cents) = Left TooLarge
90
- end
91
- end
88
+ law "|large payments fail| using fakeGateway is
89
+ definition :
90
+ for all (cents :: Int32 where cents > 100000) => prelude.attempt (pay cents) = Left TooLarge end for all
91
+ end definition
92
+ end law
92
93
 
93
- law `a declined payment is refused` using fakeGateway is
94
- definition is
95
- `for all` (cents :: Int32 where cents > 10000 && cents <= 100000) .
96
- prelude.attempt (pay cents) = Left Refused
97
- end
98
- end
94
+ law "|a declined payment is refused| using fakeGateway is
95
+ definition :
96
+ for all (cents :: Int32 where cents > 10000 && cents <= 100000) =>
97
+ prelude.attempt (pay cents) = Left Refused end for all
98
+ end definition
99
+ end law
99
100
 
100
101
  -- Without `using`, a law runs under each lawful handler in turn.
101
- law `the fee is small` is
102
- definition is fee <= 100 end
103
- end
102
+ law "|the fee is small| is
103
+ definition : fee <= 100 end definition
104
+ end law
105
+ end unit
@@ -9,99 +9,100 @@ import example.abilities as payments
9
9
  -- and goes on with `;`.
10
10
  ability Log is
11
11
  note :: Text -> Unit
12
- end
12
+ end ability
13
13
 
14
14
  -- A log that keeps what it is told.
15
15
  handler keptLog for Log with state lines :: List Text start [] is
16
- note message is ~lines := Cons message lines; unitValue end
17
- end
16
+ operation note message is ~lines := Cons message lines; unitValue end operation
17
+ end handler
18
18
 
19
19
  -- A store of one value, at any type. This unit uses it at two.
20
20
  ability Store (a :: Type) is
21
21
  load :: a
22
22
  save :: a -> Unit
23
- end
23
+ end ability
24
24
 
25
25
  handler countStore for Store Int32 with state count :: Int32 start 0 is
26
- load is count end
27
- save value is ~count := value; unitValue end
28
- end
26
+ operation load is count end operation
27
+ operation save value is ~count := value; unitValue end operation
28
+ end handler
29
29
 
30
30
  handler nameStore for Store Text with state name :: Text start "" is
31
- load is name end
32
- save value is ~name := value; unitValue end
33
- end
31
+ operation load is name end operation
32
+ operation save value is ~name := value; unitValue end operation
33
+ end handler
34
34
 
35
35
  -- A meter whose readings are never negative: every handler owes that.
36
36
  ability Meter is
37
37
  reading :: (r :: Int32 where r >= 0)
38
- end
38
+ end ability
39
39
 
40
40
  handler fixedMeter for Meter is
41
- reading is 7 end
42
- end
41
+ operation reading is 7 end operation
42
+ end handler
43
43
 
44
44
  -- A handler whose clauses use another ability: it notes each payment.
45
45
  handler notingGateway for Gateway is
46
- authorize cents is note "authorize"; Approved cents end
47
- capture cents is note "capture"; Receipt cents end
48
- fee is 0 end
49
- end
46
+ operation authorize cents is note "authorize"; Approved cents end operation
47
+ operation capture cents is note "capture"; Receipt cents end operation
48
+ operation fee is 0 end operation
49
+ end handler
50
50
 
51
51
  -- Effects run in order: `a; b` runs a, then b; `let x = e in body` runs e
52
52
  -- once and names its value.
53
- definition buy (cents :: Int32) :: Bool uses Gateway, Log is
53
+ procedure buy (cents :: Int32) -> Bool uses Gateway, Log is
54
54
  note "buying";
55
55
  let approved = payments.checkout cents in
56
56
  note "bought";
57
- approved
58
- end
57
+ approved end let
58
+ end procedure
59
59
 
60
60
  -- handle ... with h end runs its body with h answering h's ability, so the
61
61
  -- definition does not use that ability itself.
62
- definition trial (cents :: Int32) :: Bool is
63
- handle payments.checkout cents with fakeGateway end
64
- end
62
+ function trial (cents :: Int32) -> Bool is
63
+ handle payments.checkout cents with fakeGateway end handle
64
+ end function
65
65
 
66
- definition remember (count :: Int32) :: Int32 uses Store Int32 is
66
+ procedure remember (count :: Int32) -> Int32 uses Store Int32 is
67
67
  save count; load
68
- end
68
+ end procedure
69
69
 
70
- definition rename (name :: Text) :: Text uses Store Text is
70
+ procedure rename (name :: Text) -> Text uses Store Text is
71
71
  save name; load
72
- end
72
+ end procedure
73
73
 
74
74
  -- A native adapter that may fail. Its native code raises the failure
75
75
  -- through the runtime's Fail.
76
76
  refund :: Int32 -> Int32 uses Gateway fails with payments.PaymentError
77
77
 
78
- law `trial approves small amounts` is
79
- definition is
80
- `for all` (cents :: Int32 where cents >= 0 && cents <= 10000) . trial cents = true
81
- end
82
- end
83
-
84
- law `buying with a noting gateway approves small amounts` using notingGateway, keptLog is
85
- definition is
86
- `for all` (cents :: Int32 where cents >= 0 && cents <= 10000) . buy cents = true
87
- end
88
- end
89
-
90
- law `a stored count comes back` is
91
- definition is `for all` (count :: Int32) . remember count = count end
92
- end
93
-
94
- law `a stored name comes back` is
95
- definition is `for all` (name :: Text) . rename name = name end
96
- end
97
-
98
- law `a reading is small` using fixedMeter is
99
- definition is reading <= 100 end
100
- end
101
-
102
- law `refunds of large amounts fail` is
103
- definition is
104
- `for all` (cents :: Int32 where cents > 100000) .
105
- prelude.attempt (refund cents) = Left payments.TooLarge
106
- end
107
- end
78
+ law "|trial approves small amounts| is
79
+ definition :
80
+ for all (cents :: Int32 where cents >= 0 && cents <= 10000) => trial cents = true end for all
81
+ end definition
82
+ end law
83
+
84
+ law "|buying with a noting gateway approves small amounts| using notingGateway, keptLog is
85
+ definition :
86
+ for all (cents :: Int32 where cents >= 0 && cents <= 10000) => buy cents = true end for all
87
+ end definition
88
+ end law
89
+
90
+ law "|a stored count comes back| is
91
+ definition : for all (count :: Int32) => remember count = count end for all end definition
92
+ end law
93
+
94
+ law "|a stored name comes back| is
95
+ definition : for all (name :: Text) => rename name = name end for all end definition
96
+ end law
97
+
98
+ law "|a reading is small| using fixedMeter is
99
+ definition : reading <= 100 end definition
100
+ end law
101
+
102
+ law "|refunds of large amounts fail| is
103
+ definition :
104
+ for all (cents :: Int32 where cents > 100000) =>
105
+ prelude.attempt (refund cents) = Left payments.TooLarge end for all
106
+ end definition
107
+ end law
108
+ end unit
@@ -7,7 +7,7 @@ unit example.actors
7
7
  -- from several callers at once. Runs also crash the actor between
8
8
  -- messages: it restarts from its last state by reopen, and the model's state
9
9
  -- follows modelReopen.
10
- type Account is Account balance :: Int64 end
10
+ type Account is a record{ balance :: Int64} end type
11
11
 
12
12
  openAccount :: Unit -> Account
13
13
  deposit :: Account -> UInt8 -> Pair Int64 Account
@@ -17,16 +17,16 @@ close :: Account -> Account
17
17
  -- After a crash, the account reopens with the balance it had.
18
18
  reopen :: Account -> Account
19
19
 
20
- definition modelDeposit (amount :: UInt8) (n :: Int64 where n >= 0 && n <= 1000000) :: Pair Int64 Int64 is
20
+ function modelDeposit (amount :: UInt8) (n :: Int64 where n >= 0 && n <= 1000000) -> Pair Int64 Int64 is
21
21
  Pair (n + amount) (n + amount)
22
- end
22
+ end function
23
23
 
24
- definition modelWithdrawAll (n :: Int64) :: Pair Int64 Int64 is Pair n 0 end
24
+ function modelWithdrawAll (n :: Int64) -> Pair Int64 Int64 is Pair n 0 end function
25
25
 
26
- definition modelBalance (n :: Int64) :: Pair Int64 Int64 is Pair n n end
27
- definition modelClose (n :: Int64) :: Int64 is 0 end
28
- definition modelReopen (n :: Int64) :: Int64 is n end
29
- definition solvent (n :: Int64) :: Bool is n >= 0 end
26
+ function modelBalance (n :: Int64) -> Pair Int64 Int64 is Pair n n end function
27
+ function modelClose (n :: Int64) -> Int64 is 0 end function
28
+ function modelReopen (n :: Int64) -> Int64 is n end function
29
+ function solvent (n :: Int64) -> Bool is n >= 0 end function
30
30
 
31
31
  actor account :: Account by Int64 is
32
32
  start openAccount by 0
@@ -36,15 +36,15 @@ actor account :: Account by Int64 is
36
36
  on balance by modelBalance
37
37
  on close by modelClose
38
38
  invariant solvent
39
- end
39
+ end actor
40
40
 
41
41
  -- Implementation code uses the generated typed actor: depositTwice starts an
42
42
  -- account and deposits from two callers at once.
43
43
  depositTwice :: UInt8 -> Int64
44
44
 
45
- law `two callers' deposits both land` is
46
- definition is `for all` (x :: UInt8) . depositTwice x = 2 * x end
47
- end
45
+ law "|two callers' deposits both land| is
46
+ definition : for all (x :: UInt8) => depositTwice x = 2 * x end for all end definition
47
+ end law
48
48
 
49
49
  -- A supervisor starts its actors and restarts them after a crash: one for
50
50
  -- one restarts only the actor that crashed. The account restarts from its
@@ -53,22 +53,22 @@ supervisor bank is
53
53
  one for one
54
54
  at most 3 restarts in 5s
55
55
  permanent account
56
- end
56
+ end supervisor
57
57
 
58
58
  -- survivesCrash starts the bank, deposits, crashes the account, and reads
59
59
  -- its balance through the same handle.
60
60
  survivesCrash :: UInt8 -> Int64
61
61
 
62
- law `a crashed account keeps its balance` is
63
- definition is `for all` (x :: UInt8) . survivesCrash x = x end
64
- end
62
+ law "|a crashed account keeps its balance| is
63
+ definition : for all (x :: UInt8) => survivesCrash x = x end for all end definition
64
+ end law
65
65
 
66
66
  -- A scenario runs the actor's messages from processes that talk over
67
67
  -- channels. Some runs crash one process at a random point: a receive from a
68
68
  -- process that failed runs its or else instead of waiting forever.
69
69
  protocol Receipt is
70
70
  send Int64
71
- end
71
+ end protocol
72
72
 
73
73
  scenario `a deposit's receipt, or the balance if the teller fails` in account is
74
74
  channel receipt :: Receipt
@@ -78,10 +78,10 @@ scenario `a deposit's receipt, or the balance if the teller fails` in account is
78
78
  with
79
79
  receive receipt m or else
80
80
  balance
81
- end
81
+ end or else
82
82
  expect m = 5
83
- end
84
- end
83
+ end par
84
+ end scenario
85
85
 
86
86
  -- A mailbox has many senders and one receiver: two tellers report their
87
87
  -- deposits to one auditor, who receives both reports.
@@ -96,5 +96,6 @@ scenario `two tellers report to one auditor` in account is
96
96
  with
97
97
  receive reports first
98
98
  receive reports second
99
- end
100
- end
99
+ end par
100
+ end scenario
101
+ end unit