lawspec 0.19.0 → 0.20.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 CHANGED
@@ -1,5 +1,70 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 0.20.0
6
+
7
+ - An `all` group with an asynchronous step runs its steps at the same time,
8
+ on each target's own concurrency, so it takes as long as its slowest step.
9
+ Results and accumulated errors keep the order of declaration, and every
10
+ step finishes before the group fails. Groups of synchronous steps still run
11
+ in turn.
12
+ - A channel end that already talks across the network now moves when it is
13
+ sent to another node, instead of being relayed. The old node hands the
14
+ end's state over (sequence numbers, unacknowledged values, values received
15
+ but not yet used), forwards anything still in flight, and the peer is told
16
+ the new address, so the old node can stop once the receive returns. Ends
17
+ can move on again, and a peer that does not answer the move is still
18
+ reached through the old node. Local ends are relayed as before. New frames:
19
+ `take`, `state`, `moved` and `moved-ack`.
20
+ - A node's channel ends stop resending once the node closes (Python, Go,
21
+ Haskell).
22
+ - `lawspec.json` can bind an `async` adapter to native code returning the
23
+ target's task: a coroutine, `Promise`, `CompletableFuture`, `suspend fun`,
24
+ `LawSpecTask`, Rust future or `IO` action. The bridge stays asynchronous
25
+ and converts the result once the task completes.
26
+ - A Rust unit with native bindings keeps its generated remote, session, actor
27
+ and mailbox code.
28
+ - A match may leave out constructors that the value's index rules out: taking
29
+ the head of a `Vec (n + 1) a` needs no `VNil` branch. The compiler proves
30
+ each one impossible, and names a constructor the index allows.
31
+ - `SizedStack n a` and `SizedQueue n a` are stacks and queues indexed by their
32
+ size: `prelude.sizedPop`, `sizedTop`, `sizedDequeue` and `sizedFront` take a
33
+ non-empty one by type.
34
+ - A function may take several flow parameters (`A / A'`); a call passes a
35
+ state to each (`pushBoth x ~a ~b`), and a definition may update each.
36
+ - Flow calls may sit in the branches of an `if` or a `match`. A state the
37
+ branches leave at different types cannot be used afterwards, and the error
38
+ names each branch's type.
39
+ - `if c then a else b` in laws and checked definitions. Only the selected
40
+ branch is evaluated, and the totality audit checks each branch knowing which
41
+ way the condition went. `prelude.select` now means the same.
42
+ - The totality audit bounds products: `x * x` for an `Int16` `x` fits `Int64`,
43
+ and factors with known bounds give their product's bounds.
44
+ - Scenarios may close cycles between processes: LawSpec accepts channels that
45
+ form a cycle when no process can wait for another in a cycle, and names the
46
+ waits when one could. Scenarios with mailboxes or `or else` keep the tree
47
+ rule.
48
+ - A unit can re-export names it imports with an `export` line after its
49
+ imports (`export Band, rates.rateOf`), so a package can offer one facade
50
+ unit. Re-exported names are the original declarations, not copies.
51
+ - A build can hold several versions of one package. Each unit sees the version
52
+ its own package's range selects (the highest supplied version the range
53
+ accepts), and each version's units are compiled under names with the
54
+ version after the package name (`shop.tax.v2x0x0.api`), so their types and
55
+ native names stay apart. A mismatch between two versions' types names both
56
+ versions. A package supplied in one version is unchanged.
57
+
58
+ ## 0.19.1
59
+
60
+ - A handle's Kotlin type binding can give the native class's type
61
+ `arguments` (`["kotlin.Int"]`), so generated Kotlin names the handle's type
62
+ in full instead of `kotlin.Any`.
63
+ - A Haskell method binding on a handle with no type binding names the handle
64
+ and the `lawspec.json` entry to add.
65
+ - The sessions example's adapters are asynchronous, so the JavaScript and
66
+ TypeScript ones await each receive instead of using `receiveNow`.
67
+
3
68
  ## 0.19.0
4
69
 
5
70
  ### Stateful models
package/README.md CHANGED
@@ -30,7 +30,7 @@ Node 22+ and the selected target's build tools are required. No Haskell
30
30
  toolchain is needed. The reference platforms are macOS and Linux.
31
31
 
32
32
  ```sh
33
- npm install --save-dev lawspec@0.19.0
33
+ npm install --save-dev lawspec@0.20.0
34
34
  npx lawspec --version
35
35
  ```
36
36
 
@@ -40,8 +40,8 @@ LawSpec can create `package.json` and its test script:
40
40
  ```sh
41
41
  mkdir lawspec-example
42
42
  cd lawspec-example
43
- npm exec --package=lawspec@0.19.0 -- lawspec init --target javascript
44
- npm install --save-dev lawspec@0.19.0
43
+ npm exec --package=lawspec@0.20.0 -- lawspec init --target javascript
44
+ npm install --save-dev lawspec@0.20.0
45
45
  npx lawspec check
46
46
  npx lawspec explain 'example.atoi_codec::itoa and then atoi yields a'
47
47
  npx lawspec doctor
package/bin/lawspec.mjs CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  atomicWrite,
18
18
  safePath,
19
19
  } from "../files.mjs";
20
- const VERSION = "0.19.0";
20
+ const VERSION = "0.20.0";
21
21
  const args = process.argv.slice(2);
22
22
  const verb = args.shift();
23
23
  const options = {};
@@ -137,7 +137,10 @@ async function packageCommand() {
137
137
  machineBits: options.machineBits ?? 64,
138
138
  }),
139
139
  );
140
- const units = result.units.map((u) => u.id).filter((u) => u !== "prelude");
140
+ // A package owns the units in its namespace; its dependencies' units are not its own.
141
+ const units = result.units
142
+ .map((u) => u.id)
143
+ .filter((u) => u === own.name || u.startsWith(own.name + "."));
141
144
  const laws = result.laws.filter((l) => units.includes(l.owner));
142
145
  const summary = {
143
146
  name: own.name,
package/build.json CHANGED
@@ -176,8 +176,8 @@
176
176
  ],
177
177
  "digests": {
178
178
  "dev/Gen/Embed.hs": "98a186594c3c38a65aad1203d5730ce352b309f92e1990ccc508e7a5e00f8f35",
179
- "lawspec.cabal": "1b3f05b00e4c5a0bedeace6fc5a2d614242aaa36468c500cb608fc041cb4e37d",
180
- "package.yaml": "70bee72ba3361996bb3cd1952126341f30db02874ba189f300bdef63121601de",
179
+ "lawspec.cabal": "b06153b350df4ea9524268ac4fb1ba5117d1a75c61db821ab31a4983148a26e3",
180
+ "package.yaml": "4e26f42e1e761ab66e01604320f8b8ed7e9a50287354d22368c65a87c13e8e81",
181
181
  "runtime/LawSpecCodecs.hs": "1b3f6b40ad49928cf5e9386e06bc2992c9f1271754351b9fa3075e50346ef03b",
182
182
  "runtime/LawSpecCollectionCodecs.hs": "74caa786801c5142ed040897c7ebb7373abf49ee49e02af53e466646fb624f47",
183
183
  "runtime/LawSpecDataStrategies.hs": "9cc5b98476364a6c255dc3eb40c53d65b4a9d4ab0c3961a806b3515a8d5e8f7f",
@@ -185,8 +185,8 @@
185
185
  "runtime/LawSpecKotlin.kt": "0cf3b7de0406155225ccca33ee3dfdf8f0456c47d577f6be8f1265c13df838cb",
186
186
  "runtime/LawSpecKotlinCodecs.kt": "811accd1cac055d46f7ae0a2aff03602389fbbaaa2eaf778a9dcdd6899b12466",
187
187
  "runtime/LawSpecKotlinStrategies.kt": "8ee1edeec1c342f2bc70ca8bdad22ec5aabc38f6f61381fe905b717ffce0688e",
188
- "runtime/LawSpecRuntime.hs": "671895d4746c491f640fb3076a65f49386a6e8615b507f277d813fe1a66bc76a",
189
- "runtime/LawSpecRuntime.java": "298f696cc3df5694a003e46fc9070748d00faa91e46dcc59d9e0f195fcd82e92",
188
+ "runtime/LawSpecRuntime.hs": "8c34e7580d7de9a15078ca1ee087e254bb93c73c55fdb346e99e1b860a2859d8",
189
+ "runtime/LawSpecRuntime.java": "9f71e9ed0068fc7253701271d2fb199c0c4290c38e1eb70fcc8a1fbb951645f3",
190
190
  "runtime/LawSpecSchema.hs": "1000ee60eb6910a9fd4fdced5940014eb1a0720afecd4e2b571f185aec6de5de",
191
191
  "runtime/LawSpecSchema.java": "78b715e9ad3f20603c6a05c6f06a3736664a1821d9a6f4d73f3ff1dfed74473a",
192
192
  "runtime/LawSpecStrategies.kt": "569f7775c0ac44765d05567cbf62d026558ac193c080ca71681ec6ee49c21794",
@@ -195,16 +195,16 @@
195
195
  "runtime/lawspec_data_strategies.go": "65ca2a09012c516c17bb66d7381637e71f454740858f648a78b9e536f1c7c600",
196
196
  "runtime/lawspec_data_strategies.mjs": "5fe9327a6dda2e759558b77100aec96798f1aed4f517d4bc91f45a543b8d14b9",
197
197
  "runtime/lawspec_data_strategies.py": "0d06f0c5b9cdd5f6659f424a328884b670c94b1572ec0fa5d5408a05110d94dd",
198
- "runtime/lawspec_runtime.go": "25b342e07996db86c4b997aa2a7f48aefc39d6ebff6cfad58095f4756040ed61",
199
- "runtime/lawspec_runtime.mjs": "755b90f13085b409302df1cb3b396dd6917fbdbaab66c9903a29f3981e5e936b",
200
- "runtime/lawspec_runtime.py": "0949983cf2594cb2e9eef812f570a775a56ab50c598c4872a0bbad427b0372d3",
201
- "runtime/lawspec_runtime.rs": "3221a2de8ed83fb5586ec1b0dd8dbdf4954ea5f71a0f5f23930fb8da4cb36581",
198
+ "runtime/lawspec_runtime.go": "164c5545bf5f504b154bc53ba7e928dd4660d198d7b426e6bcdd89f64b05b02e",
199
+ "runtime/lawspec_runtime.mjs": "6385d76b1354d895e0726c3636a2e9c3cbb82e1c344633d373fc57931827a998",
200
+ "runtime/lawspec_runtime.py": "a41403fa4c1a93f1bf203bb2cffce4e6474add98a0cb300e1e94d35b7387fe0c",
201
+ "runtime/lawspec_runtime.rs": "fe06f79e47d8ec2a12be4dc5c41828533907e973b2a800314aa797c8f74054ef",
202
202
  "runtime/lawspec_schema.go": "83c7ebf07c386fdfcf55562f4b1d6947ecb1d6a022f50aa0d49b4bce0eead746",
203
203
  "runtime/lawspec_schema.mjs": "89b3b76ffd0ddd70c4bd49b73ca08a359d70aa3994745746978ed615676fde26",
204
204
  "runtime/lawspec_schema.py": "4c8ea9895f2f93ff5d34c4df414305bc0c2a151edd4e192ebc8982b35fa7782d",
205
205
  "runtime/lawspec_strategies.rs": "6c21050184ac20b2ad38e99f47b78fb013f1916389e85e522dd73209133af990",
206
- "runtime/rust/Cargo.lock": "1625b198406975e7f4c8edcf2f041236492d0089521342d3c772ffcd241c7504",
207
- "runtime/rust/Cargo.toml": "7f7a0af0c06a4dc1d02cf0dc2369f82f01859610a84a8e0ea8795a287fee740c",
206
+ "runtime/rust/Cargo.lock": "71b9c6cee8e6192faa42d9383d311fe866fcd0d2730056a3ea8bb77f11cb4fb8",
207
+ "runtime/rust/Cargo.toml": "9c33b43458ac5ad54481af7453a8977be5acd9ed824397d7909cfc7cc9c2226d",
208
208
  "src/LawSpec/Actors.hs": "98677022a6d596bbdbb32c69a23bdc0ade9dd18bb60067bdfb2c280fc0c54089",
209
209
  "src/LawSpec/Actors/Go.hs": "81f732637abd28e5d7ba1ba94dd0a8bf88722accf9c2583453f7dae176460429",
210
210
  "src/LawSpec/Actors/Haskell.hs": "7fcc71ca1f7eb2e57aba631f0cf9334a1dd6ab644211126fa831535bbfce90a8",
@@ -213,80 +213,80 @@
213
213
  "src/LawSpec/Actors/Rust.hs": "e36b8e3fd7add15d12b7e92b71ef98d038e9d78343c89b58fcbbf6c57d6cada7",
214
214
  "src/LawSpec/Actors/Types.hs": "6831a6aafa5486f2e8d1d454e6448a7908235f80fc00c91239f91258fc22952a",
215
215
  "src/LawSpec/Actors/Web.hs": "6660ddc6ac535e926c222dd413934474a775c98ce18b4f709b30555a5e00aed8",
216
- "src/LawSpec/Api.hs": "c0cb09ea2754f79138697e6ee6b4817a43d8343cb410380389d6b321c2feb07b",
217
- "src/LawSpec/Backend.hs": "709581d869bbc3c3103d72b8d4b4d506b96eceefee03add45ca36acd5cedf41c",
216
+ "src/LawSpec/Api.hs": "162f0b9d26e06d3492bb39541310f10bd9814eb79a89e1bd3c5156003dac5bbc",
217
+ "src/LawSpec/Backend.hs": "6508dede12ed070ace7c505f006d436c2b200c5f4686b041c813cbcfb407ee86",
218
218
  "src/LawSpec/Bounds.hs": "00c4467bbd1d96cd31a1ac43b42226079126e70158bb87f365d6b9ea2757ff54",
219
219
  "src/LawSpec/Capabilities.hs": "ab457f3da440a237ee731d664b94d95a0cc1fa4d8be4d4d0403a61ebcf98e310",
220
220
  "src/LawSpec/Code/Doc.hs": "9e3b70f85deb1dcbce385af1d0cd4bea2dfa8a2d806d54745d4bb437406673e5",
221
221
  "src/LawSpec/Code/JavaScript.hs": "77bf27dcc210216e4739f68c4709f556f80130ab83b3b9387ac4a2421e790910",
222
- "src/LawSpec/Collections.hs": "504af1d31c267287456fde20d2782c72c519abf4ce26b083e59a7aefa876a768",
222
+ "src/LawSpec/Collections.hs": "9141429df6d0150c6b1a594901b1f4277ca8c34638501a88c880994d7769e7fd",
223
223
  "src/LawSpec/Common.hs": "107612a8aaa787488413acf9c1a56622004d3bff251db89b99928343e6070883",
224
224
  "src/LawSpec/Compile.hs": "efca518b2f0a7dff48927dedc3d6752e10228520d1cae4567aabc2bfac3d94a1",
225
- "src/LawSpec/Core.hs": "755018ff6eb70ff2adf6e75208c930ef04ba698b4e7f4ad10da3278f61c6f0df",
225
+ "src/LawSpec/Core.hs": "be52d8fd7f2b33641479f6b363c7a22ae3d6bd9ce46264ace998564180fec3e3",
226
226
  "src/LawSpec/Core/DefinitionContracts.hs": "b7f60f038b231187ecf898e585ae1a8fb1fc113bb55bad6d1bb2660350fd969e",
227
227
  "src/LawSpec/Core/Definitions.hs": "a57e30f6864a6bae7e60cd08ef968b1adc9bbd1c86d4b20c405276eccd604f8d",
228
- "src/LawSpec/Core/Eval.hs": "7c55598054f76e5f3c332a53df46bc2090a4914e8e1460671896f50db0102a9d",
229
- "src/LawSpec/Core/Evidence.hs": "e8870096ca2e3fe46325ceff13cbc93fd6d0b46c9aa9c56300e9269460c3d773",
230
- "src/LawSpec/Core/Expression.hs": "850ff201b56553021404ed783e037f9a27a7d70658c62f5e22e89868bb06044a",
228
+ "src/LawSpec/Core/Eval.hs": "a9965e3dce64eb080c5cf356171113c72fc273d8d1d58b91a3c674cae430d3b1",
229
+ "src/LawSpec/Core/Evidence.hs": "0784dcb0796947209bdbe7bb867bde7eab66664eff6ca171c6682adcea980437",
230
+ "src/LawSpec/Core/Expression.hs": "146714aeefc7086c7a58e5825786655af96cd2076b38151437ea9530fa3d0fdc",
231
231
  "src/LawSpec/Core/Machine.hs": "7ba46cdc4934af3ffd52f3766e56091a2d8e04a9301dde16be7ebeb3260fbd79",
232
232
  "src/LawSpec/Core/Payload.hs": "da2417fc99354338eab49a688c5f36cecde5ec1aacd8582c895428568b10a376",
233
233
  "src/LawSpec/Core/PayloadPlan.hs": "f2a7d2dc58c6a0f79707bdc24773bd3aad3a3b8eea2735a8284b2a9f3a4af4a8",
234
234
  "src/LawSpec/Core/Policy.hs": "c0fdb7babe904bafa0fe97c2089f63ae393c3e8845a6d3110e12d8531e0656f0",
235
- "src/LawSpec/Core/Program.hs": "36a4ed09b61e8fa2b8e69556105f7276a20e8384868cdd26e11714020c6e930c",
235
+ "src/LawSpec/Core/Program.hs": "408d0d6e24566e3b79c8cabd193c441e67353c750284668582ac3e8314f0ede7",
236
236
  "src/LawSpec/Core/RefinementProof.hs": "c19fc03e68488357a59897ec38ce3d2efd320c35b405b632af17425d6a18447a",
237
237
  "src/LawSpec/Core/Schema.hs": "ce06bd96b63d11f80be518e626b33526668ae1e2f3f7fc626bb1048e296efc21",
238
238
  "src/LawSpec/Core/Semantics.hs": "cdb8256e523f7808fa50fe7d80d709217a28de4c81c5ff5be8382f94900f3779",
239
239
  "src/LawSpec/Core/Stages.hs": "b88b974e3510ca797bd4ad8a22c47d63cce28245fc4775999d666e8f2d8dac56",
240
- "src/LawSpec/Core/Total.hs": "d706a145c3663b6bd3f0ecf390fee1fe4847564ec4f9ce70fa7583ead04a933a",
241
- "src/LawSpec/Core/Totality.hs": "a9460bc11a91be583274bf4e87bbc85630a544736c4d532a61cf9038f1a3d42d",
242
- "src/LawSpec/Core/Types.hs": "a684e003ed64924cb54717f0e4b166fea62a2ac0fe5c9f8851a865f4dcb9858e",
240
+ "src/LawSpec/Core/Total.hs": "4d22dfe80ed26f90ec6ca39c49ad848d9efeac3abf2a0312a31bafb186e6058b",
241
+ "src/LawSpec/Core/Totality.hs": "110728fcc0b7aa808209479550e4a6bd042a3ae89d36c878ede62914918d7ae6",
242
+ "src/LawSpec/Core/Types.hs": "e83b3058dc58ec74979c3a82a19e3f1e9daabfc8d1a417eba3ac87e327578c56",
243
243
  "src/LawSpec/Core/Validate.hs": "74c2a51eb913f8414268064f22d2d5d97ebfb0e4797e146b229076c29ac38726",
244
244
  "src/LawSpec/Core/Value.hs": "52fedabbc07c8c65acc5be1efc7b4860bee47b58931ef76d26fcbfc8a280bf41",
245
- "src/LawSpec/CoreEmit.hs": "d27b3119ca11809a8a4ff70826e4b5a4853543a159e8078260614795946e87ed",
246
- "src/LawSpec/CoreNativeScalarEmit.hs": "5182e898f247376d4846336e0aecd22685dd2f6d9a41897afb67b0b4e732b82e",
245
+ "src/LawSpec/CoreEmit.hs": "3ee94e83ebe3162a8ea0e432048509ad2ea5dd57a4ee9512985d43128e628d53",
246
+ "src/LawSpec/CoreNativeScalarEmit.hs": "0066b0e525c69414655c079b6286421a05aa4e69488db715ef42c0e36566f066",
247
247
  "src/LawSpec/CorePersist.hs": "d28fd82240b9926201cf3befe45e2190c57bbed899e3f7d861220aa9580ddaa5",
248
248
  "src/LawSpec/CoreScalarEmit.hs": "163669ab934a1736976437394f3f4528ca7ae85dc14facebef6ec2fa576b92f0",
249
- "src/LawSpec/Data.hs": "a7f2f6e27027452ce9f5a9cd87e102f39b4e5adba23e4a5f085e1ea186912c27",
249
+ "src/LawSpec/Data.hs": "99fe2a88d2206909c1ee63d05d224111449a5a8c15727cada961ec498a8425db",
250
250
  "src/LawSpec/DataNames.hs": "2eeb0d215131981a2271725a50c21dce44c7146a167025eb239a83922fdecaf6",
251
- "src/LawSpec/DefinitionTotality.hs": "af3aa9f7495344ea34c90cf87664f3ec2d9f95474ef273905fc6c9b17edd5d80",
252
- "src/LawSpec/Dependencies.hs": "b748d2231f543a878e2ff3816f8a027285c610555821856383e8d1853e4c7151",
251
+ "src/LawSpec/DefinitionTotality.hs": "02dc2b7121880474ad0313f81bd504ad26ddb5ede1afde4f49198ffbe9908a71",
252
+ "src/LawSpec/Dependencies.hs": "e2ff77d88fadd9f8bc3fff7c5a56c9feabfc25777d5fa6a7dd84f912dfff2d32",
253
253
  "src/LawSpec/Digest.hs": "ba8128e36856d5fb0d2345779fd949b11042af688a0d8cee63e5ae8818cef7ca",
254
- "src/LawSpec/Discharge.hs": "5369d37d511f5d7422bb03dab4b128430b1a3a3d561814fe7904729e02501afa",
254
+ "src/LawSpec/Discharge.hs": "513ea5462120267aa8c7b9b4491c76e8194ce33f94b62092ea213f8bf1bc9289",
255
255
  "src/LawSpec/Domain.hs": "222d15f0012ae630802238a6d7e1ee78d1e718b599f5ebb5a1ddc4e8d29d68c3",
256
- "src/LawSpec/DomainModel.hs": "b2ac0eb9b63fae2860d9f53e6770d8fdf053d9df33773071b31de53cdf4e1562",
257
- "src/LawSpec/Elaboration.hs": "b69b739a61fb431432424fc31815462c8e64737df66e8a59610f15bd9c98a30c",
256
+ "src/LawSpec/DomainModel.hs": "00f25a84c9577b8e91798e63d625da2efd2426b87c79aef2dd2a715496cf1807",
257
+ "src/LawSpec/Elaboration.hs": "65e136339bafe325b0a2f4b81375f8438191e7bb4bf937a09a89e8f5413a82c6",
258
258
  "src/LawSpec/Emit.hs": "9f34f5765915a2a12a66a6dca647ddaef9289372956802c6d99cf0cfec447c7a",
259
259
  "src/LawSpec/Eval.hs": "b87a786ed7a512c60e00a037a1a36738933518aafa255babaa8b1b42dbb8ff6d",
260
- "src/LawSpec/Flow.hs": "830b9d59b94f26a05687bd5baed06b4ecbf1f47c6a634766810d3dd2a44647cd",
260
+ "src/LawSpec/Flow.hs": "2f8c4dd40ff56dbb2f0e05b25ed7d83838027eb788008917f6d191744bc11873",
261
261
  "src/LawSpec/Frontend.hs": "85d631cb6246efcb14814177d1620ffd5f67964de725a8af241a11f1f30f5da3",
262
262
  "src/LawSpec/GoData.hs": "7532c2fbcce57a75013874e383225ad42b2a7d39b7f3420d56076d733e3d95cf",
263
263
  "src/LawSpec/GoDefinitions.hs": "13ff50b7fec465b0750b57a09081e5cd7949e49105fa74da76836b3fcd014ae8",
264
- "src/LawSpec/GoExpr.hs": "67ef004e97074976e0fd137dfef8d417efe8de3f7d5c3c08293874d30d89e9d0",
265
- "src/LawSpec/GoNativeBinding.hs": "14825118889abfa737abed9c22c1e5a5e29b9f7433a35ca80fcbe00f1fbe632d",
264
+ "src/LawSpec/GoExpr.hs": "3b4283fa98dceedaaceb75bc1444495bd3539b2c21f45f39456ce4ae29776cad",
265
+ "src/LawSpec/GoNativeBinding.hs": "08eb8f6dfb56a5f5deacdf7749deefe8b74ca3c2499f207458df8a2f8eab7fac",
266
266
  "src/LawSpec/GoProperties.hs": "ef0cc192eb49c928c96bd9842618c5d59ff0b6442ed4f14423e061a9cf848888",
267
267
  "src/LawSpec/GoTestHelpers.hs": "76241cf037208f5caac5e905acf4e05acfc26917adc74f11f92aca60aa1c352e",
268
268
  "src/LawSpec/GoTypeRefs.hs": "7f239f5ac3ac8bd21c8f76c328049f7715d8562ee1382befa0a58abd4f15f726",
269
269
  "src/LawSpec/HaskellData.hs": "6366fad5cec25eeffee4ddcfe8a01672d2b1ac9c96144088ccf80061ef690fb1",
270
270
  "src/LawSpec/HaskellDefinitions.hs": "9e99c5ef7110e286b92acd08efd8890340b9c2d242053568804648789907479b",
271
- "src/LawSpec/HaskellExpr.hs": "f7ef064ac6700c027de4bd71bddeb3236853232cf7a39bed61de16153539b401",
272
- "src/LawSpec/HaskellNativeBinding.hs": "b42a716c0c1bd744e2b051f2711ea4800f618d8642835ea2868705e48ef2f42c",
271
+ "src/LawSpec/HaskellExpr.hs": "25b71df11bf8a3b4b3c3033ca603f8006554e88b990bb9c9b4e5ab9285f422c8",
272
+ "src/LawSpec/HaskellNativeBinding.hs": "00ead409eeb5e916b21a522162f4072d18c7280922d8537ae865a6cb3fe67fba",
273
273
  "src/LawSpec/HaskellProperties.hs": "24f0fc966e3c1f59761010ea1860bb4fffc2fd4fe57f2e3159371b021881a2f1",
274
274
  "src/LawSpec/HaskellTestHelpers.hs": "a0d3bef096b9a8bddfbb213e554e00535a3a7691c4ef95cb6c61a4eb6cea5098",
275
275
  "src/LawSpec/HaskellTypeRefs.hs": "2225b2a5e2ab3662e7202d23b24f4d6db48353b35ae28df8acd2b92fd2b97574",
276
- "src/LawSpec/Imports.hs": "0f81acb1e85d23b0c5745aa8530b0b979d739f201fc1d3d8f2d901c16c820b4a",
276
+ "src/LawSpec/Imports.hs": "47e6ec1d3c7ed2b8d6aaa7a99032524113bff4a301f93bf0bb3f4d20ab27d538",
277
277
  "src/LawSpec/IndexTerm.hs": "1c694f279b934e7b853c0028158c2754048928deb45fb7d65abc1d98da382bcb",
278
- "src/LawSpec/Indexed.hs": "1e7ed53653cabc097f75dcf350c81facf9feb30af73f3e21f9344665fc316387",
279
- "src/LawSpec/Inference.hs": "40693bcf11935f812bac171e981476acd978a16d126855c9ddf385a8b1cc23c3",
280
- "src/LawSpec/JavaData.hs": "92a8f51ad656c9684c55ed999ce97bc476038cfac404bca20eaf6b0ada0790e2",
278
+ "src/LawSpec/Indexed.hs": "850b1b409b3a74d72700792b33daf96bf0b4bf4062002da76fce109f7ede1aa5",
279
+ "src/LawSpec/Inference.hs": "91fa7551d9de424fdc7478ab37da1f842a38978005083831e6a8eaa5ab8b5c87",
280
+ "src/LawSpec/JavaData.hs": "6173a61ffd95e1f671a0df1f85c056a1f785f6fa66c4d55d09d2420400cfcb94",
281
281
  "src/LawSpec/JavaDefinitions.hs": "587b82efbe07823defdd2143469b4632bd86b21f0d9644a4929cf58d1d0a2342",
282
- "src/LawSpec/JavaExpr.hs": "fb1d3e64f3288e557720dead7738eb4f2a59d4563e5be4a742e1582829f19d3e",
283
- "src/LawSpec/JavaNativeBinding.hs": "2c2bb31c121f54ba1b43b201163398ac562a3b99e7b9190ecab1c43ac1a2abd0",
282
+ "src/LawSpec/JavaExpr.hs": "f38f90c5a3cbfa537d7f5b79310b8d517a2d65d8d8cff5d2d6f62eedfea59ff5",
283
+ "src/LawSpec/JavaNativeBinding.hs": "45b85c16891fb6127ff9a9fee85e1f8a6a00fa48bcdf2093e358bfa46b905985",
284
284
  "src/LawSpec/JavaProperties.hs": "b57a30301ac295dfbd6d4d7ff0d94f2c788fc892c184fb7661b338aad6d89f7e",
285
285
  "src/LawSpec/JavaTestHelpers.hs": "3eab1c7f55ddbf34c4ab53e4718d347f5fd9df22900dc4d34808b31590f4cac4",
286
- "src/LawSpec/KotlinData.hs": "40ed6f62a6c55c69546f75f2c26a31bae51837e7064364d6bcac5cbe653bcee2",
286
+ "src/LawSpec/KotlinData.hs": "ccbef310915bd4c998bb9566c0e741be1275109ea536947a9844794eaeecaba0",
287
287
  "src/LawSpec/KotlinDefinitions.hs": "4d49a62a1f8ea31a31dc79a6f4aba318f2f71552c495a67499f3cec6dc17fa60",
288
- "src/LawSpec/KotlinExpr.hs": "20312f0774f1d0832a21a19b93c8103e2791ecd32a827d8e9c4f2b4830a996a0",
289
- "src/LawSpec/KotlinNativeBinding.hs": "12a4f40de319b87a6f5a2e48ea2616010d620d00e2e3b67de063947e958f7da8",
288
+ "src/LawSpec/KotlinExpr.hs": "456ca80544de1c544fa661e450ad19353b4485cab96258cfc83b7e698937101e",
289
+ "src/LawSpec/KotlinNativeBinding.hs": "5928b20e40d5e7ebab119e37defc491455417ae6b1fea4311fa5f94f9f46baa4",
290
290
  "src/LawSpec/KotlinProperties.hs": "51b62307275e635f9d064b370df40e5bda6ec9251d78716e1b27110d8d1951f9",
291
291
  "src/LawSpec/KotlinTestHelpers.hs": "6fc4fb258899f358156f1ad04a7709c2a2807f9dab54c1fc983cce9305ef6957",
292
292
  "src/LawSpec/MachineSpec.hs": "3f687e2d0a60f9c5527f506661ec4e291d53fb061abbe10ced5db000ba52b7bb",
@@ -294,62 +294,62 @@
294
294
  "src/LawSpec/Memo.hs": "1230a08b003cc6eee0db951b55a93f9ec573e5b6752c63d65d6c3487927b0b4e",
295
295
  "src/LawSpec/Model.hs": "c645aad0f37f175a099865f467864391cc0cb8e76e4f6b3e1297d7ac6c31260d",
296
296
  "src/LawSpec/ModelTests.hs": "a5905c0c4a493129c19cc135fb606dacd12fc72d495df471d63e7d3cacdfe925",
297
- "src/LawSpec/NativeBinding.hs": "3f43c2e636c2ffe50ed58f732e4c40027154d77ce9938c503a5db3365e49f37c",
298
- "src/LawSpec/NativeRequest.hs": "1ab2b94f97fad341df78922ad06d4d90042ff87d5e94d85edb467b020acb3795",
299
- "src/LawSpec/Packages.hs": "161fc68a9959a80762ca4ece405240351e3180ea4dbb2bf148eaca6562fb7c30",
300
- "src/LawSpec/Parser.hs": "a687fb2d2a12d37a7fad97eb92375c7b425fa823cd85133e2f660f78a62da2c3",
297
+ "src/LawSpec/NativeBinding.hs": "a2fae69f02eaa21b61c61496587f46508cab142b07434ad952cb4c154d9e0d04",
298
+ "src/LawSpec/NativeRequest.hs": "9f77dfef419e22164841ce6aabbd0333e1a579f77c2d623fec916b0d29ff2c68",
299
+ "src/LawSpec/Packages.hs": "fd4bc9453bc86ad242083c0278221720460391c071c6226eee91da90e97bcddc",
300
+ "src/LawSpec/Parser.hs": "ae96a2defd2f3110cb80567eaef7f775d6b24bcecebafc52feac6e41ade20a9c",
301
301
  "src/LawSpec/Persist.hs": "f29c228ba12605f9ddd393f2535a306e4ff41aa38a2e256840ef547be54dacbe",
302
302
  "src/LawSpec/PortableGenerator.hs": "7dcf856ea56f57103da6cdfc39b63724ac6be2c2912acb791999c8a952679264",
303
303
  "src/LawSpec/PortableTestHelpers.hs": "8d98184c92a34b431f2a820cef3ea735b0cec3a52504f519b3bb06cb5174017c",
304
304
  "src/LawSpec/Prelude.hs": "515698dda42a8b950c8529b14b5f9d6fe25e590eb1a7a2593ccbcb2edf87ea57",
305
- "src/LawSpec/Public.hs": "7010357e250607a9f94d1ab8dc34fad4014fb7d9f15ba0d7c2fc94d0f48fcac4",
305
+ "src/LawSpec/Public.hs": "7d9c822b6da62b16e40c2416f06d4a9aca4c5fd9792cccf98674e79c7bb88423",
306
306
  "src/LawSpec/PythonData.hs": "ca8fe8b2410c83fb0e49a5f95a538d3601172cc6ed1ca6fdb2245c71df36acf6",
307
307
  "src/LawSpec/PythonDefinitions.hs": "90bd885196387cc9fdb61b6623b08afd2bbd3a052a8b4fa7c18a22a9db2472b9",
308
- "src/LawSpec/PythonExpr.hs": "23d7d24b5fb4efff9cb63d38c02a93d95744ec79b4565daf1412088fc7c4ba59",
309
- "src/LawSpec/PythonNativeBinding.hs": "106e2052d4023ae59628de310e26a6802de988a7732ff73a81d3df06fbe7b75a",
308
+ "src/LawSpec/PythonExpr.hs": "0f58687d340f89077aafb6de94d28228d7adb2db01e114e1d428d253aba279af",
309
+ "src/LawSpec/PythonNativeBinding.hs": "4f004f215703061f68249ab3eac46381aacfbbd44cc9ac6265f73671ef31064c",
310
310
  "src/LawSpec/PythonTypes.hs": "7193a0b8dad1661bb48189351e3dacdd938bf1ec40e3b716e2f7fb571bc6eb3a",
311
311
  "src/LawSpec/Railway.hs": "7b13256dc9601e921096e0a957da66baa47ae9be7153c194a3ed805473c15f61",
312
312
  "src/LawSpec/Refinement.hs": "f73b9d57a89a52934e0ae664c02984041faed09e8d478cb6416aafd25b5a2d94",
313
313
  "src/LawSpec/Remote.hs": "3142e9dab22afb807f91bf528efd347d1271085bb85fc66c0505f3270bbc05ab",
314
314
  "src/LawSpec/Resilience.hs": "97b4a498ee74b608120ca578c7b9c708d2025b77db23d83e5c4ad80d5ff8a465",
315
- "src/LawSpec/RuntimeSources.hs": "b56aa873658c36acf202fdd75fae885a93bd67981c6ee68741b28cf4efb3905a",
315
+ "src/LawSpec/RuntimeSources.hs": "60a7864e3c7f55787ad541bb94c24103986084418413d1b3ddbab59461fa64e0",
316
316
  "src/LawSpec/RustData.hs": "d4ac7ae37ebe55c3ca9c587c09895fa4ef0156a989412bf6f5f8bd56749fb4e7",
317
317
  "src/LawSpec/RustDefinitions.hs": "77c00183d9af6973ec77d387203a24ab3094dec9a7485e836b286fb90ea9733a",
318
318
  "src/LawSpec/RustEmit.hs": "4a786ffbd99cefcd3fd5c4f9e395132871c6a88a4c1bd8a40adce2e5d72d7d1d",
319
- "src/LawSpec/RustExpr.hs": "04b2ef81417b811c7b98a98acdadab4e588ca8757964a63ba8dc5936c36479e6",
320
- "src/LawSpec/RustNativeBinding.hs": "c7f098efece9ac5d7328c813c9afe31725d4a65e6745931f3cad20d27b9a235c",
319
+ "src/LawSpec/RustExpr.hs": "a44dcf2ae62b4d6ebeac6627cfa286b268873af14543f7d5f729be86cae74b18",
320
+ "src/LawSpec/RustNativeBinding.hs": "00ec9f71010b5fb5423e1725a4e1393d2a45aad62b73007ff2dc6e2422a6cf94",
321
321
  "src/LawSpec/RustNativeGenerators.hs": "a3b1484d9ff0008e4f961aa81d0aa51da57ec0cd7909124e80c98d56aacc8ce9",
322
322
  "src/LawSpec/Scaffold.hs": "bc68ab7e19f12aa4da850e79219a4d601d884a160ba143d15892a7792f8fc02b",
323
323
  "src/LawSpec/Scalar.hs": "8ff178cbce4aa514f4b770e65efd471461cc12812e854d95f48b0dd54f0cc637",
324
- "src/LawSpec/Scenario.hs": "143cf61314cc5e7e593512fbf27cb64ada62af6bdf05dfc5b3be6f8acf7c3f06",
324
+ "src/LawSpec/Scenario.hs": "679a4a50ebdee3bf6dbe3773b46f8979a9951d2f509828ed947013e506768cc9",
325
325
  "src/LawSpec/Sessions.hs": "741f5a8bffdaabf47d016d0069e7041dbb20e99313258ff923479aa1f0991b31",
326
- "src/LawSpec/Sessions/Go.hs": "6a2bea954730e340eeea8469edfef7ece624fea358b453221c6f6837196e6c08",
327
- "src/LawSpec/Sessions/Haskell.hs": "2b39ec5a99e5438504dd7d43d3a4debfba2a81b4d0ca015a378bd57eaab3e769",
328
- "src/LawSpec/Sessions/Jvm.hs": "b1fc004fe558840caf1699de497459880d980f8651d928e336f925d84cc75cde",
329
- "src/LawSpec/Sessions/Python.hs": "1f98eb9b3e51176247cb6bb9157ffa30daa64f21266aeb53e9dfd15756a6f186",
330
- "src/LawSpec/Sessions/Rust.hs": "9ad3a48e5dd074ab8d4828ec3402556cdb2d32193139fa18d909ab431e58530d",
331
- "src/LawSpec/Sessions/Web.hs": "9020ed23bdd4232ea51c4d5952e277c7480924408a10c251d1af5e2a4a3cb4d4",
326
+ "src/LawSpec/Sessions/Go.hs": "550a6fa377a76148d0e514e9490992401965f05eaac64dc5909d7bff25273b49",
327
+ "src/LawSpec/Sessions/Haskell.hs": "f366f5feece8d2b1ceac3afbb7e40ed0cbb7c0c5772abc5657eb000d8cbcc164",
328
+ "src/LawSpec/Sessions/Jvm.hs": "bd55375091fe7d8b54d28f97893219d60338b63ffb9cb5c03ec77181f2328531",
329
+ "src/LawSpec/Sessions/Python.hs": "d731d82de534dad981c1f9bfded59bb885dd77824aa061bd903304113383f7d4",
330
+ "src/LawSpec/Sessions/Rust.hs": "4a3548323b93153afe0b847a37227b45c738e00189451efcd84b0071f5a0bdc4",
331
+ "src/LawSpec/Sessions/Web.hs": "616b2bf642a77aa6a9ff20c3acc9ff6923c1c927c3102c7ad368b34d99c16ac8",
332
332
  "src/LawSpec/SpecializeDefinitions.hs": "2bdd6d9b191941d869ef524659e02fed551499aaa2ea98c99323da03af113012",
333
- "src/LawSpec/StatefulModel.hs": "ab2d5eb1c0443f6b527f8f2696a4d0b9ae14f0df91b8cef202c4f0c850e2115b",
333
+ "src/LawSpec/StatefulModel.hs": "188ab12acfdc8df837b603e960bcab274ee3d4e0e00e95ada0638fe24b627dce",
334
334
  "src/LawSpec/TargetNames.hs": "06410a1973d12bc241bfc399c8f5856d1692c6af792bb83b187bca894cfde4ca",
335
335
  "src/LawSpec/TestManifest.hs": "3c2018eea1528d047dff4c5fd2f353ee1ceb339cce7b1c32f0a2390df2d40ac8",
336
336
  "src/LawSpec/Testing.hs": "3bb83c3e74de6f0a09b12736115e47b4db2244e2f749d640e063cfc0500f174c",
337
337
  "src/LawSpec/Time.hs": "9b05a784879a5791087492129bb9bd432d5e23082aa370e2a289552731bfb527",
338
338
  "src/LawSpec/WebData.hs": "a8e907ce04768ec8bf6f88f96d4d0e3e1888451335350d210cf051160daf4e51",
339
339
  "src/LawSpec/WebDefinitions.hs": "b20086e4d9090c5fdd7eecd1dbc489de3e60fddae8a12c0fd83902892eff2c0d",
340
- "src/LawSpec/WebExpr.hs": "5bf5a2082f216646541bfa482f0f4eb492e32da9ab965e1e789256564d64332f",
341
- "src/LawSpec/WebNativeBinding.hs": "1039b25ffe7ad1c033baf7d040de0f667ddc521fc771bdf1ca056e63c842680d",
340
+ "src/LawSpec/WebExpr.hs": "f008ad07ebcd269a93ad5b2325a07626ed07a2443aaff7e9a51882c2984b8fe5",
341
+ "src/LawSpec/WebNativeBinding.hs": "9932e20f6e076cee1bef947e1c3c577d276ce43c674081d333a3f51fdca19136",
342
342
  "src/LawSpec/WebTypes.hs": "60237d8b119e3a18690aa5429e99c8613e0ddae4da76d697de7af8b31aeb1ab0",
343
- "src/LawSpec/Witness.hs": "9ae944c9307df964bc853205269c1e4cb69cc076070bb878fc957f4bdb02de85",
343
+ "src/LawSpec/Witness.hs": "13a924fc879f01655c44f30cada2be86d2c95dd0c84a17f91cd35bdb77f8d203",
344
344
  "stack.yaml": "20ccf4d599e355e60b7aa4f814a7cd4299fe2048616cc2e6dbdc22a7bd8cec73",
345
345
  "stack.yaml.lock": "ae222b9c81af920c56e50fa4596fa57786e7fa5a7b461390362b2b2ff63818c7",
346
346
  "wasm/app/Exports.hs": "4ecbdac8faa2449e6fc61b93c82e6278fa14374154f29b4dacf0eef433f06a47",
347
347
  "wasm/cabal.project": "021e560afdc5eb4cb7169e7119ecb8f92c9ee170245af909c94b612941bff5cc",
348
348
  "wasm/cabal.project.freeze": "733dbed3d2ecccb26e874fd58f136296dad772184deb1658c196b5d54a0814dc",
349
- "wasm/lawspec-wasm.cabal": "b4106f6f330381e0707ba83b4b0b4f00dc1cee1ef93962ecf79156aa19146165",
350
- "npm/core.wasm": "7268bf6b82ef2e41e95a928d7da56f077939a99a383c783aa164583f2fb601b0",
349
+ "wasm/lawspec-wasm.cabal": "145ac9e47202b04085500fd64db9ff98a33b231c2c3e7615be280ae04ccce0d5",
350
+ "npm/core.wasm": "643e0c013f34e7d48540696edf9202e73304a5a4782f458a8d1b954b943f5e7e",
351
351
  "npm/core_jsffi.js": "88d136efe92f7cff5758c8fec8d9b6bbc9707fe37741cebeeb415fe34ce3d72b",
352
352
  "npm/api.mjs": "19e1624f91258c1397f3212faf65b407c62671b0fc5b118520e6a91f7ad7c6ba",
353
- "npm/index.d.ts": "b6beef671c22633fdf369f584bfe9bc9bd0b281c54df06f1946970415e1e7793"
353
+ "npm/index.d.ts": "58ebf96832216d675857bfcc0905e7395172078b726b3da9165e2b96214f35bb"
354
354
  }
355
355
  }
package/core.wasm CHANGED
Binary file
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 1,
3
3
  "sources": ["orders.lawspec"],
4
- "dependencies": { "shop.domain": "^1.0.0" },
5
- "packages": ["../shop-domain"],
4
+ "dependencies": { "shop.domain": "^1.0.0", "shop.tax": "^2.0.0" },
5
+ "packages": ["../shop-domain", "../shop-tax-1", "../shop-tax-2"],
6
6
  "targets": []
7
7
  }
@@ -1,5 +1,8 @@
1
1
  unit shop.orders
2
2
  import shop.domain as domain (Money, Cents, `commutative`, `idempotent`)
3
+ -- shop.domain uses version 1 of shop.tax; this project's range selects
4
+ -- version 2. Both are in the build, and their Bands are different types.
5
+ import shop.tax.api as tax (Band)
3
6
 
4
7
  -- Constructor names are scoped to their unit: this Usd is not domain.Usd.
5
8
  type Currency is | Usd | Gbp end
@@ -12,6 +15,7 @@ lineTotal :: Line -> Money
12
15
  -- any Int64; the last law restricts its inputs to Cents.
13
16
  cheaper :: Int64 -> Int64 -> Int64
14
17
  roundDown :: Int64 -> Int64
18
+ classify :: Int64 -> Band
15
19
 
16
20
  law `dollars settle in dollars` is
17
21
  definition is
@@ -55,3 +59,24 @@ law `rounding down never raises a price` is
55
59
  `for all` (c :: Cents) . roundDown c <= c
56
60
  end
57
61
  end
62
+
63
+ law `prices are classified into version 2 bands` is
64
+ definition is
65
+ `for all` (c :: Cents) . tax.rateOf (classify c) <= 25
66
+ end
67
+ example `nothing` is c = 0 expect classify c = Zero end
68
+ example `small` is c = 9999 expect classify c = Low end
69
+ example `large` is c = 10000 expect classify c = High end
70
+ end
71
+
72
+ law `shop.domain keeps version 1 of the bands` is
73
+ definition is
74
+ domain.dutyOf domain.High = 20
75
+ end
76
+ end
77
+
78
+ law `this project sees version 2 of the bands` is
79
+ definition is
80
+ tax.rateOf High = 25
81
+ end
82
+ end
@@ -1,5 +1,7 @@
1
1
  {
2
2
  "name": "shop.domain",
3
3
  "version": "1.2.0",
4
- "sources": ["src"]
4
+ "sources": ["src"],
5
+ "dependencies": { "shop.tax": "^1.0.0" },
6
+ "packages": ["../shop-tax-1"]
5
7
  }
@@ -1,4 +1,9 @@
1
1
  unit shop.domain
2
+ import shop.tax.api as tax (Band)
3
+
4
+ -- shop.domain depends on version 1 of shop.tax and offers its Band to its own
5
+ -- importers, as if declared here.
6
+ export Band
2
7
 
3
8
  -- A package of reusable types, refinements, definitions and laws. Other units
4
9
  -- import it by name; its declarations keep their own names, so an importer may
@@ -19,6 +24,9 @@ definition centsOf (m :: Money) :: Int64 is
19
24
  match m with | Money c n -> n end
20
25
  end
21
26
 
27
+ -- The duty on a band, at version 1's rates.
28
+ definition dutyOf (b :: Band) :: Int64 is tax.rateOf b end
29
+
22
30
  -- Generic laws are templates: an importer applies them to its own adapters.
23
31
  law `commutative` (f :: a -> a -> a) requires Eq a is
24
32
  definition is
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "shop.tax",
3
+ "version": "1.0.0",
4
+ "sources": ["src"]
5
+ }
@@ -0,0 +1,6 @@
1
+ unit shop.tax.api
2
+ import shop.tax.rates as rates (Band)
3
+
4
+ -- The package's facade: importers use shop.tax.api, and the names it
5
+ -- re-exports are the declarations of shop.tax.rates, not copies.
6
+ export Band, rates.rateOf
@@ -0,0 +1,8 @@
1
+ unit shop.tax.rates
2
+
3
+ -- Version 1 of the tax bands.
4
+ type Band is | Low | High end
5
+
6
+ definition rateOf (b :: Band) :: Int64 is
7
+ match b with | Low -> 5 | High -> 20 end
8
+ end
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "shop.tax",
3
+ "version": "2.0.0",
4
+ "sources": ["src"]
5
+ }
@@ -0,0 +1,6 @@
1
+ unit shop.tax.api
2
+ import shop.tax.rates as rates (Band)
3
+
4
+ -- The package's facade: importers use shop.tax.api, and the names it
5
+ -- re-exports are the declarations of shop.tax.rates, not copies.
6
+ export Band, rates.rateOf
@@ -0,0 +1,9 @@
1
+ unit shop.tax.rates
2
+
3
+ -- Version 2 adds a zero band and changes the rates. A build may hold both
4
+ -- versions: each dependent sees the one its version range selects.
5
+ type Band is | Zero | Low | High end
6
+
7
+ definition rateOf (b :: Band) :: Int64 is
8
+ match b with | Zero -> 0 | Low -> 10 | High -> 25 end
9
+ end
@@ -0,0 +1,35 @@
1
+ unit example.approvals
2
+
3
+ -- The workflows example's approve workflow, run under the real clock. Its
4
+ -- own unit, so the adapters can call the workflow on every target (a Haskell
5
+ -- workflow imports its steps' module).
6
+
7
+ -- Approves order n under the real clock: whether it took less than 550ms,
8
+ -- which the slow order does only when its checks run at the same time (the
9
+ -- longer one, not the two together).
10
+ async approvedQuickly :: Int64 -> Bool
11
+
12
+ law `an all group's checks run at the same time` is
13
+ definition is
14
+ `for all` (n :: Int64) . approvedQuickly n = true
15
+ end
16
+ example `the slow order` is
17
+ n = -1
18
+ expect approvedQuickly n = true
19
+ end
20
+ end
21
+
22
+ -- Approves order n: the messages of its failures, as the workflow reports
23
+ -- them. Order -1's credit check finishes first, but is declared second.
24
+ async approvalErrors :: Int64 -> List Text
25
+
26
+ law `failures are reported in declaration order` is
27
+ definition is
28
+ `for all` (n :: Int64) .
29
+ approvalErrors n = prelude.select (n < 0) ["no stock", "no credit"] []
30
+ end
31
+ example `the slow order` is
32
+ n = -1
33
+ expect approvalErrors n = ["no stock", "no credit"]
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ unit example.warehouse
2
+
3
+ -- Asynchronous adapters bound to native code. Each target's bindings name a
4
+ -- native function or method returning the target's asynchronous type (a
5
+ -- coroutine, Promise, CompletableFuture, suspend function, Go task, Rust
6
+ -- future or IO action); the generated bridge awaits it and converts the
7
+ -- result.
8
+
9
+ -- A price, looked up by a native asynchronous function.
10
+ async priceOf :: Text -> Int32
11
+ -- The same price, computed by a native synchronous function.
12
+ quoteOf :: Text -> Int32
13
+
14
+ law `a looked-up price is the quoted price` is
15
+ definition is `for all` (sku :: Text) . priceOf sku = quoteOf sku end
16
+ example `a free sample` is
17
+ sku = "free"
18
+ expect priceOf sku = 0
19
+ end
20
+ end
21
+
22
+ -- A shelf is a native object; its methods are asynchronous.
23
+ handle Shelf
24
+
25
+ newShelf :: Unit -> Shelf
26
+ async restock :: Shelf -> (amount :: Int32 where amount >= 0 && amount <= 100) -> Unit
27
+ async count :: Shelf -> Int64
28
+
29
+ definition modelRestock (amount :: Int32 where amount >= 0 && amount <= 100) (total :: Int64 where total >= 0 && total <= 1000000) :: Int64 is
30
+ total + amount
31
+ end
32
+
33
+ definition modelCount (total :: Int64) :: Pair Int64 Int64 is Pair total total end
34
+
35
+ model shelf :: shared Shelf by Int64 is
36
+ start newShelf ~ 0
37
+ restock ~ modelRestock
38
+ count ~ modelCount
39
+ end
@@ -124,3 +124,23 @@ law `the empty stack stays empty` is
124
124
  `for all` (x :: Int8) . prelude.isEmpty (prelude.pop (prelude.stackOf [x])) = true
125
125
  end
126
126
  end
127
+
128
+ -- Size-indexed stacks and queues: a pop, top, dequeue or front needs a
129
+ -- non-empty one (SizedStack (n + 1) a), so it can never fail.
130
+ law `the top is what was pushed` is
131
+ definition is
132
+ `for all` (x :: Int8) (s :: SizedStack 2 Int8) . prelude.sizedTop (prelude.sizedPush x s) = x
133
+ end
134
+ end
135
+
136
+ law `popping undoes a push` is
137
+ definition is
138
+ `for all` (s :: SizedStack 3 Int8) . prelude.sizedStackItems (prelude.sizedPop (prelude.sizedPush 7 s)) = prelude.sizedStackItems s
139
+ end
140
+ end
141
+
142
+ law `a sized queue keeps arrival order` is
143
+ definition is
144
+ `for all` (x :: Int8) (y :: Int8) . prelude.sizedFront (prelude.sizedEnqueue y (prelude.sizedEnqueue x SizedQueueEmpty)) = x
145
+ end
146
+ end
@@ -97,8 +97,9 @@ law `messages reach a mailbox on another node` is
97
97
  definition is `for all` (x :: Int32) . remoteLedger x = 2 * x end
98
98
  end
99
99
 
100
- -- A channel end sent to another node: the node that sends it relays the
101
- -- conversation, so the end works on its new node as it did on the old one.
100
+ -- A channel end sent to another node. A local end stays where it is and
101
+ -- the sending node relays its conversation, so the end works on its new
102
+ -- node as it did on the old one.
102
103
  protocol Handoff is
103
104
  send Doubling
104
105
  end
@@ -108,3 +109,24 @@ async remoteHandoff :: Int32 -> Int64
108
109
  law `a channel end handed to another node` is
109
110
  definition is `for all` (x :: Int32) . remoteHandoff x = 2 * x end
110
111
  end
112
+
113
+ -- An end that is already between nodes moves: its state goes to the new
114
+ -- node, with any values that reached it, and its peer is told the new
115
+ -- address. Here an end whose peer is on node C goes from A to B and on to D
116
+ -- over a network that loses, duplicates and delays frames, while C is
117
+ -- already sending to it; then A and B close, and the conversation between C
118
+ -- and D still completes.
119
+ protocol Answering is
120
+ receive Int32
121
+ send Int64
122
+ end
123
+
124
+ protocol Passing is
125
+ send Answering
126
+ end
127
+
128
+ async remoteHandoffOnward :: Int32 -> Int64
129
+
130
+ law `a channel end moved on twice` is
131
+ definition is `for all` (x :: Int32) . remoteHandoffOnward x = 2 * x end
132
+ end
@@ -57,3 +57,37 @@ law `push agrees with the reference` is
57
57
  `for all` (x :: Int8) (s :: Stack n) . (pushed x ~s; pop ~s) = x
58
58
  end
59
59
  end
60
+
61
+ -- A function may take several flow parameters: pushBoth takes two stacks and
62
+ -- leaves each one higher. A call passes ~a ~b, rebinding each.
63
+ definition pushBoth (x :: Int8) (a :: Stack n / Stack (n + 1)) (b :: Stack m / Stack (m + 1)) :: Unit is
64
+ ~a := Push x a; ~b := Push x b
65
+ end
66
+
67
+ law `both stacks get the value` is
68
+ definition is
69
+ `for all` (x :: Int8) (a :: Stack n) (b :: Stack m) . (pushBoth x ~a ~b; pop ~a; pop ~b) = x
70
+ end
71
+ end
72
+
73
+ -- A flow call may sit in a branch of an if or a match, when every branch
74
+ -- leaves the stack at the same type: here each branch pushes once.
75
+ law `a push in each branch` is
76
+ definition is
77
+ `for all` (x :: Int8) (s :: Stack n) .
78
+ ((if x > 0 then push x ~s else push 0 ~s); pop ~s) = (if x > 0 then x else 0)
79
+ end
80
+ end
81
+
82
+ law `a push chosen by a match` is
83
+ definition is
84
+ `for all` (m :: Maybe Int8) (s :: Stack n) .
85
+ ((match m with
86
+ | Just v -> push v ~s
87
+ | Nothing -> push 0 ~s
88
+ end); pop ~s) = (match m with
89
+ | Just v -> v
90
+ | Nothing -> prelude.Int8 0
91
+ end)
92
+ end
93
+ end
@@ -140,3 +140,25 @@ law `refined amounts are drawn from their range` is
140
140
  `for all` (p :: Purse) (amount :: Int32 where amount >= 1 && amount <= 1000) . spend p amount >= 1
141
141
  end
142
142
  end
143
+
144
+ -- if c then a else b evaluates only the branch c selects, and each branch is
145
+ -- checked knowing which way c went: the division is safe because n > 0.
146
+ definition share (total :: Int32 where total >= 0 && total <= 1000) (n :: Int32 where n >= 0 && n <= 10) :: Int32 is
147
+ if n > 0 then prelude.quot total n else 0
148
+ end
149
+
150
+ law `a share is at most the total` is
151
+ definition is
152
+ `for all` (t :: Int32 where t >= 0 && t <= 1000) (n :: Int32 where n >= 0 && n <= 10) . share t n <= t
153
+ end
154
+ example `nobody to share with` is
155
+ t = 7
156
+ n = 0
157
+ expect share t n = 0
158
+ end
159
+ example `three people` is
160
+ t = 7
161
+ n = 3
162
+ expect share t n = 2
163
+ end
164
+ end
@@ -119,3 +119,24 @@ scenario `two counts at once` in counter is
119
119
  total <- read
120
120
  expect total = 2
121
121
  end
122
+
123
+ -- Two channels between the same two processes close a cycle. That is
124
+ -- accepted when no process waits for another in a cycle: here the first
125
+ -- process sends before it waits, so the echo can always answer.
126
+ protocol Echo is
127
+ receive Int64
128
+ end
129
+
130
+ scenario `a count is echoed back` in counter is
131
+ channel out :: Report
132
+ channel back :: Echo
133
+ par
134
+ n <- increment
135
+ send out n
136
+ receive back m
137
+ expect m = 1
138
+ with
139
+ receive out k
140
+ send back k
141
+ end
142
+ end
@@ -18,11 +18,12 @@ protocol Hire is
18
18
  send Serve
19
19
  end
20
20
 
21
- -- Adds through a server process.
22
- add :: Int32 -> Int32 -> Integer
21
+ -- Adds through a server process. Processes that talk over channels wait for
22
+ -- each other, so these adapters are asynchronous.
23
+ async add :: Int32 -> Int32 -> Integer
23
24
 
24
25
  -- Adds through a worker that is handed the server's end over a Hire channel.
25
- addHired :: Int32 -> Int32 -> Integer
26
+ async addHired :: Int32 -> Int32 -> Integer
26
27
 
27
28
  law `a server adds` is
28
29
  definition is
@@ -143,3 +143,33 @@ law `vetting a named child reports its age` is
143
143
  vet (Signup "ada" (prelude.Int32 age)) = Left (VetFailures [VetCheckAgeFailed "too young"])
144
144
  end
145
145
  end
146
+
147
+ -- In a workflow with asynchronous steps, an all group runs them at the same
148
+ -- time. Order -1's checks are slow: the stock check takes 400ms and the
149
+ -- credit check 250ms, so run in turn they would take 650ms. Every order with
150
+ -- a negative number fails both checks.
151
+ type Order is Order number :: Int64 end
152
+
153
+ async checkStock :: Order -> Either Text Order
154
+ async checkCredit :: Order -> Either Text Order
155
+
156
+ definition firstOrder (a :: Order) (b :: Order) :: Order is a end
157
+
158
+ workflow approve :: Order -> Either _ Order is
159
+ all accumulate
160
+ then checkStock
161
+ then checkCredit
162
+ end
163
+ combine firstOrder
164
+ end
165
+
166
+ -- The failures are in the order the steps are declared, not the order they
167
+ -- finish in.
168
+ law `approval reports failures in declaration order` is
169
+ definition is
170
+ `for all` (n :: Int64) .
171
+ approve (Order n) = prelude.select (n < 0)
172
+ (Left (ApproveFailures [ApproveCheckStockFailed "no stock", ApproveCheckCreditFailed "no credit"]))
173
+ (Right (Order n))
174
+ end
175
+ end
package/index.d.ts CHANGED
@@ -186,6 +186,7 @@ export interface NativeTypeBinding {
186
186
  native: NativeReference;
187
187
  constructors?: NativeConstructorBinding[];
188
188
  codec?: NativeCodecBinding;
189
+ arguments?: string[];
189
190
  }
190
191
 
191
192
  export interface NativeGeneratorBinding {
@@ -196,7 +197,9 @@ export interface NativeGeneratorBinding {
196
197
 
197
198
  export interface NativeFunctionBinding {
198
199
  declaration: string;
199
- native: NativeReference;
200
+ native?: NativeReference;
201
+ method?: string;
202
+ constructor?: NativeReference;
200
203
  }
201
204
 
202
205
  export interface NativeGoImport {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lawspec",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "State the law once. Check it everywhere.",
5
5
  "license": "MIT",
6
6
  "repository": {