lawspec 0.25.0 → 0.26.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 (149) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/README.md +5 -4
  3. package/api.mjs +0 -8
  4. package/bin/lawspec.mjs +14 -52
  5. package/build.json +77 -105
  6. package/core.wasm +2 -2
  7. package/core_jsffi.js +5 -0
  8. package/examples/native-payments/clojure/lawspec.json +1 -1
  9. package/examples/native-payments/csharp/lawspec.json +1 -1
  10. package/examples/native-payments/elixir/lawspec.json +1 -1
  11. package/examples/native-payments/erlang/lawspec.json +1 -1
  12. package/examples/native-payments/fsharp/lawspec.json +1 -1
  13. package/examples/native-payments/gleam/lawspec.json +1 -1
  14. package/examples/native-payments/go/lawspec.json +1 -1
  15. package/examples/native-payments/groovy/lawspec.json +1 -1
  16. package/examples/native-payments/haskell/lawspec.json +1 -1
  17. package/examples/native-payments/java/lawspec.json +1 -1
  18. package/examples/native-payments/javascript/lawspec.json +1 -1
  19. package/examples/native-payments/kotlin/lawspec.json +1 -1
  20. package/examples/native-payments/python/lawspec.json +1 -1
  21. package/examples/native-payments/rust/lawspec.json +1 -1
  22. package/examples/native-payments/scala/lawspec.json +1 -1
  23. package/examples/native-payments/swift/lawspec.json +1 -1
  24. package/examples/native-payments/typescript/lawspec.json +1 -1
  25. package/examples/packages/orders/lawspec.json +1 -1
  26. package/examples/packages/orders/orders.lawspec +27 -25
  27. package/examples/packages/shop-domain/src/domain.lawspec +15 -14
  28. package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
  29. package/examples/packages/shop-tax-1/src/rates.lawspec +1 -0
  30. package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
  31. package/examples/packages/shop-tax-2/src/rates.lawspec +1 -0
  32. package/examples/rc1/authorization-snapshots.lawspec +24 -23
  33. package/examples/rc1/banner-filenames.lawspec +7 -6
  34. package/examples/rc1/bit-codec.lawspec +12 -11
  35. package/examples/rc1/bounded-witness-search.lawspec +52 -45
  36. package/examples/rc1/conflicting-requirements.lawspec +8 -7
  37. package/examples/rc1/constructive-witnesses.lawspec +40 -33
  38. package/examples/rc1/documentary-review.lawspec +9 -8
  39. package/examples/rc1/empty-domains.lawspec +16 -15
  40. package/examples/rc1/finite-integer-domains.lawspec +24 -23
  41. package/examples/rc1/law-metadata.lawspec +6 -5
  42. package/examples/rc1/native-payments.lawspec +17 -16
  43. package/examples/rc1/nesting/rrr.lawspec +4 -3
  44. package/examples/rc1/nesting/rru.lawspec +7 -6
  45. package/examples/rc1/nesting/rur.lawspec +7 -6
  46. package/examples/rc1/nesting/ruu.lawspec +10 -9
  47. package/examples/rc1/nesting/urr.lawspec +7 -6
  48. package/examples/rc1/nesting/uru.lawspec +10 -9
  49. package/examples/rc1/nesting/uur.lawspec +10 -9
  50. package/examples/rc1/nesting/uuu.lawspec +13 -12
  51. package/examples/rc1/order-workflow.lawspec +18 -17
  52. package/examples/rc1/parcel-measurements.lawspec +14 -13
  53. package/examples/rc1/picture-records.lawspec +6 -5
  54. package/examples/rc1/picture-tuples.lawspec +6 -5
  55. package/examples/rc1/record-payloads.lawspec +12 -11
  56. package/examples/rc1/recursive-records.lawspec +11 -10
  57. package/examples/rc1/refund-conformance.lawspec +7 -6
  58. package/examples/rc1/refund-policy.lawspec +15 -14
  59. package/examples/rc1/requirement-composition.lawspec +26 -25
  60. package/examples/rc1/structural-records.lawspec +13 -12
  61. package/examples/rc1-authoring.lawspec +6 -5
  62. package/examples/specs/abilities.lawspec +67 -65
  63. package/examples/specs/ability_imports.lawspec +58 -57
  64. package/examples/specs/actors.lawspec +23 -22
  65. package/examples/specs/algebra.lawspec +142 -141
  66. package/examples/specs/approvals.lawspec +16 -15
  67. package/examples/specs/async_bindings.lawspec +10 -9
  68. package/examples/specs/async_fetch.lawspec +12 -11
  69. package/examples/specs/atoi_codec.lawspec +16 -15
  70. package/examples/specs/boolean_flags.lawspec +10 -9
  71. package/examples/specs/builtins.lawspec +73 -72
  72. package/examples/specs/canonical_url.lawspec +14 -13
  73. package/examples/specs/collections.lawspec +153 -154
  74. package/examples/specs/composition.lawspec +70 -66
  75. package/examples/specs/concurrent_collections.lawspec +8 -7
  76. package/examples/specs/consistency.lawspec +4 -3
  77. package/examples/specs/contracts.lawspec +80 -79
  78. package/examples/specs/crypto.lawspec +26 -25
  79. package/examples/specs/ctc.lawspec +148 -0
  80. package/examples/specs/currying.lawspec +32 -31
  81. package/examples/specs/data_types.lawspec +50 -49
  82. package/examples/specs/distribution.lawspec +57 -56
  83. package/examples/specs/domain_modeling.lawspec +48 -47
  84. package/examples/specs/durations.lawspec +39 -38
  85. package/examples/specs/equivalent.lawspec +25 -24
  86. package/examples/specs/failures.lawspec +64 -63
  87. package/examples/specs/finite_data.lawspec +32 -31
  88. package/examples/specs/flow_stack.lawspec +64 -63
  89. package/examples/specs/gadt_expressions.lawspec +50 -49
  90. package/examples/specs/generation.lawspec +115 -114
  91. package/examples/specs/handler_bindings.lawspec +42 -40
  92. package/examples/specs/handles.lawspec +2 -1
  93. package/examples/specs/harness.lawspec +45 -43
  94. package/examples/specs/harness_testing.lawspec +18 -13
  95. package/examples/specs/indexed_arithmetic.lawspec +401 -126
  96. package/examples/specs/indexed_families.lawspec +182 -66
  97. package/examples/specs/keywords.lawspec +22 -21
  98. package/examples/specs/limits.lawspec +6 -5
  99. package/examples/specs/list_contracts.lawspec +121 -120
  100. package/examples/specs/list_refinements.lawspec +43 -42
  101. package/examples/specs/lists.lawspec +45 -44
  102. package/examples/specs/matchers.lawspec +79 -78
  103. package/examples/specs/matching.lawspec +43 -42
  104. package/examples/specs/mixed_inputs.lawspec +25 -24
  105. package/examples/specs/models.lawspec +44 -43
  106. package/examples/specs/parse_port.lawspec +28 -27
  107. package/examples/specs/payments.lawspec +55 -54
  108. package/examples/specs/railway.lawspec +59 -58
  109. package/examples/specs/records.lawspec +149 -148
  110. package/examples/specs/records_inner.lawspec +5 -4
  111. package/examples/specs/recursive_refinements.lawspec +30 -29
  112. package/examples/specs/refined_definitions.lawspec +24 -23
  113. package/examples/specs/refinements.lawspec +58 -57
  114. package/examples/specs/resilience.lawspec +159 -158
  115. package/examples/specs/resources.lawspec +61 -60
  116. package/examples/specs/scalar_adapters.lawspec +60 -59
  117. package/examples/specs/scalar_catalog.lawspec +165 -164
  118. package/examples/specs/scalars.lawspec +78 -77
  119. package/examples/specs/scheduling_order.lawspec +8 -7
  120. package/examples/specs/scheduling_overlap.lawspec +5 -4
  121. package/examples/specs/sequences.lawspec +66 -65
  122. package/examples/specs/sessions.lawspec +13 -12
  123. package/examples/specs/slug.lawspec +16 -15
  124. package/examples/specs/sum_refinements.lawspec +42 -41
  125. package/examples/specs/tables.lawspec +29 -28
  126. package/examples/specs/total_functions.lawspec +71 -70
  127. package/examples/specs/workflows.lawspec +101 -100
  128. package/examples-command.mjs +4 -6
  129. package/explain.mjs +6 -4
  130. package/expression-presentation.mjs +8 -8
  131. package/files.mjs +1 -1
  132. package/index.d.ts +4 -527
  133. package/launcher.mjs +9 -2
  134. package/lsp.mjs +10 -6
  135. package/native-examples.mjs +2 -2
  136. package/package.json +1 -1
  137. package/starter-rc1.lawspec +6 -5
  138. package/starter.lawspec +16 -15
  139. package/templates.mjs +4 -2
  140. package/migrate.mjs +0 -135
  141. package/migration-bindings.mjs +0 -86
  142. package/migration-cases.mjs +0 -45
  143. package/migration-collections.mjs +0 -54
  144. package/migration-correspondence.mjs +0 -275
  145. package/migration-generation.mjs +0 -99
  146. package/migration-laws.mjs +0 -102
  147. package/migration-records.mjs +0 -166
  148. package/migration-source.mjs +0 -247
  149. package/migration-write.mjs +0 -156
@@ -4,121 +4,122 @@ unit example.contracts
4
4
  -- over Bytes and Text, refined records, and handlers named like their
5
5
  -- abilities.
6
6
 
7
- type Refusal is | Negative | Empty end
7
+ type Refusal is one of | Negative | Empty end type
8
8
 
9
- definition bump (n :: Int64) (total :: Int64) :: Pair Int64 Int64 fails with Refusal is
9
+ procedure bump (n :: Int64) (total :: Int64) -> Pair Int64 Int64 fails with Refusal is
10
10
  if n < 0 then raise Negative else
11
- if total > 1000000 || n > 1000000 then Pair total total else Pair (prelude.Int64 (total + n)) (prelude.Int64 (total + n))
12
- end
11
+ if total > 1000000 || n > 1000000 then Pair total total else Pair (prelude.Int64 (total + n)) (prelude.Int64 (total + n)) end if end if
12
+ end procedure
13
13
 
14
14
  -- A definition that may fail but does not.
15
- definition peek (total :: Int64) :: Pair Int64 Int64 fails with Refusal is Pair total total end
15
+ procedure peek (total :: Int64) -> Pair Int64 Int64 fails with Refusal is Pair total total end procedure
16
16
 
17
17
  ability Counter is
18
18
  add :: Int64 -> Int64 fails with Refusal
19
19
  current :: Int64 fails with Refusal
20
- end
20
+ end ability
21
21
 
22
22
  -- Named like its ability.
23
23
  handler counter for Counter with state total :: Int64 start 0 is
24
- add by bump
25
- current by peek
26
- end
24
+ operation add by bump end operation
25
+ operation current by peek end operation
26
+ end handler
27
27
 
28
28
  -- A state with no typed form keeps this handler on the dynamic path.
29
- type Scaled is Scaled count :: Int64 scale :: Float64 end
29
+ type Scaled is a record{ count :: Int64 scale :: Float64} end type
30
30
 
31
- definition bumpScaled (n :: Int64) (s :: Scaled) :: Pair Int64 Scaled fails with Refusal is
31
+ procedure bumpScaled (n :: Int64) (s :: Scaled) -> Pair Int64 Scaled fails with Refusal is
32
32
  if n < 0 then raise Negative else
33
33
  if s.count > 1000000 || n > 1000000 then Pair s.count s else
34
- Pair (prelude.Int64 (s.count + n)) (s with count = prelude.Int64 (s.count + n))
35
- end
34
+ Pair (prelude.Int64 (s.count + n)) (s with count = prelude.Int64 (s.count + n)) end if end if
35
+ end procedure
36
36
 
37
- definition peekScaled (s :: Scaled) :: Pair Int64 Scaled fails with Refusal is Pair s.count s end
37
+ procedure peekScaled (s :: Scaled) -> Pair Int64 Scaled fails with Refusal is Pair s.count s end procedure
38
38
 
39
- handler scaledCounter for Counter with state s :: Scaled start Scaled 0 1.0 is
40
- add by bumpScaled
41
- current by peekScaled
42
- end
39
+ handler scaledCounter for Counter with state s :: Scaled start Scaled record{ count = 0 , scale = 1.0} is
40
+ operation add by bumpScaled end operation
41
+ operation current by peekScaled end operation
42
+ end handler
43
43
 
44
44
  -- Bytes and Text inside handler clauses, on both paths.
45
45
  ability Codec is
46
46
  octetCount :: Text -> Int64
47
47
  label :: Text -> Int32 -> Text
48
- end
48
+ end ability
49
49
 
50
50
  handler codec for Codec is
51
- octetCount t is prelude.length (prelude.octets (prelude.utf8 t)) end
52
- label t n is prelude.join "-" [t, prelude.textOf n] ++ prelude.slice 0 0 t end
53
- end
51
+ operation octetCount t is prelude.length (prelude.octets (prelude.utf8 t)) end operation
52
+ operation label t n is prelude.join "-" [t, prelude.textOf n] ++ prelude.slice 0 0 t end operation
53
+ end handler
54
54
 
55
55
  handler scaledCodec for Codec with state s :: Float64 start 1.0 is
56
- octetCount t is prelude.length (prelude.bytesOf (prelude.octets (prelude.utf8 t))) end
57
- label t n is prelude.take (prelude.length t + 9) (t ++ "-" ++ prelude.textOf n) end
58
- end
56
+ operation octetCount t is prelude.length (prelude.bytesOf (prelude.octets (prelude.utf8 t))) end operation
57
+ operation label t n is prelude.take (prelude.length t + 9) (t ++ "-" ++ prelude.textOf n) end operation
58
+ end handler
59
59
 
60
60
  -- A failed operation leaves the handler's state as it was, on the typed
61
61
  -- path (counter) and the dynamic one (scaledCounter).
62
- law `a refused add changes nothing` using counter is
63
- definition is
64
- `for all` (n :: Int64 where n >= 0 && n <= 1000) .
65
- (let refused = prelude.attempt (add (0 - 1)) in add n) = n
66
- end
67
- end
68
-
69
- law `a refused add changes nothing, dynamically` using scaledCounter is
70
- definition is
71
- `for all` (n :: Int64 where n >= 0 && n <= 1000) .
72
- (let refused = prelude.attempt (add (0 - 1)) in add n) = n
73
- end
74
- end
75
-
76
- law `a text's octets count its UTF-8 bytes` using codec is
77
- definition is
78
- `for all` (n :: Int32 where n >= 0 && n <= 1000) .
79
- octetCount (prelude.textOf n ++ "é") = prelude.length (prelude.textOf n) + 2
80
- end
81
- end
82
-
83
- law `a text's octets count its UTF-8 bytes, dynamically` using scaledCodec is
84
- definition is
85
- `for all` (n :: Int32 where n >= 0 && n <= 1000) .
86
- octetCount (prelude.textOf n ++ "é") = prelude.length (prelude.textOf n) + 2
87
- end
88
- end
89
-
90
- law `a label joins its parts` using codec is
91
- definition is label "member" 3 = "member-3" end
92
- end
93
-
94
- law `a label joins its parts, dynamically` using scaledCodec is
95
- definition is label "member" 3 = "member-3" end
96
- end
62
+ law "|a refused add changes nothing| using counter is
63
+ definition :
64
+ for all (n :: Int64 where n >= 0 && n <= 1000) =>
65
+ (let refused = prelude.attempt (add (0 - 1)) in add n end let) = n end for all
66
+ end definition
67
+ end law
68
+
69
+ law "|a refused add changes nothing, dynamically| using scaledCounter is
70
+ definition :
71
+ for all (n :: Int64 where n >= 0 && n <= 1000) =>
72
+ (let refused = prelude.attempt (add (0 - 1)) in add n end let) = n end for all
73
+ end definition
74
+ end law
75
+
76
+ law "|a text's octets count its UTF-8 bytes| using codec is
77
+ definition :
78
+ for all (n :: Int32 where n >= 0 && n <= 1000) =>
79
+ octetCount (prelude.textOf n ++ "é") = prelude.length (prelude.textOf n) + 2 end for all
80
+ end definition
81
+ end law
82
+
83
+ law "|a text's octets count its UTF-8 bytes, dynamically| using scaledCodec is
84
+ definition :
85
+ for all (n :: Int32 where n >= 0 && n <= 1000) =>
86
+ octetCount (prelude.textOf n ++ "é") = prelude.length (prelude.textOf n) + 2 end for all
87
+ end definition
88
+ end law
89
+
90
+ law "|a label joins its parts| using codec is
91
+ definition : label "member" 3 = "member-3" end definition
92
+ end law
93
+
94
+ law "|a label joins its parts, dynamically| using scaledCodec is
95
+ definition : label "member" 3 = "member-3" end definition
96
+ end law
97
97
 
98
98
  -- Refined records.
99
- type Pet is
100
- Pet
99
+ type Pet is a record{
100
+
101
101
  id :: Maybe Int64
102
- name :: (v :: Text where v matches regex "[a-z]+")
103
- end
102
+ name :: (v :: Text where v matches regex "[a-z]+")}
103
+ end type
104
+
105
+ function validName (name :: Text) -> Bool is name matches regex "[a-z]+" end function
104
106
 
105
- definition validName (name :: Text) :: Bool is name matches regex "[a-z]+" end
107
+ type Badge is a record{
106
108
 
107
- type Badge is
108
- Badge
109
- label :: (v :: Text where validName v)
110
- end
109
+ label :: (v :: Text where validName v)}
110
+ end type
111
111
 
112
- definition withId (body :: Pet) (key :: Int64) :: Pet is body with id = Just key end
112
+ function withId (body :: Pet) (key :: Int64) -> Pet is body with id = Just key end function
113
113
 
114
- definition validPet (p :: Pet) :: Bool is p.name matches regex "[a-z]{2,8}" end
114
+ function validPet (p :: Pet) -> Bool is p.name matches regex "[a-z]{2,8}" end function
115
115
 
116
- law `an id is set by a record update` is
117
- definition is
118
- `for all` (p :: Pet where validPet p) (key :: Int64) . (withId p key).id = Just key and (withId p key).name = p.name
119
- end
120
- end
116
+ law "|an id is set by a record update| is
117
+ definition :
118
+ for all (p :: Pet where validPet p) (key :: Int64) => (withId p key).id = Just key and (withId p key).name = p.name end for all
119
+ end definition
120
+ end law
121
121
 
122
- law `a badge keeps its label` is
123
- definition is `for all` (t :: Badge) . validName t.label = true end
124
- end
122
+ law "|a badge keeps its label| is
123
+ definition : for all (t :: Badge) => validName t.label = true end for all end definition
124
+ end law
125
+ end unit
@@ -9,43 +9,44 @@ import lawspec.crypto (ExchangeKeyPair, ExchangePublicKey, Encapsulated, Signing
9
9
  -- with its long-term key; the client checks the signature, encapsulates a
10
10
  -- secret to the exchange key, and both sides derive the same AEAD key from
11
11
  -- it. The client's message then crosses sealed.
12
- definition handshake (message :: Bytes) (context :: Bytes) :: Maybe Bytes uses KeyExchange, Signature, Aead is
13
- match signingKeyPair with
14
- | SigningKeyPair verifying signing ->
15
- (match exchangeKeyPair with
16
- | ExchangeKeyPair public secret ->
12
+ procedure handshake (message :: Bytes) (context :: Bytes) -> Maybe Bytes uses KeyExchange, Signature, Aead is
13
+ first matching case of signingKeyPair :
14
+ when SigningKeyPair verifying signing then
15
+ (first matching case of exchangeKeyPair :
16
+ when ExchangeKeyPair public secret then
17
17
  (let offer = sign signing (valueOfExchangePublicKey public) in
18
18
  if verify verifying (valueOfExchangePublicKey public) offer then
19
- (match encapsulate public with
20
- | Encapsulated sent shared ->
19
+ (first matching case of encapsulate public :
20
+ when Encapsulated sent shared then
21
21
  (let client = deriveAeadKey shared context in
22
22
  let server = deriveAeadKey (decapsulate secret sent) context in
23
- unseal server (seal client message context) context)
24
- end)
25
- else Nothing)
26
- end)
27
- end
28
- end
23
+ unseal server (seal client message context) context end let end let)
24
+ end case)
25
+ else Nothing end if end let)
26
+ end case)
27
+ end case
28
+ end procedure
29
29
 
30
- law `a handshake carries the message` is
31
- definition is `for all` (message :: Bytes) (context :: Bytes) . handshake message context = Just message end
32
- end
30
+ law "|a handshake carries the message| is
31
+ definition : for all (message :: Bytes) (context :: Bytes) => handshake message context = Just message end for all end definition
32
+ end law
33
33
 
34
34
  -- A native adapter: a short fingerprint of a public key, from its SHA3-256
35
35
  -- digest.
36
36
  fingerprint :: Bytes -> Bytes uses Hash
37
37
 
38
- law `a fingerprint is 8 bytes` is
39
- definition is `for all` (key :: Bytes) . prelude.length (fingerprint key) = 8 end
40
- end
38
+ law "|a fingerprint is 8 bytes| is
39
+ definition : for all (key :: Bytes) => prelude.length (fingerprint key) = 8 end for all end definition
40
+ end law
41
41
 
42
- law `a key has one fingerprint` is
43
- definition is `for all` (key :: Bytes) . fingerprint key = fingerprint key end
44
- end
42
+ law "|a key has one fingerprint| is
43
+ definition : for all (key :: Bytes) => fingerprint key = fingerprint key end for all end definition
44
+ end law
45
45
 
46
46
  -- A native adapter that seals with a fresh key and opens again.
47
47
  roundTrip :: Bytes -> Bool uses Aead
48
48
 
49
- law `sealed messages open` is
50
- definition is `for all` (message :: Bytes) . roundTrip message = true end
51
- end
49
+ law "|sealed messages open| is
50
+ definition : for all (message :: Bytes) => roundTrip message = true end for all end definition
51
+ end law
52
+ end unit
@@ -0,0 +1,148 @@
1
+ unit tensorflow.ctc
2
+
3
+ type Frame is one of
4
+ | Blank
5
+ | H
6
+ | E
7
+ | L
8
+ | O
9
+ end type
10
+
11
+ function decodeAfter
12
+ (previous of type Frame)
13
+ (frames of type List Frame) -> List Frame is
14
+ first matching case of frames:
15
+ when Nil then []
16
+ when Cons Blank remaining then
17
+ decodeAfter Blank remaining
18
+ when Cons frame remaining then
19
+ if frame = previous then
20
+ decodeAfter frame remaining
21
+ else
22
+ Cons frame (decodeAfter frame remaining)
23
+ end if
24
+ end case
25
+ end function
26
+
27
+ function "|decode frames| (frames of type List Frame) -> List Frame is
28
+ decodeAfter Blank frames
29
+ end function
30
+
31
+ function encodeFrames (letters of type List Frame) -> List Frame is
32
+ first matching case of letters:
33
+ when Nil then []
34
+ when Cons letter remaining then
35
+ Cons letter (Cons Blank (encodeFrames remaining))
36
+ end case
37
+ end function
38
+
39
+ law "|empty input produces empty output| is
40
+ definition:
41
+ "|decode frames| [] must be ([] :: List Frame)
42
+ end definition
43
+ end law
44
+
45
+ law "|a single letter survives| is
46
+ definition:
47
+ for all (letter of type Frame) =>
48
+ letter != Blank implies
49
+ "|decode frames| [letter] must be [letter]
50
+ end for all
51
+ end definition
52
+ end law
53
+
54
+ law "|decoded output contains no blanks| is
55
+ description:
56
+ "Blanks separate repeated letters but never appear in decoded output."
57
+ end description
58
+ definition:
59
+ for all (frames of type List Frame) =>
60
+ not (Blank in "|decode frames| frames)
61
+ end for all
62
+ end definition
63
+ expect "|decode frames| frames = expected
64
+ in table (frames, expected):
65
+ row [], []
66
+ row [L, L], [L]
67
+ row [L, Blank, L], [L, L]
68
+ row [Blank, Blank], []
69
+ row [H, H, E, L, L, Blank, L, O, O], [H, E, L, L, O]
70
+ end table
71
+ end law
72
+
73
+ law "|padding with blanks changes nothing| is
74
+ definition:
75
+ for all (frames of type List Frame) =>
76
+ "|decode frames| ([Blank] ++ frames ++ [Blank])
77
+ must be "|decode frames| frames
78
+ end for all
79
+ end definition
80
+ end law
81
+
82
+ law "|repeating a frame changes nothing| is
83
+ definition:
84
+ for all
85
+ (before of type List Frame)
86
+ (frame of type Frame)
87
+ (after of type List Frame) =>
88
+ "|decode frames| (before ++ [frame, frame] ++ after)
89
+ must be "|decode frames| (before ++ [frame] ++ after)
90
+ end for all
91
+ end definition
92
+ end law
93
+
94
+ law "|a blank preserves a doubled letter| is
95
+ definition:
96
+ for all (letter of type Frame) =>
97
+ letter != Blank implies
98
+ "|decode frames| [letter, Blank, letter] must be [letter, letter]
99
+ end for all
100
+ end definition
101
+ end law
102
+
103
+ law "|distinct letters retain their order| is
104
+ definition:
105
+ for all (left of type Frame) (right of type Frame) =>
106
+ left != Blank and right != Blank and left != right implies
107
+ "|decode frames| [left, right] must be [left, right]
108
+ end for all
109
+ end definition
110
+ end law
111
+
112
+ law "|a blank separates independently decoded segments| is
113
+ definition:
114
+ for all (left of type List Frame) (right of type List Frame) =>
115
+ "|decode frames| (left ++ [Blank] ++ right) must be
116
+ ("|decode frames| left) ++ ("|decode frames| right)
117
+ end for all
118
+ end definition
119
+ end law
120
+
121
+ law "|decoding never lengthens the input| is
122
+ definition:
123
+ for all (frames of type List Frame) =>
124
+ prelude.length ("|decode frames| frames) <= prelude.length frames
125
+ end for all
126
+ end definition
127
+ end law
128
+
129
+ law "|every blank-free output has an encoding| is
130
+ description:
131
+ "Every sequence of letters can be represented, including doubled letters."
132
+ end description
133
+ definition:
134
+ for all (letters of type List Frame) =>
135
+ not (Blank in letters) implies
136
+ there exists (frames of type List Frame) such that
137
+ "|decode frames| frames must be letters
138
+ end exists
139
+ end for all
140
+ end definition
141
+ end law
142
+
143
+ harness tensorflow.ctc.testing for tensorflow.ctc is
144
+ for law "|every blank-free output has an encoding|
145
+ witness encodeFrames letters for letters.frames
146
+ end for law
147
+ end harness
148
+ end unit
@@ -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