lawspec 0.24.0 → 0.25.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 (87) hide show
  1. package/CHANGELOG.md +67 -1
  2. package/README.md +29 -22
  3. package/UNICODE-LICENSE.txt +39 -0
  4. package/api.mjs +14 -23
  5. package/bin/lawspec.mjs +186 -65
  6. package/build.json +255 -159
  7. package/builtin-data-names.mjs +73 -0
  8. package/core.wasm +2 -2
  9. package/examples/native-payments/clojure/lawspec.json +13 -2
  10. package/examples/native-payments/csharp/lawspec.json +13 -2
  11. package/examples/native-payments/elixir/lawspec.json +14 -3
  12. package/examples/native-payments/erlang/lawspec.json +14 -3
  13. package/examples/native-payments/fsharp/lawspec.json +14 -3
  14. package/examples/native-payments/gleam/lawspec.json +14 -3
  15. package/examples/native-payments/go/lawspec.json +14 -3
  16. package/examples/native-payments/groovy/lawspec.json +14 -3
  17. package/examples/native-payments/haskell/lawspec.json +14 -3
  18. package/examples/native-payments/java/lawspec.json +14 -3
  19. package/examples/native-payments/javascript/lawspec.json +14 -3
  20. package/examples/native-payments/kotlin/lawspec.json +14 -3
  21. package/examples/native-payments/python/lawspec.json +14 -3
  22. package/examples/native-payments/rust/lawspec.json +14 -3
  23. package/examples/native-payments/scala/lawspec.json +14 -3
  24. package/examples/native-payments/swift/lawspec.json +14 -3
  25. package/examples/native-payments/typescript/lawspec.json +14 -3
  26. package/examples/packages/orders/lawspec.json +25 -5
  27. package/examples/packages/orders/orders.lawspec +36 -34
  28. package/examples/packages/shop-domain/src/domain.lawspec +23 -21
  29. package/examples/packages/shop-tax-1/src/rates.lawspec +4 -4
  30. package/examples/packages/shop-tax-2/src/rates.lawspec +5 -4
  31. package/examples/rc1/authorization-snapshots.lawspec +112 -0
  32. package/examples/rc1/banner-filenames.lawspec +63 -0
  33. package/examples/rc1/bit-codec.lawspec +56 -0
  34. package/examples/rc1/bounded-witness-search.lawspec +144 -0
  35. package/examples/rc1/conflicting-requirements.lawspec +30 -0
  36. package/examples/rc1/constructive-witnesses.lawspec +113 -0
  37. package/examples/rc1/documentary-review.lawspec +42 -0
  38. package/examples/rc1/empty-domains.lawspec +46 -0
  39. package/examples/rc1/finite-integer-domains.lawspec +75 -0
  40. package/examples/rc1/law-metadata.lawspec +29 -0
  41. package/examples/rc1/native-payments.lawspec +107 -0
  42. package/examples/rc1/nesting/rrr.lawspec +33 -0
  43. package/examples/rc1/nesting/rru.lawspec +56 -0
  44. package/examples/rc1/nesting/rur.lawspec +57 -0
  45. package/examples/rc1/nesting/ruu.lawspec +77 -0
  46. package/examples/rc1/nesting/urr.lawspec +52 -0
  47. package/examples/rc1/nesting/uru.lawspec +72 -0
  48. package/examples/rc1/nesting/uur.lawspec +73 -0
  49. package/examples/rc1/nesting/uuu.lawspec +95 -0
  50. package/examples/rc1/order-workflow.lawspec +126 -0
  51. package/examples/rc1/parcel-measurements.lawspec +92 -0
  52. package/examples/rc1/picture-records.lawspec +51 -0
  53. package/examples/rc1/picture-tuples.lawspec +47 -0
  54. package/examples/rc1/record-payloads.lawspec +56 -0
  55. package/examples/rc1/recursive-records.lawspec +64 -0
  56. package/examples/rc1/refund-conformance.lawspec +44 -0
  57. package/examples/rc1/refund-policy.lawspec +88 -0
  58. package/examples/rc1/requirement-composition.lawspec +89 -0
  59. package/examples/rc1/structural-records.lawspec +53 -0
  60. package/examples/rc1-authoring.lawspec +56 -0
  61. package/examples-command.mjs +11 -5
  62. package/explain.mjs +112 -0
  63. package/expression-presentation.mjs +333 -0
  64. package/files.mjs +16 -0
  65. package/index.d.ts +929 -11
  66. package/lsp.mjs +231 -0
  67. package/migrate.mjs +135 -0
  68. package/migration-bindings.mjs +86 -0
  69. package/migration-cases.mjs +45 -0
  70. package/migration-collections.mjs +54 -0
  71. package/migration-correspondence.mjs +275 -0
  72. package/migration-generation.mjs +99 -0
  73. package/migration-laws.mjs +102 -0
  74. package/migration-records.mjs +166 -0
  75. package/migration-source.mjs +247 -0
  76. package/migration-write.mjs +156 -0
  77. package/native-evidence.mjs +187 -0
  78. package/native-examples.mjs +8 -1
  79. package/node-events-reporter.mjs +23 -0
  80. package/package.json +8 -1
  81. package/positional-fields.mjs +13 -0
  82. package/proof.d.ts +35 -0
  83. package/proof.mjs +174 -0
  84. package/starter-rc1.lawspec +25 -0
  85. package/templates.mjs +2 -2
  86. package/test-command.mjs +107 -35
  87. package/typed-presentation.mjs +165 -0
@@ -0,0 +1,113 @@
1
+ unit example.rc1.constructiveWitnesses
2
+
3
+ type RequestLabel is a record{
4
+ text of type Text
5
+ }
6
+ end type
7
+
8
+ function keep (value of type a) -> a is
9
+ value
10
+ end function
11
+
12
+ function increment (value of type Integer) -> Integer is
13
+ value + 1
14
+ end function
15
+
16
+ function "|add for approval| (left of type Integer) (right of type Integer) -> Integer is
17
+ left + right
18
+ end function
19
+
20
+ function labelFor (allowed of type Bool) -> RequestLabel is
21
+ RequestLabel record{text = if allowed then "approved" else "declined" end if}
22
+ end function
23
+
24
+ function amountDescription (amount of type Integer) -> Text is
25
+ if amount > 0 then "positive" else "nonpositive" end if
26
+ end function
27
+
28
+ law "|every integer has a successor| is
29
+ description:
30
+ "Every exact integer has a larger integer exactly one step away."
31
+ end
32
+ definition:
33
+ for all (value of type Integer) =>
34
+ there exists (answer of type Integer where answer > value) such that
35
+ answer must be value + 1
36
+ end
37
+ end
38
+ end
39
+ expect increment value = expected
40
+ in table (value, expected):
41
+ row -1, 0
42
+ row 0, 1
43
+ row 1, 2
44
+ end
45
+ end
46
+
47
+ law "|each request has a matching label| is
48
+ description:
49
+ "An allowed request can be labelled approved; another can be labelled declined."
50
+ end
51
+ definition:
52
+ for all (allowed of type Bool) =>
53
+ there exists (label of type RequestLabel) such that
54
+ label.text must be (if allowed then "approved" else "declined" end if)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ law "|positive amounts have a description| is
61
+ definition:
62
+ for all (allowed of type Bool) =>
63
+ there exists (amount of type Integer where amount > 0) such that
64
+ there exists (word of type Text) such that
65
+ word must be "positive"
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ law "|separate requirements can choose separate values| is
73
+ definition:
74
+ (there exists (value of type Integer) such that value = 1 end)
75
+ and
76
+ (there exists (value of type Integer) such that value = 2 end)
77
+ end
78
+ end
79
+
80
+ law "|a request cannot be both allowed and disallowed| is
81
+ definition:
82
+ there must not exist (allowed of type Bool) such that
83
+ allowed and not allowed
84
+ end
85
+ end
86
+ end
87
+
88
+ law "|an empty request domain needs no witness| is
89
+ definition:
90
+ for all (allowed of type Bool where false) =>
91
+ there exists (answer of type Integer) such that
92
+ false
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ harness example.rc1.constructiveWitnesses.testing for example.rc1.constructiveWitnesses is
99
+ for law "|every integer has a successor|
100
+ witness keep (value `|add for approval| 1) for definition.value.answer
101
+ for law "|each request has a matching label|
102
+ witness keep (labelFor allowed) for allowed.label
103
+ for law "|positive amounts have a description|
104
+ witness (if allowed then 1 else 2 end if) for allowed.amount
105
+ witness keep (amountDescription amount) for allowed.amount.word
106
+ for law "|separate requirements can choose separate values|
107
+ witness 1 for branch1.value
108
+ witness 2 for branch2.value
109
+ for law "|a request cannot be both allowed and disallowed|
110
+ witness false for allowed
111
+ for law "|an empty request domain needs no witness|
112
+ witness 0 for allowed.answer
113
+ end
@@ -0,0 +1,42 @@
1
+ unit example.rc1.documentaryReview
2
+
3
+ type Review is one of
4
+ | Approved
5
+ | Declined
6
+ end type
7
+
8
+ function review (allowed of type Bool) -> Review is
9
+ if allowed then Approved else Declined end if
10
+ end function
11
+
12
+ law "|allowed requests are approved| is
13
+ id: "REVIEW-001"
14
+ owner: Payments.Review
15
+ description:
16
+ "An allowed request receives approval."
17
+ end
18
+ definition:
19
+ review true must be Approved
20
+ end
21
+ references:
22
+ #S{ref law "|other requests are declined| description,
23
+ ref function review}
24
+ ref law "|other requests are declined| references."|Review policy|
25
+ "|Review policy|: "Allowed requests are approved; all other requests are declined."
26
+ end
27
+ end
28
+
29
+ law "|other requests are declined| is
30
+ owner: Payments.Review
31
+ id: "REVIEW-002"
32
+ description:
33
+ "A request without permission receives a decline."
34
+ end
35
+ definition:
36
+ review false must be Declined
37
+ end
38
+ references:
39
+ ref law "|allowed requests are approved| definition
40
+ "|Review policy|: "Allowed requests are approved; all other requests are declined."
41
+ end
42
+ end
@@ -0,0 +1,46 @@
1
+ unit example.rc1.emptyDomains
2
+
3
+ type UnissuedApproval is one of
4
+ | Unissued of type UnissuedApproval
5
+ | StillUnissued of type UnissuedApproval
6
+ end type
7
+
8
+ law "|no issued approval incurs an obligation| is
9
+ definition:
10
+ for all (approval of type UnissuedApproval) =>
11
+ false
12
+ end
13
+ end
14
+ description:
15
+ "No approval can be constructed in this domain. Universal verification evaluates zero cases."
16
+ end
17
+ end
18
+
19
+ law "|excluded inputs require no witnesses| is
20
+ definition:
21
+ for all (enabled of type Bool where false) =>
22
+ there must exist (witness of type Integer) such that
23
+ false
24
+ end
25
+ end
26
+ end
27
+ description:
28
+ "The restriction excludes every input. This establishes no witness for any actual input."
29
+ end
30
+ end
31
+
32
+ law "|absence remains different from existence| is
33
+ definition:
34
+ there must not exist (approval of type UnissuedApproval) such that
35
+ true
36
+ end
37
+ end
38
+ end
39
+
40
+ law "|excluded payments incur no obligation| is
41
+ definition:
42
+ for all (eligible of type Bool where false) =>
43
+ false
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,75 @@
1
+ unit example.rc1.finiteIntegerDomains
2
+
3
+ function credit (amount of type Integer) -> Integer is
4
+ amount + 1
5
+ end function
6
+
7
+ law "|each small credit has its exact settlement amount| is
8
+ description:
9
+ "Every amount from zero through three receives exactly one extra cent."
10
+ end
11
+ definition:
12
+ for all (amount of type Integer where amount >= 0 and amount <= 3) =>
13
+ there exists (settled of type Integer where
14
+ settled >= amount + 1 and settled <= amount + 1) such that
15
+ settled must be credit amount
16
+ end
17
+ end
18
+ end
19
+ expect credit amount = expected
20
+ in table (amount, expected):
21
+ row 0, 1
22
+ row 1, 2
23
+ row 2, 3
24
+ row 3, 4
25
+ end
26
+ end
27
+
28
+ law "|small retry budgets include zero| is
29
+ definition:
30
+ for all (budget of type Whole where budget <= 3) =>
31
+ must budget >= 0
32
+ end
33
+ end
34
+ end
35
+
36
+ law "|positive attempt counts exclude zero| is
37
+ definition:
38
+ there must not exist (attempts of type Nat where attempts <= 3) such that
39
+ attempts = 0
40
+ end
41
+ end
42
+ end
43
+
44
+ law "|a small credit cannot settle outside the limit| is
45
+ definition:
46
+ there must not exist (settled of type Integer where
47
+ settled >= 0 and settled <= 3) such that
48
+ settled = 4
49
+ end
50
+ end
51
+ end
52
+
53
+ law "|consecutive exact cents have no intermediate amount| is
54
+ description:
55
+ "No exact integer amount lies strictly between two consecutive cents."
56
+ end
57
+ definition:
58
+ for all (amount of type Integer)
59
+ (between of type Integer where between > amount and between < amount + 1)
60
+ =>
61
+ false
62
+ end
63
+ end
64
+ end
65
+
66
+ law "|every exact amount has an adjacent settlement amount| is
67
+ definition:
68
+ for all (amount of type Integer) =>
69
+ there exists (settled of type Integer where
70
+ settled > amount and settled <= amount + 2) such that
71
+ settled must be amount + 1
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,29 @@
1
+ unit example.rc1.lawMetadata
2
+
3
+ type Review is one of
4
+ | Approved
5
+ | Declined
6
+ end type
7
+
8
+ function review (allowed of type Bool) -> Review is
9
+ if allowed then Approved else Declined end if
10
+ end function
11
+
12
+ law "|allowed requests are approved| is
13
+ id: "REVIEW-001"
14
+ owner: Payments.Review
15
+ description:
16
+ "An allowed request receives approval."
17
+ end
18
+ definition:
19
+ review true must be Approved
20
+ end
21
+ end
22
+
23
+ law "|other requests are declined| is
24
+ owner: Payments.Review
25
+ id: "REVIEW-002"
26
+ definition:
27
+ review false must be Declined
28
+ end
29
+ end
@@ -0,0 +1,107 @@
1
+ unit example.payments
2
+
3
+ -- Executable acceptance model for canonical native domain bindings.
4
+ -- Applications may call Money "Price", amount "major", and currency "unit";
5
+ -- those representation choices must not alter these laws.
6
+ type Currency is one of
7
+ | USD
8
+ | EUR
9
+ | GBP
10
+ end type
11
+
12
+ type Money is a record{
13
+ amount of type Decimal
14
+ currency of type Currency
15
+ }
16
+ end type
17
+
18
+ type Payment is one of
19
+ | Paid of type Money
20
+ | Declined of type Text
21
+ end type
22
+
23
+ addFee of type Money -> Money
24
+ roundTrip of type Payment -> Payment
25
+ archive of type List (Maybe Payment) -> List (Maybe Payment)
26
+
27
+ function feeModel (money of type Money) -> Money is
28
+ first matching case of money:
29
+ when Money record{amount = amount, currency = currency} then
30
+ Money record{amount = amount + 0.2, currency = currency}
31
+ end case
32
+ end function
33
+
34
+ law "|fees preserve currency and exact decimal value| is
35
+ definition:
36
+ for all (money of type Money) =>
37
+ addFee money must be feeModel money
38
+ end
39
+ end
40
+
41
+ example "|decimal tenths|:
42
+ money = Money record{amount = 0.1, currency = USD}
43
+ expect addFee money = Money record{amount = 0.3, currency = USD}
44
+ end
45
+
46
+ example "|small amount is not rounded away|:
47
+ money = Money record{
48
+ amount = 0.000000000000000000000000000001, currency = EUR
49
+ }
50
+ expect addFee money = Money record{
51
+ amount = 0.200000000000000000000000000001, currency = EUR
52
+ }
53
+ end
54
+
55
+ example "|beyond binary floating precision|:
56
+ money = Money record{amount = 9007199254740993.1, currency = GBP}
57
+ expect addFee money = Money record{
58
+ amount = 9007199254740993.3, currency = GBP
59
+ }
60
+ end
61
+ end
62
+
63
+ law "|payment variants and payloads survive native conversion| is
64
+ definition:
65
+ for all (payment of type Payment) =>
66
+ roundTrip payment must be payment
67
+ end
68
+ end
69
+
70
+ example "|successful payment|:
71
+ payment = Paid (Money record{amount = 12.34, currency = EUR})
72
+ expect roundTrip payment = Paid (Money record{
73
+ amount = 12.34, currency = EUR
74
+ })
75
+ end
76
+
77
+ example "|declined payment|:
78
+ payment = Declined "card declined"
79
+ expect roundTrip payment = Declined "card declined"
80
+ end
81
+ end
82
+
83
+ law "|archives preserve order duplicates and absence| is
84
+ definition:
85
+ for all (payments of type List (Maybe Payment)) =>
86
+ archive payments must be payments
87
+ end
88
+ end
89
+
90
+ example "|empty archive|:
91
+ payments = []
92
+ expect archive payments = []
93
+ end
94
+
95
+ example "|missing is different from a declined payment|:
96
+ payments = [
97
+ Nothing, Just (Declined ""),
98
+ Just (Paid (Money record{amount = 0.1, currency = USD})),
99
+ Just (Paid (Money record{amount = 0.1, currency = USD}))
100
+ ]
101
+ expect archive payments = [
102
+ Nothing, Just (Declined ""),
103
+ Just (Paid (Money record{amount = 0.1, currency = USD})),
104
+ Just (Paid (Money record{amount = 0.1, currency = USD}))
105
+ ]
106
+ end
107
+ end
@@ -0,0 +1,33 @@
1
+ unit example.delivery.rrr
2
+
3
+ type EmailDelivery is a record{
4
+ recipient of type Text
5
+ document of type record{number of type Text
6
+ file of type record{fileName of type Text
7
+ byteCount of type Whole}}
8
+ }
9
+ end type
10
+
11
+ function "|email invoice PDF file name|
12
+ (delivery of type EmailDelivery) -> Maybe Text is
13
+ first matching case of delivery:
14
+ when record{document = record{file = record{fileName = name}}}
15
+ then Just name
16
+ end case
17
+ end function
18
+
19
+ function emailPdfInvoice (name of type Text) -> EmailDelivery is
20
+ EmailDelivery record{recipient = "accounts@example.com", document =
21
+ record{number = "INV-2026-10", file = record{fileName = name,
22
+ byteCount = 1200}}}
23
+ end function
24
+
25
+ law "|emailPdfInvoice result| is
26
+ description:
27
+ "PDF invoices sent by email retain their file names."
28
+ end
29
+ definition:
30
+ "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
31
+ "invoice.pdf"
32
+ end
33
+ end
@@ -0,0 +1,56 @@
1
+ unit example.delivery.rru
2
+
3
+ type File is one of
4
+ | Pdf of type record{fileName of type Text
5
+ byteCount of type Whole}
6
+ | PlainText of type record{fileName of type Text}
7
+ end type
8
+
9
+ type EmailDelivery is a record{
10
+ recipient of type Text
11
+ document of type record{number of type Text
12
+ file of type File}
13
+ }
14
+ end type
15
+
16
+ function "|email invoice PDF file name|
17
+ (delivery of type EmailDelivery) -> Maybe Text is
18
+ first matching case of delivery:
19
+ when record{document = record{file = Pdf record{fileName = name}}}
20
+ then Just name
21
+ otherwise Nothing
22
+ end case
23
+ end function
24
+
25
+ function emailPdfInvoice (name of type Text) -> EmailDelivery is
26
+ EmailDelivery record{recipient = "accounts@example.com", document =
27
+ record{number = "INV-2026-10", file = (Pdf (record{fileName =
28
+ name,
29
+ byteCount = 1200}))}}
30
+ end function
31
+
32
+ law "|emailPdfInvoice result| is
33
+ description:
34
+ "PDF invoices sent by email retain their file names."
35
+ end
36
+ definition:
37
+ "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
38
+ "invoice.pdf"
39
+ end
40
+ end
41
+
42
+ function emailPlainTextInvoice (name of type Text) -> EmailDelivery is
43
+ EmailDelivery record{recipient = "accounts@example.com", document =
44
+ record{number = "INV-2026-10", file = (PlainText (record{fileName =
45
+ name}))}}
46
+ end function
47
+
48
+ law "|emailPlainTextInvoice result| is
49
+ description:
50
+ "Plain-text invoices have no PDF file name."
51
+ end
52
+ definition:
53
+ "|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
54
+ Nothing
55
+ end
56
+ end
@@ -0,0 +1,57 @@
1
+ unit example.delivery.rur
2
+
3
+ type Document is one of
4
+ | Invoice of type record{number of type Text
5
+ file of type record{fileName of type Text
6
+ byteCount of type Whole}}
7
+ | Letter of type record{subject of type Text
8
+ file of type record{fileName of type Text
9
+ byteCount of type Whole}}
10
+ end type
11
+
12
+ type EmailDelivery is a record{
13
+ recipient of type Text
14
+ document of type Document
15
+ }
16
+ end type
17
+
18
+ function "|email invoice PDF file name|
19
+ (delivery of type EmailDelivery) -> Maybe Text is
20
+ first matching case of delivery:
21
+ when record{document = Invoice record{file = record{fileName = name}}}
22
+ then Just name
23
+ otherwise Nothing
24
+ end case
25
+ end function
26
+
27
+ function emailPdfInvoice (name of type Text) -> EmailDelivery is
28
+ EmailDelivery record{recipient = "accounts@example.com", document = (Invoice
29
+ (record{number = "INV-2026-10", file = record{fileName
30
+ = name, byteCount = 1200}}))}
31
+ end function
32
+
33
+ law "|emailPdfInvoice result| is
34
+ description:
35
+ "PDF invoices sent by email retain their file names."
36
+ end
37
+ definition:
38
+ "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
39
+ "invoice.pdf"
40
+ end
41
+ end
42
+
43
+ function emailPdfLetter (name of type Text) -> EmailDelivery is
44
+ EmailDelivery record{recipient = "accounts@example.com", document = (Letter
45
+ (record{subject = "Receipt", file = record{fileName =
46
+ name, byteCount = 1200}}))}
47
+ end function
48
+
49
+ law "|emailPdfLetter result| is
50
+ description:
51
+ "Letters have no invoice PDF file name."
52
+ end
53
+ definition:
54
+ "|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
55
+ Nothing
56
+ end
57
+ end
@@ -0,0 +1,77 @@
1
+ unit example.delivery.ruu
2
+
3
+ type File is one of
4
+ | Pdf of type record{fileName of type Text
5
+ byteCount of type Whole}
6
+ | PlainText of type record{fileName of type Text}
7
+ end type
8
+
9
+ type Document is one of
10
+ | Invoice of type record{number of type Text
11
+ file of type File}
12
+ | Letter of type record{subject of type Text
13
+ file of type File}
14
+ end type
15
+
16
+ type EmailDelivery is a record{
17
+ recipient of type Text
18
+ document of type Document
19
+ }
20
+ end type
21
+
22
+ function "|email invoice PDF file name|
23
+ (delivery of type EmailDelivery) -> Maybe Text is
24
+ first matching case of delivery:
25
+ when record{document = Invoice record{file = Pdf record{fileName = name}}}
26
+ then Just name
27
+ otherwise Nothing
28
+ end case
29
+ end function
30
+
31
+ function emailPdfInvoice (name of type Text) -> EmailDelivery is
32
+ EmailDelivery record{recipient = "accounts@example.com", document = (Invoice
33
+ (record{number = "INV-2026-10", file = (Pdf (record{fileName = name,
34
+ byteCount = 1200}))}))}
35
+ end function
36
+
37
+ law "|emailPdfInvoice result| is
38
+ description:
39
+ "PDF invoices sent by email retain their file names."
40
+ end
41
+ definition:
42
+ "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
43
+ "invoice.pdf"
44
+ end
45
+ end
46
+
47
+ function emailPlainTextInvoice (name of type Text) -> EmailDelivery is
48
+ EmailDelivery record{recipient = "accounts@example.com", document = (Invoice
49
+ (record{number = "INV-2026-10", file = (PlainText
50
+ (record{fileName = name}))}))}
51
+ end function
52
+
53
+ law "|emailPlainTextInvoice result| is
54
+ description:
55
+ "Plain-text invoices have no PDF file name."
56
+ end
57
+ definition:
58
+ "|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
59
+ Nothing
60
+ end
61
+ end
62
+
63
+ function emailPdfLetter (name of type Text) -> EmailDelivery is
64
+ EmailDelivery record{recipient = "accounts@example.com", document = (Letter
65
+ (record{subject = "Receipt", file = (Pdf (record{fileName = name, byteCount
66
+ = 1200}))}))}
67
+ end function
68
+
69
+ law "|emailPdfLetter result| is
70
+ description:
71
+ "Letters have no invoice PDF file name."
72
+ end
73
+ definition:
74
+ "|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
75
+ Nothing
76
+ end
77
+ end
@@ -0,0 +1,52 @@
1
+ unit example.delivery.urr
2
+
3
+ type Delivery is one of
4
+ | Email of type record{recipient of type Text
5
+ document of type record{number of type Text
6
+ file of type record{fileName of type Text
7
+ byteCount of type Whole}}}
8
+ | Download of type record{document of type record{number of type Text
9
+ file of type record{fileName of type Text
10
+ byteCount of type Whole}}}
11
+ end type
12
+
13
+ function "|email invoice PDF file name|
14
+ (delivery of type Delivery) -> Maybe Text is
15
+ first matching case of delivery:
16
+ when Email record{document = record{file = record{fileName = name}}}
17
+ then Just name
18
+ otherwise Nothing
19
+ end case
20
+ end function
21
+
22
+ function emailPdfInvoice (name of type Text) -> Delivery is
23
+ Email (record{recipient = "accounts@example.com", document =
24
+ record{number = "INV-2026-10", file = record{fileName =
25
+ name,
26
+ byteCount = 1200}}})
27
+ end function
28
+
29
+ law "|emailPdfInvoice result| is
30
+ description:
31
+ "PDF invoices sent by email retain their file names."
32
+ end
33
+ definition:
34
+ "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
35
+ "invoice.pdf"
36
+ end
37
+ end
38
+
39
+ function downloadPdfInvoice (name of type Text) -> Delivery is
40
+ Download (record{document = record{number =
41
+ "INV-2026-10", file = record{fileName = name, byteCount = 1200}}})
42
+ end function
43
+
44
+ law "|downloadPdfInvoice result| is
45
+ description:
46
+ "Downloads have no email invoice PDF file name."
47
+ end
48
+ definition:
49
+ "|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
50
+ Nothing
51
+ end
52
+ end