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
@@ -5,56 +5,57 @@ format :: Text -> Bool -> Int32 -> Text -> Text
5
5
  referenceFormat :: Text -> Bool -> Int32 -> Text -> Text
6
6
  trim :: Text -> Text
7
7
 
8
- law `a four-argument function partially applied twice is commutative` is
9
- definition is
10
- `commutative` (sumFour 1 2)
11
- end
8
+ law "|a four-argument function partially applied twice is commutative| is
9
+ definition :
10
+ apply law "|commutative| (sumFour 1 2)
11
+ end definition
12
12
 
13
- example `the fixed 1 and 2 plus 3 and 4 sum to 10 in either order` is
13
+ example "|the fixed 1 and 2 plus 3 and 4 sum to 10 in either order| :
14
14
  x = 3
15
15
  y = 4
16
16
  expect sumFour 1 2 x y = 10
17
17
  expect sumFour 1 2 y x = 10
18
- end
19
- end
18
+ end example
19
+ end law
20
20
 
21
- law `staged formatter`
21
+ law "|staged formatter|
22
22
  (render :: Int32 -> Text -> Text)
23
23
  (reference :: Int32 -> Text -> Text)
24
24
  is
25
- definition is
26
- `for all` (port :: Int32) (suffix :: Text) .
27
- render port suffix = reference port suffix
28
- end
29
- end
30
-
31
- law `partial application preserves heterogeneous argument order` is
32
- definition is
33
- `staged formatter` (format "port:" true) (referenceFormat "port:" true)
34
- end
35
-
36
- example `port 443 with a tcp suffix formats as port:443/tcp` is
25
+ definition :
26
+ for all (port :: Int32) (suffix :: Text) =>
27
+ render port suffix = reference port suffix end for all
28
+ end definition
29
+ end law
30
+
31
+ law "|partial application preserves heterogeneous argument order| is
32
+ definition :
33
+ apply law "|staged formatter| (format "port:" true) (referenceFormat "port:" true)
34
+ end definition
35
+
36
+ example "|port 443 with a tcp suffix formats as port:443/tcp| :
37
37
  port = 443
38
38
  suffix = "/tcp"
39
39
  expect format "port:" true port suffix = "port:443/tcp"
40
40
  expect referenceFormat "port:" true port suffix = "port:443/tcp"
41
- end
41
+ end example
42
42
 
43
- example `a disabled numeric field keeps the prefix and suffix` is
43
+ example "|a disabled numeric field keeps the prefix and suffix| :
44
44
  port = 443
45
45
  suffix = "/tcp"
46
46
  expect format "port:" false port suffix = "port:/tcp"
47
47
  expect referenceFormat "port:" false port suffix = "port:/tcp"
48
- end
49
- end
48
+ end example
49
+ end law
50
50
 
51
- law `composition accepts a partially applied function` is
52
- definition is
53
- `equivalent` ((format "port:" true 443) . trim) ((referenceFormat "port:" true 443) . trim)
54
- end
51
+ law "|composition accepts a partially applied function| is
52
+ definition :
53
+ apply law "|equivalent| ((format "port:" true 443) . trim) ((referenceFormat "port:" true 443) . trim)
54
+ end definition
55
55
 
56
- example `trim runs before the remaining formatter argument` is
56
+ example "|trim runs before the remaining formatter argument| :
57
57
  x = " /tcp "
58
58
  expect ((format "port:" true 443) . trim) x = "port:443/tcp"
59
- end
60
- end
59
+ end example
60
+ end law
61
+ end unit
@@ -1,66 +1,67 @@
1
1
  unit example.data_types
2
2
 
3
- type Pair (a :: Type) (b :: Type) is
4
- Pair
3
+ type Pair (a :: Type) (b :: Type) is a record{
4
+
5
5
  first :: a
6
- second :: b
7
- end
6
+ second :: b}
7
+ end type
8
8
 
9
- type Tree (a :: Type) is
10
- Leaf value :: a
11
- Branch children :: List (Tree a)
12
- end
9
+ type Tree (a :: Type) is one of
10
+ Leaf of type a
11
+ Branch of type List (Tree a)
12
+ end type
13
13
 
14
- law `products preserve every field` is
15
- definition is
16
- `for all` (pair :: Pair Int8 Bool) .
17
- (match pair with
18
- | Pair first second -> Pair first second
19
- end) = pair
20
- end
21
- example `maximum integer and false` is
22
- pair = Pair 127 false
23
- expect pair = Pair 127 false
24
- end
25
- end
14
+ law "|products preserve every field| is
15
+ definition :
16
+ for all (pair :: Pair Int8 Bool) =>
17
+ (first matching case of pair :
18
+ when Pair record{ first = first , second = second} then Pair record{ first = first , second = second}
19
+ end case) = pair end for all
20
+ end definition
21
+ example "|maximum integer and false| :
22
+ pair = Pair record{ first = 127 , second = false}
23
+ expect pair = Pair record{ first = 127 , second = false}
24
+ end example
25
+ end law
26
26
 
27
- law `sums preserve constructor identity and payloads` is
28
- definition is
29
- `for all` (tree :: Tree Int8) .
30
- (match tree with
31
- | Leaf value -> Leaf value
32
- | Branch children -> Branch children
33
- end) = tree
34
- end
35
- example `nested branches` is
27
+ law "|sums preserve constructor identity and payloads| is
28
+ definition :
29
+ for all (tree :: Tree Int8) =>
30
+ (first matching case of tree :
31
+ when Leaf value then Leaf value
32
+ when Branch children then Branch children
33
+ end case) = tree end for all
34
+ end definition
35
+ example "|nested branches| :
36
36
  tree = Branch [Leaf 127, Branch [], Leaf -128]
37
37
  expect tree = Branch [Leaf 127, Branch [], Leaf -128]
38
- end
39
- end
38
+ end example
39
+ end law
40
40
 
41
41
 
42
42
  -- A refined type argument constrains the corresponding stored fields. This
43
43
  -- predicate becomes a scoped Core traversal, shared by all eight backends.
44
- refinement Positive is (value :: Int8 where value > 0) end
44
+ refinement Positive is (value :: Int8 where value > 0) end refinement
45
45
 
46
- definition positivePair (value :: Positive) :: Pair Positive Bool is
47
- Pair value true
48
- end
46
+ function positivePair (value :: Positive) -> Pair Positive Bool is
47
+ Pair record{ first = value , second = true}
48
+ end function
49
49
 
50
- definition reciprocalFirst (pair :: Pair Positive Bool) :: Rational is
51
- match pair with
52
- | Pair first second -> 1 / first
53
- end
54
- end
50
+ function reciprocalFirst (pair :: Pair Positive Bool) -> Rational is
51
+ first matching case of pair :
52
+ when Pair record{ first = first , second = second} then 1 / first
53
+ end case
54
+ end function
55
55
 
56
- law `named payload contracts justify exact division` is
57
- definition is
58
- `for all` (value :: Positive) .
59
- reciprocalFirst (positivePair value) = 1 / value
60
- end
61
- example `one half` is
56
+ law "|named payload contracts justify exact division| is
57
+ definition :
58
+ for all (value :: Positive) =>
59
+ reciprocalFirst (positivePair value) = 1 / value end for all
60
+ end definition
61
+ example "|one half| :
62
62
  value = 2
63
- expect positivePair value = Pair 2 true
63
+ expect positivePair value = Pair record{ first = 2 , second = true}
64
64
  expect reciprocalFirst (positivePair value) = rational(1, 2)
65
- end
66
- end
65
+ end example
66
+ end law
67
+ end unit
@@ -16,82 +16,82 @@ import lawspec.network
16
16
  encoded :: Text -> UInt64 -> Int32 -> Int32 -> List Text
17
17
  roundTrips :: Text -> UInt64 -> Int32 -> Int32 -> Bool
18
18
 
19
- law `integers on the wire` is
20
- definition is
21
- `for all` (seed :: UInt64) . prelude.length (encoded "(int Integer _ _)" seed 4 4) = 4
22
- end
23
- example `seed 7` is
19
+ law "|integers on the wire| is
20
+ definition :
21
+ for all (seed :: UInt64) => prelude.length (encoded "(int Integer _ _)" seed 4 4) = 4 end for all
22
+ end definition
23
+ example "|seed 7| :
24
24
  seed = 7
25
25
  expect encoded "(int Integer _ _)" seed 4 4 = ["9ddc4f", "eefb17", "8fc703", "8ee709"]
26
26
  expect encoded "(int Int8 -128 127)" 42 4 5 = ["f901", "28", "00", "48", "5c"]
27
- end
28
- end
29
-
30
- law `text, lists, Maybe and Either on the wire` is
31
- definition is
32
- `for all` (seed :: UInt64) . roundTrips "(list (maybe (either (int UInt8 0 255) (text))))" seed 4 8 = true
33
- end
34
- example `vectors` is
27
+ end example
28
+ end law
29
+
30
+ law "|text, lists, Maybe and Either on the wire| is
31
+ definition :
32
+ for all (seed :: UInt64) => roundTrips "(list (maybe (either (int UInt8 0 255) (text))))" seed 4 8 = true end for all
33
+ end definition
34
+ example "|vectors| :
35
35
  seed = 3
36
36
  expect encoded "(text)" seed 4 3 = ["037b5b2c", "0134", "024d54"]
37
37
  expect encoded "(list (maybe (bool)))" 5 3 3 = ["02000101", "0100", "010100"]
38
38
  expect encoded "(either (int UInt8 0 255) (text))" 9 3 4 = ["00ec02", "0000", "00d201", "0100"]
39
- end
40
- end
41
-
42
- law `data types on the wire` is
43
- definition is
44
- `for all` (seed :: UInt64) . roundTrips "(data Shape (ctor Shape::Circle (int Int32 0 100)) (ctor Shape::Box (int Int32 0 100) (int Int32 0 100)) (ctor Shape::Group (list (ref Shape))))" seed 4 8 = true
45
- end
46
- example `vectors` is
39
+ end example
40
+ end law
41
+
42
+ law "|data types on the wire| is
43
+ definition :
44
+ for all (seed :: UInt64) => roundTrips "(data Shape (ctor Shape::Circle (int Int32 0 100)) (ctor Shape::Box (int Int32 0 100) (int Int32 0 100)) (ctor Shape::Group (list (ref Shape))))" seed 4 8 = true end for all
45
+ end definition
46
+ example "|vectors| :
47
47
  seed = 11
48
48
  expect encoded "(data Shape (ctor Shape::Circle (int Int32 0 100)) (ctor Shape::Box (int Int32 0 100) (int Int32 0 100)) (ctor Shape::Group (list (ref Shape))))" seed 3 3 = ["0030", "020201b80100015ac801", "014808"]
49
- end
50
- end
49
+ end example
50
+ end law
51
51
 
52
52
  -- A checked definition that another node evaluates by its content hash.
53
- definition shifted (x :: Int32) :: Int64 is x + 1000 end
53
+ function shifted (x :: Int32) -> Int64 is x + 1000 end function
54
54
 
55
55
  -- Calls that cross a network wait for it, so they are asynchronous.
56
56
  async remoteShifted :: Int32 -> Int64
57
57
 
58
- law `a definition evaluated on another node` is
59
- definition is `for all` (x :: Int32) . remoteShifted x = shifted x end
60
- end
58
+ law "|a definition evaluated on another node| is
59
+ definition : for all (x :: Int32) => remoteShifted x = shifted x end for all end definition
60
+ end law
61
61
 
62
62
  -- An actor served on one node and called from another.
63
- type Tally is Tally count :: Int64 end
63
+ type Tally is a record{ count :: Int64} end type
64
64
 
65
65
  openTally :: Unit -> Tally
66
66
  add :: Tally -> UInt8 -> Pair Int64 Tally
67
67
 
68
- definition modelAdd (n :: UInt8) (total :: Int64 where total >= 0 && total <= 1000000) :: Pair Int64 Int64 is
68
+ function modelAdd (n :: UInt8) (total :: Int64 where total >= 0 && total <= 1000000) -> Pair Int64 Int64 is
69
69
  Pair (total + n) (total + n)
70
- end
70
+ end function
71
71
 
72
72
  actor tally :: Tally by Int64 is
73
73
  start openTally by 0
74
74
  on add by modelAdd
75
- end
75
+ end actor
76
76
 
77
77
  async remoteAdds :: UInt8 -> Int64
78
78
 
79
- law `two calls from another node` is
80
- definition is `for all` (x :: UInt8) . remoteAdds x = 2 * x end
81
- end
79
+ law "|two calls from another node| is
80
+ definition : for all (x :: UInt8) => remoteAdds x = 2 * x end for all end definition
81
+ end law
82
82
 
83
83
  -- A protocol between two nodes: the first end sends a number and receives
84
84
  -- its double.
85
85
  protocol Doubling is
86
86
  send Int32
87
87
  receive Int64
88
- end
88
+ end protocol
89
89
 
90
90
  async remoteDoubling :: Int32 -> Int64
91
91
 
92
- law `a conversation between nodes` is
93
- definition is `for all` (x :: Int32) . remoteDoubling x = 2 * x end
94
- end
92
+ law "|a conversation between nodes| is
93
+ definition : for all (x :: Int32) => remoteDoubling x = 2 * x end for all end definition
94
+ end law
95
95
 
96
96
  -- A mailbox offered on one node and sent to from another: each send waits
97
97
  -- until the mailbox has the message.
@@ -99,22 +99,22 @@ mailbox ledger of Int64
99
99
 
100
100
  async remoteLedger :: Int32 -> Int64
101
101
 
102
- law `messages reach a mailbox on another node` is
103
- definition is `for all` (x :: Int32) . remoteLedger x = 2 * x end
104
- end
102
+ law "|messages reach a mailbox on another node| is
103
+ definition : for all (x :: Int32) => remoteLedger x = 2 * x end for all end definition
104
+ end law
105
105
 
106
106
  -- A channel end sent to another node. A local end stays where it is and
107
107
  -- the sending node relays its conversation, so the end works on its new
108
108
  -- node as it did on the old one.
109
109
  protocol Handoff is
110
110
  send Doubling
111
- end
111
+ end protocol
112
112
 
113
113
  async remoteHandoff :: Int32 -> Int64
114
114
 
115
- law `a channel end handed to another node` is
116
- definition is `for all` (x :: Int32) . remoteHandoff x = 2 * x end
117
- end
115
+ law "|a channel end handed to another node| is
116
+ definition : for all (x :: Int32) => remoteHandoff x = 2 * x end for all end definition
117
+ end law
118
118
 
119
119
  -- An end that is already between nodes moves: its state goes to the new
120
120
  -- node, with any values that reached it, and its peer is told the new
@@ -125,17 +125,17 @@ end
125
125
  protocol Answering is
126
126
  receive Int32
127
127
  send Int64
128
- end
128
+ end protocol
129
129
 
130
130
  protocol Passing is
131
131
  send Answering
132
- end
132
+ end protocol
133
133
 
134
134
  async remoteHandoffOnward :: Int32 -> Int64
135
135
 
136
- law `a channel end moved on twice` is
137
- definition is `for all` (x :: Int32) . remoteHandoffOnward x = 2 * x end
138
- end
136
+ law "|a channel end moved on twice| is
137
+ definition : for all (x :: Int32) => remoteHandoffOnward x = 2 * x end for all end definition
138
+ end law
139
139
 
140
140
  -- The network is secure by default. Each node has an ML-DSA-65 identity;
141
141
  -- the first frame between two nodes waits for a handshake (a signed
@@ -144,9 +144,9 @@ end
144
144
  -- it; no other transport can.
145
145
  async sealedOnTheWire :: Int32 -> Bool
146
146
 
147
- law `frames cross sealed by default` is
148
- definition is `for all` (x :: Int32) . sealedOnTheWire x = true end
149
- end
147
+ law "|frames cross sealed by default| is
148
+ definition : for all (x :: Int32) => sealedOnTheWire x = true end for all end definition
149
+ end law
150
150
 
151
151
  -- Every target computes the same handshake: from these seeds and this
152
152
  -- ciphertext, the same hashes of the hello and welcome, the same session
@@ -156,6 +156,7 @@ end
156
156
  -- key and sealed record (dev/handshake-vector.py makes them).
157
157
  handshakeAgrees :: Text -> Bool
158
158
 
159
- law `the secure handshake agrees across targets` is
160
- definition is handshakeAgrees "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f 404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f 808182838485868788898a8b8c8d8e8f tcp://10.0.0.1:7000 tcp://10.0.0.2:7000 36ed31b7f151b4412fa0898659e567a9fe899394069c31ec9007f98bd63282609999cc959fe9a01b4e9a21d61a866da30cdfb2db3d533e3614a170941f668dbe14b0ed47843bd401f8c76d5c8bc030e33c25cabf09b8fd4e3bdb84fc0fe2d8f1b7fea58f9124cd315d94970a9a9677160ffc00cd22875a598904ddd45c5e94ebea8db52eddd181d50f89a577de6f2cb21836a9da82e68ccf61d7aa72576a9ed6355577af27522b4006af2148510c5e8c901aafca088990811e31791a4c71abb7d96c522ee2de83431dc6db6d13e6b8a8cf8656cb64cf8368b691344d07f3ab75814960f85671890e8ccf6a2cf6b82667ff9a4a09eb59f0168453bc45ade0fa1bf747db6c2179dc1173689897f1dd582f2737f3bc8b6f3b84fa5bda5f204ae845ee5124363cad0ad7a3827c46f3ba55458215b32e748fb075e146880c93e97ca8f0f6b5768ac08d19127a2038889352893f19daccb8a01607805492a3c429df462ee941a73fd396de512d8873e901764b2636e7b03c5562097db59e8e00b08a65667873fdfcff99c805aaf49871d282744ee26118c43186d408ac5a0105c80e2b640d0ba44250887721535d865b1425e193777f4e0967a4d74e17fb14c54befd35d7baadb2caad627bb88e739e8d87616a38ac38bdea36c8b0e6dca981dd7cd15846d4187e2e841d1f6ce704369fddf5957b8827a80c80b1f34f44bab0b48ef26a30486f228c2c023e50ec6fb61c1ced87ab11b41b1e30a7f1a30e2c67e78bffead095b3dfc69205965bf9133a8f3dcc7e074ebaed77fd9f009906228f216a12af663d248c871a3a4b728da3d9987e53416c492da03f9c8f3c6c702f082cfdf8a326268a8e7d3c59f54405eef85c6104207bec5685dab59fdfa94b88cd22a00c8b89a85f71fb09d500b62422fdfac9fc7112aa8f756c3a723d211eeb2081d8858e87b1f480fb4cf80d194527f883be6ff89e648884d62c5df6af29de4119efe1fd5546a120902daa9a087143233432942b828871a1f8ec50081312a3e5363315b5198a5f71849cd9541b4aaaeb956f30a1be583532b1810687f6900c85d05e6e9d066570306c5ced181d90807f85634f1cbed272e8614caa69ddb359862eec8ea23b8e3a741e45e730e1ac9f7832bf4fee8f0a41f77015d0e95394838964bb43032b085cf8af0abe20701c011086474b610fa25185b33e24ea7493f28cc60fd78e5598a612f5c62d14344fa6a08d23231b78830d92c1d816ce3d51f33316c76b7896d789fda34cae5e095e592e73b7c300e9fbeb87aef276c5b0d53e3c120bf204bf8a3c5823e7318bf3e7da8e1abb590f0012a10882f49be91c496b000c28a067014ff1e6734f556b4918f2661faeef5783fbea9ba50340b6532edabf4d89b4113c72e6f92e085fb499a93335d03f616a1ecb5258713e0903c475e043486c78d16d0a4014ec1a065a87ac940e909df94d53109d109bd5b235b0c05b5b81fe202cebabd7cec50e434300eff7b75d910471f8bd400f04a7ffb814051c8b15fe7b7 c8c9cacbcccdcecfd0d1d2d3 046368616e05656e642d33137463703a2f2f31302e302e302e313a373030300e0300022a da31284386e2b951348bda30557cf4b5abb4ad9a1ac15582e99c3b938573a254 9c78ba836e9dcaf2845dceaa7a02c9aad0fe0fd29bb9a5b948635c65aa4b2676 c595a58a85aebe6fb8009a0ca6afc9eb614c7ab4711c08c4f7d34c38420c4abd 4c53010310808182838485868788898a8b8c8d8e8f0040c8c9cacbcccdcecfd0d1d2d314713b317e0cd4b10f4d5b885bc8bc1fa7aae4f824a30442ed569d3eab22fcce44c274bd139e84e8a9960d14a17722544ee187c1" = true end
161
- end
159
+ law "|the secure handshake agrees across targets| is
160
+ definition : handshakeAgrees "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f 404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f 808182838485868788898a8b8c8d8e8f tcp://10.0.0.1:7000 tcp://10.0.0.2:7000 36ed31b7f151b4412fa0898659e567a9fe899394069c31ec9007f98bd63282609999cc959fe9a01b4e9a21d61a866da30cdfb2db3d533e3614a170941f668dbe14b0ed47843bd401f8c76d5c8bc030e33c25cabf09b8fd4e3bdb84fc0fe2d8f1b7fea58f9124cd315d94970a9a9677160ffc00cd22875a598904ddd45c5e94ebea8db52eddd181d50f89a577de6f2cb21836a9da82e68ccf61d7aa72576a9ed6355577af27522b4006af2148510c5e8c901aafca088990811e31791a4c71abb7d96c522ee2de83431dc6db6d13e6b8a8cf8656cb64cf8368b691344d07f3ab75814960f85671890e8ccf6a2cf6b82667ff9a4a09eb59f0168453bc45ade0fa1bf747db6c2179dc1173689897f1dd582f2737f3bc8b6f3b84fa5bda5f204ae845ee5124363cad0ad7a3827c46f3ba55458215b32e748fb075e146880c93e97ca8f0f6b5768ac08d19127a2038889352893f19daccb8a01607805492a3c429df462ee941a73fd396de512d8873e901764b2636e7b03c5562097db59e8e00b08a65667873fdfcff99c805aaf49871d282744ee26118c43186d408ac5a0105c80e2b640d0ba44250887721535d865b1425e193777f4e0967a4d74e17fb14c54befd35d7baadb2caad627bb88e739e8d87616a38ac38bdea36c8b0e6dca981dd7cd15846d4187e2e841d1f6ce704369fddf5957b8827a80c80b1f34f44bab0b48ef26a30486f228c2c023e50ec6fb61c1ced87ab11b41b1e30a7f1a30e2c67e78bffead095b3dfc69205965bf9133a8f3dcc7e074ebaed77fd9f009906228f216a12af663d248c871a3a4b728da3d9987e53416c492da03f9c8f3c6c702f082cfdf8a326268a8e7d3c59f54405eef85c6104207bec5685dab59fdfa94b88cd22a00c8b89a85f71fb09d500b62422fdfac9fc7112aa8f756c3a723d211eeb2081d8858e87b1f480fb4cf80d194527f883be6ff89e648884d62c5df6af29de4119efe1fd5546a120902daa9a087143233432942b828871a1f8ec50081312a3e5363315b5198a5f71849cd9541b4aaaeb956f30a1be583532b1810687f6900c85d05e6e9d066570306c5ced181d90807f85634f1cbed272e8614caa69ddb359862eec8ea23b8e3a741e45e730e1ac9f7832bf4fee8f0a41f77015d0e95394838964bb43032b085cf8af0abe20701c011086474b610fa25185b33e24ea7493f28cc60fd78e5598a612f5c62d14344fa6a08d23231b78830d92c1d816ce3d51f33316c76b7896d789fda34cae5e095e592e73b7c300e9fbeb87aef276c5b0d53e3c120bf204bf8a3c5823e7318bf3e7da8e1abb590f0012a10882f49be91c496b000c28a067014ff1e6734f556b4918f2661faeef5783fbea9ba50340b6532edabf4d89b4113c72e6f92e085fb499a93335d03f616a1ecb5258713e0903c475e043486c78d16d0a4014ec1a065a87ac940e909df94d53109d109bd5b235b0c05b5b81fe202cebabd7cec50e434300eff7b75d910471f8bd400f04a7ffb814051c8b15fe7b7 c8c9cacbcccdcecfd0d1d2d3 046368616e05656e642d33137463703a2f2f31302e302e302e313a373030300e0300022a da31284386e2b951348bda30557cf4b5abb4ad9a1ac15582e99c3b938573a254 9c78ba836e9dcaf2845dceaa7a02c9aad0fe0fd29bb9a5b948635c65aa4b2676 c595a58a85aebe6fb8009a0ca6afc9eb614c7ab4711c08c4f7d34c38420c4abd 4c53010310808182838485868788898a8b8c8d8e8f0040c8c9cacbcccdcecfd0d1d2d314713b317e0cd4b10f4d5b885bc8bc1fa7aae4f824a30442ed569d3eab22fcce44c274bd139e84e8a9960d14a17722544ee187c1" = true end definition
161
+ end law
162
+ end unit
@@ -3,16 +3,16 @@ unit example.ordering
3
3
  -- Constrained primitives. Each wrapper is a distinct type whose constructor
4
4
  -- checks the value, so an out-of-range quantity cannot be constructed,
5
5
  -- generated or decoded from native code. valueOf<Name> unwraps a value.
6
- wrapper UnitQuantity is Int32 where value >= 1 && value <= 1000 end
7
- wrapper OrderId is Text where prelude.length value > 0 end
8
- wrapper NonEmptyList (a :: Type) is List a where prelude.length value > 0 end
6
+ wrapper UnitQuantity is Int32 where value >= 1 && value <= 1000 end wrapper
7
+ wrapper OrderId is Text where prelude.length value > 0 end wrapper
8
+ wrapper NonEmptyList (a :: Type) is List a where prelude.length value > 0 end wrapper
9
9
 
10
10
  -- Each workflow state is its own type. A ValidatedOrder can only hold checked
11
11
  -- values, so no later step needs to validate again.
12
- type UnvalidatedOrder is UnvalidatedOrder id :: Text quantity :: Int32 end
13
- type ValidatedOrder is ValidatedOrder id :: OrderId quantity :: UnitQuantity end
14
- type PricedOrder is PricedOrder id :: OrderId quantity :: UnitQuantity total :: Int64 end
15
- type OrderError is | InvalidOrderId | InvalidQuantity | PriceTooHigh end
12
+ type UnvalidatedOrder is a record{ id :: Text quantity :: Int32} end type
13
+ type ValidatedOrder is a record{ id :: OrderId quantity :: UnitQuantity} end type
14
+ type PricedOrder is a record{ id :: OrderId quantity :: UnitQuantity total :: Int64} end type
15
+ type OrderError is one of | InvalidOrderId | InvalidQuantity | PriceTooHigh end type
16
16
 
17
17
  -- The compiler checks that each step accepts the previous step's state and
18
18
  -- generates placeOrder on every target: the steps run in order and the first
@@ -22,55 +22,76 @@ type OrderError is | InvalidOrderId | InvalidQuantity | PriceTooHigh end
22
22
  workflow placeOrder :: UnvalidatedOrder -> Either OrderError PricedOrder is
23
23
  validateOrder :: UnvalidatedOrder -> Either OrderError ValidatedOrder
24
24
  priceOrder :: ValidatedOrder -> Either OrderError PricedOrder
25
- end
25
+ end workflow
26
26
 
27
27
  firstLine :: NonEmptyList Int32 -> Int32
28
28
 
29
29
  -- An order is placed when it is valid and its total is at most 20000.
30
- law `placing an order prices it` is
31
- definition is
32
- `for all` (input :: UnvalidatedOrder) .
33
- prelude.isRight (placeOrder input) = (match input with
34
- | UnvalidatedOrder id quantity ->
30
+ law "|placing an order prices it| is
31
+ definition :
32
+ for all (input :: UnvalidatedOrder) =>
33
+ prelude.isRight (placeOrder input) = (first matching case of input :
34
+ when UnvalidatedOrder record{ id = id , quantity = quantity} then
35
35
  prelude.length id > 0 && quantity >= 1 && quantity <= 800
36
- end)
37
- end
38
- example `a hundred units` is
39
- input = UnvalidatedOrder "A-1" 100
36
+ end case) end for all
37
+ end definition
38
+ example "|a hundred units| :
39
+ input = UnvalidatedOrder record{ id = "A-1" , quantity = 100}
40
40
  expect prelude.isRight (placeOrder input) = true
41
- end
42
- end
41
+ end example
42
+ example "|the last quantity within the price limit| :
43
+ input = UnvalidatedOrder record{ id = "A-2" , quantity = 800}
44
+ expect prelude.isRight (placeOrder input) = true
45
+ end example
46
+ example "|the first quantity over the price limit| :
47
+ input = UnvalidatedOrder record{ id = "A-3" , quantity = 801}
48
+ expect prelude.isRight (placeOrder input) = false
49
+ end example
50
+ end law
43
51
 
44
- law `validation accepts exactly the valid orders` is
45
- definition is
46
- `for all` (input :: UnvalidatedOrder) .
47
- (match validateOrder input with
48
- | Left e -> false
49
- | Right v -> true
50
- end) = (match input with
51
- | UnvalidatedOrder id quantity ->
52
+ law "|validation accepts exactly the valid orders| is
53
+ definition :
54
+ for all (input :: UnvalidatedOrder) =>
55
+ (first matching case of validateOrder input :
56
+ when Left e then false
57
+ when Right v then true
58
+ end case) = (first matching case of input :
59
+ when UnvalidatedOrder record{ id = id , quantity = quantity} then
52
60
  prelude.length id > 0 && quantity >= 1 && quantity <= 1000
53
- end)
54
- end
55
- end
61
+ end case) end for all
62
+ end definition
63
+ example "|the largest valid quantity is accepted| :
64
+ input = UnvalidatedOrder record{ id = "A-4" , quantity = 1000}
65
+ expect prelude.isRight (validateOrder input) = true
66
+ end example
67
+ example "|a quantity above the declared range is rejected| :
68
+ input = UnvalidatedOrder record{ id = "A-5" , quantity = 1001}
69
+ expect prelude.isRight (validateOrder input) = false
70
+ end example
71
+ example "|zero is not a unit quantity| :
72
+ input = UnvalidatedOrder record{ id = "A-6" , quantity = 0}
73
+ expect prelude.isRight (validateOrder input) = false
74
+ end example
75
+ end law
56
76
 
57
- law `quantities are always in range` is
58
- definition is
59
- `for all` (q :: UnitQuantity) .
60
- valueOfUnitQuantity q >= 1 && valueOfUnitQuantity q <= 1000
61
- end
62
- example `largest quantity` is
77
+ law "|quantities are always in range| is
78
+ definition :
79
+ for all (q :: UnitQuantity) =>
80
+ valueOfUnitQuantity q >= 1 && valueOfUnitQuantity q <= 1000 end for all
81
+ end definition
82
+ example "|largest quantity| :
63
83
  q = UnitQuantity 1000
64
84
  expect valueOfUnitQuantity q = 1000
65
- end
66
- end
85
+ end example
86
+ end law
67
87
 
68
- law `a non-empty list has a first element` is
69
- definition is
70
- `for all` (xs :: NonEmptyList Int32) .
71
- (match valueOfNonEmptyList xs with
72
- | Nil -> false
73
- | Cons head tail -> firstLine xs == head
74
- end) = true
75
- end
76
- end
88
+ law "|a non-empty list has a first element| is
89
+ definition :
90
+ for all (xs :: NonEmptyList Int32) =>
91
+ (first matching case of valueOfNonEmptyList xs :
92
+ when Nil then false
93
+ when Cons head tail then firstLine xs = head
94
+ end case) = true end for all
95
+ end definition
96
+ end law
97
+ end unit
@@ -7,57 +7,58 @@ unit example.durations
7
7
  -- fail, as division by zero does.
8
8
 
9
9
  -- A checked definition: the totality audit proves the result in range.
10
- definition timeoutFor (retries :: Int32 where retries >= 0 && retries <= 5) :: Duration is
10
+ function timeoutFor (retries :: Int32 where retries >= 0 && retries <= 5) -> Duration is
11
11
  2s + 500ms * retries
12
- end
12
+ end function
13
13
 
14
14
  -- An adapter: the time left of a budget, never negative.
15
15
  remaining :: Duration -> Duration -> Duration
16
16
 
17
- law `units relate` is
18
- definition is
19
- `for all` (b :: Bool) . (1us * 1000 == 1ms && 1000ms == 1s && 60s == 1min && 60min == 1h && 24h == 1d) = true
20
- end
21
- end
17
+ law "|units relate| is
18
+ definition :
19
+ for all (b :: Bool) => (1us * 1000 = 1ms && 1000ms = 1s && 60s = 1min && 60min = 1h && 24h = 1d) = true end for all
20
+ end definition
21
+ end law
22
22
 
23
- law `subtraction undoes addition` is
24
- definition is
25
- `for all` (n :: Int32 where n >= 0) (m :: Int32 where m >= 0) .
23
+ law "|subtraction undoes addition| is
24
+ definition :
25
+ for all (n :: Int32 where n >= 0) (m :: Int32 where m >= 0) =>
26
26
  prelude.milliseconds (prelude.Integer n) + prelude.milliseconds (prelude.Integer m) - prelude.milliseconds (prelude.Integer m) =
27
- prelude.milliseconds (prelude.Integer n)
28
- end
29
- end
30
-
31
- law `timeouts grow by half a second` is
32
- definition is
33
- `for all` (r :: Int32 where r >= 0 && r <= 4) . timeoutFor (r + 1) - timeoutFor r = 500ms
34
- end
35
- example `no retries` is
27
+ prelude.milliseconds (prelude.Integer n) end for all
28
+ end definition
29
+ end law
30
+
31
+ law "|timeouts grow by half a second| is
32
+ definition :
33
+ for all (r :: Int32 where r >= 0 && r <= 4) => timeoutFor (r + 1) - timeoutFor r = 500ms end for all
34
+ end definition
35
+ example "|no retries| :
36
36
  r = 0
37
37
  expect prelude.toMicroseconds (timeoutFor r) = 2000000
38
- end
39
- end
40
-
41
- law `spending everything leaves nothing` is
42
- definition is
43
- `for all` (d :: Duration) . remaining d d = 0us and remaining d 0us = d
44
- end
45
- end
46
-
47
- law `what remains of a budget` is
48
- definition is
49
- `for all` (budget :: Duration) (spent :: Duration) .
38
+ end example
39
+ end law
40
+
41
+ law "|spending everything leaves nothing| is
42
+ definition :
43
+ for all (d :: Duration) => remaining d d = 0us and remaining d 0us = d end for all
44
+ end definition
45
+ end law
46
+
47
+ law "|what remains of a budget| is
48
+ definition :
49
+ for all (budget :: Duration) (spent :: Duration) =>
50
50
  prelude.toMicroseconds (remaining budget spent) =
51
- prelude.select (spent <= budget) (prelude.toMicroseconds budget - prelude.toMicroseconds spent) 0
52
- end
53
- example `part of a second` is
51
+ prelude.select (spent <= budget) (prelude.toMicroseconds budget - prelude.toMicroseconds spent) 0 end for all
52
+ end definition
53
+ example "|part of a second| :
54
54
  budget = 1s
55
55
  spent = 250ms
56
56
  expect remaining budget spent = 750ms
57
- end
58
- example `an overrun leaves nothing` is
57
+ end example
58
+ example "|an overrun leaves nothing| :
59
59
  budget = 1s
60
60
  spent = 2s
61
61
  expect remaining budget spent = 0us
62
- end
63
- end
62
+ end example
63
+ end law
64
+ end unit