lawspec 0.24.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.
- package/CHANGELOG.md +109 -1
- package/README.md +34 -26
- package/UNICODE-LICENSE.txt +39 -0
- package/api.mjs +6 -23
- package/bin/lawspec.mjs +148 -65
- package/build.json +245 -177
- package/builtin-data-names.mjs +73 -0
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- package/examples/native-payments/clojure/lawspec.json +13 -2
- package/examples/native-payments/csharp/lawspec.json +13 -2
- package/examples/native-payments/elixir/lawspec.json +14 -3
- package/examples/native-payments/erlang/lawspec.json +14 -3
- package/examples/native-payments/fsharp/lawspec.json +14 -3
- package/examples/native-payments/gleam/lawspec.json +14 -3
- package/examples/native-payments/go/lawspec.json +14 -3
- package/examples/native-payments/groovy/lawspec.json +14 -3
- package/examples/native-payments/haskell/lawspec.json +14 -3
- package/examples/native-payments/java/lawspec.json +14 -3
- package/examples/native-payments/javascript/lawspec.json +14 -3
- package/examples/native-payments/kotlin/lawspec.json +14 -3
- package/examples/native-payments/python/lawspec.json +14 -3
- package/examples/native-payments/rust/lawspec.json +14 -3
- package/examples/native-payments/scala/lawspec.json +14 -3
- package/examples/native-payments/swift/lawspec.json +14 -3
- package/examples/native-payments/typescript/lawspec.json +14 -3
- package/examples/packages/orders/lawspec.json +25 -5
- package/examples/packages/orders/orders.lawspec +57 -53
- package/examples/packages/shop-domain/src/domain.lawspec +36 -33
- package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-1/src/rates.lawspec +5 -4
- package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/rates.lawspec +6 -4
- package/examples/rc1/authorization-snapshots.lawspec +113 -0
- package/examples/rc1/banner-filenames.lawspec +64 -0
- package/examples/rc1/bit-codec.lawspec +57 -0
- package/examples/rc1/bounded-witness-search.lawspec +151 -0
- package/examples/rc1/conflicting-requirements.lawspec +31 -0
- package/examples/rc1/constructive-witnesses.lawspec +120 -0
- package/examples/rc1/documentary-review.lawspec +43 -0
- package/examples/rc1/empty-domains.lawspec +47 -0
- package/examples/rc1/finite-integer-domains.lawspec +76 -0
- package/examples/rc1/law-metadata.lawspec +30 -0
- package/examples/rc1/native-payments.lawspec +108 -0
- package/examples/rc1/nesting/rrr.lawspec +34 -0
- package/examples/rc1/nesting/rru.lawspec +57 -0
- package/examples/rc1/nesting/rur.lawspec +58 -0
- package/examples/rc1/nesting/ruu.lawspec +78 -0
- package/examples/rc1/nesting/urr.lawspec +53 -0
- package/examples/rc1/nesting/uru.lawspec +73 -0
- package/examples/rc1/nesting/uur.lawspec +74 -0
- package/examples/rc1/nesting/uuu.lawspec +96 -0
- package/examples/rc1/order-workflow.lawspec +127 -0
- package/examples/rc1/parcel-measurements.lawspec +93 -0
- package/examples/rc1/picture-records.lawspec +52 -0
- package/examples/rc1/picture-tuples.lawspec +48 -0
- package/examples/rc1/record-payloads.lawspec +57 -0
- package/examples/rc1/recursive-records.lawspec +65 -0
- package/examples/rc1/refund-conformance.lawspec +45 -0
- package/examples/rc1/refund-policy.lawspec +89 -0
- package/examples/rc1/requirement-composition.lawspec +90 -0
- package/examples/rc1/structural-records.lawspec +54 -0
- package/examples/rc1-authoring.lawspec +57 -0
- package/examples/specs/abilities.lawspec +67 -65
- package/examples/specs/ability_imports.lawspec +58 -57
- package/examples/specs/actors.lawspec +23 -22
- package/examples/specs/algebra.lawspec +142 -141
- package/examples/specs/approvals.lawspec +16 -15
- package/examples/specs/async_bindings.lawspec +10 -9
- package/examples/specs/async_fetch.lawspec +12 -11
- package/examples/specs/atoi_codec.lawspec +16 -15
- package/examples/specs/boolean_flags.lawspec +10 -9
- package/examples/specs/builtins.lawspec +73 -72
- package/examples/specs/canonical_url.lawspec +14 -13
- package/examples/specs/collections.lawspec +153 -154
- package/examples/specs/composition.lawspec +70 -66
- package/examples/specs/concurrent_collections.lawspec +8 -7
- package/examples/specs/consistency.lawspec +4 -3
- package/examples/specs/contracts.lawspec +80 -79
- package/examples/specs/crypto.lawspec +26 -25
- package/examples/specs/ctc.lawspec +148 -0
- package/examples/specs/currying.lawspec +32 -31
- package/examples/specs/data_types.lawspec +50 -49
- package/examples/specs/distribution.lawspec +57 -56
- package/examples/specs/domain_modeling.lawspec +48 -47
- package/examples/specs/durations.lawspec +39 -38
- package/examples/specs/equivalent.lawspec +25 -24
- package/examples/specs/failures.lawspec +64 -63
- package/examples/specs/finite_data.lawspec +32 -31
- package/examples/specs/flow_stack.lawspec +64 -63
- package/examples/specs/gadt_expressions.lawspec +50 -49
- package/examples/specs/generation.lawspec +115 -114
- package/examples/specs/handler_bindings.lawspec +42 -40
- package/examples/specs/handles.lawspec +2 -1
- package/examples/specs/harness.lawspec +45 -43
- package/examples/specs/harness_testing.lawspec +18 -13
- package/examples/specs/indexed_arithmetic.lawspec +401 -126
- package/examples/specs/indexed_families.lawspec +182 -66
- package/examples/specs/keywords.lawspec +22 -21
- package/examples/specs/limits.lawspec +6 -5
- package/examples/specs/list_contracts.lawspec +121 -120
- package/examples/specs/list_refinements.lawspec +43 -42
- package/examples/specs/lists.lawspec +45 -44
- package/examples/specs/matchers.lawspec +79 -78
- package/examples/specs/matching.lawspec +43 -42
- package/examples/specs/mixed_inputs.lawspec +25 -24
- package/examples/specs/models.lawspec +44 -43
- package/examples/specs/parse_port.lawspec +28 -27
- package/examples/specs/payments.lawspec +55 -54
- package/examples/specs/railway.lawspec +59 -58
- package/examples/specs/records.lawspec +149 -148
- package/examples/specs/records_inner.lawspec +5 -4
- package/examples/specs/recursive_refinements.lawspec +30 -29
- package/examples/specs/refined_definitions.lawspec +24 -23
- package/examples/specs/refinements.lawspec +58 -57
- package/examples/specs/resilience.lawspec +159 -158
- package/examples/specs/resources.lawspec +61 -60
- package/examples/specs/scalar_adapters.lawspec +60 -59
- package/examples/specs/scalar_catalog.lawspec +165 -164
- package/examples/specs/scalars.lawspec +78 -77
- package/examples/specs/scheduling_order.lawspec +8 -7
- package/examples/specs/scheduling_overlap.lawspec +5 -4
- package/examples/specs/sequences.lawspec +66 -65
- package/examples/specs/sessions.lawspec +13 -12
- package/examples/specs/slug.lawspec +16 -15
- package/examples/specs/sum_refinements.lawspec +42 -41
- package/examples/specs/tables.lawspec +29 -28
- package/examples/specs/total_functions.lawspec +71 -70
- package/examples/specs/workflows.lawspec +101 -100
- package/examples-command.mjs +8 -4
- package/explain.mjs +114 -0
- package/expression-presentation.mjs +333 -0
- package/files.mjs +16 -0
- package/index.d.ts +406 -11
- package/launcher.mjs +9 -2
- package/lsp.mjs +235 -0
- package/native-evidence.mjs +187 -0
- package/native-examples.mjs +8 -1
- package/node-events-reporter.mjs +23 -0
- package/package.json +8 -1
- package/positional-fields.mjs +13 -0
- package/proof.d.ts +35 -0
- package/proof.mjs +174 -0
- package/starter-rc1.lawspec +26 -0
- package/starter.lawspec +16 -15
- package/templates.mjs +6 -4
- package/test-command.mjs +107 -35
- package/typed-presentation.mjs +165 -0
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
29
|
+
type Scaled is a record{ count :: Int64 scale :: Float64} end type
|
|
30
30
|
|
|
31
|
-
|
|
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
|
-
|
|
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
|
|
63
|
-
definition
|
|
64
|
-
|
|
65
|
-
(let refused = prelude.attempt (add (0 - 1)) in add n) = n
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
law
|
|
70
|
-
definition
|
|
71
|
-
|
|
72
|
-
(let refused = prelude.attempt (add (0 - 1)) in add n) = n
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
law
|
|
77
|
-
definition
|
|
78
|
-
|
|
79
|
-
octetCount (prelude.textOf n ++ "é") = prelude.length (prelude.textOf n) + 2
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
law
|
|
84
|
-
definition
|
|
85
|
-
|
|
86
|
-
octetCount (prelude.textOf n ++ "é") = prelude.length (prelude.textOf n) + 2
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
law
|
|
91
|
-
definition
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
law
|
|
95
|
-
definition
|
|
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
|
-
|
|
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
|
-
|
|
107
|
+
type Badge is a record{
|
|
106
108
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
label :: (v :: Text where validName v)
|
|
110
|
-
end
|
|
109
|
+
label :: (v :: Text where validName v)}
|
|
110
|
+
end type
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
function withId (body :: Pet) (key :: Int64) -> Pet is body with id = Just key end function
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
function validPet (p :: Pet) -> Bool is p.name matches regex "[a-z]{2,8}" end function
|
|
115
115
|
|
|
116
|
-
law
|
|
117
|
-
definition
|
|
118
|
-
|
|
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
|
|
123
|
-
definition
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
(
|
|
16
|
-
|
|
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
|
-
(
|
|
20
|
-
|
|
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
|
|
31
|
-
definition
|
|
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
|
|
39
|
-
definition
|
|
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
|
|
43
|
-
definition
|
|
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
|
|
50
|
-
definition
|
|
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
|
|
9
|
-
definition
|
|
10
|
-
|
|
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
|
|
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
|
|
21
|
+
law "|staged formatter|
|
|
22
22
|
(render :: Int32 -> Text -> Text)
|
|
23
23
|
(reference :: Int32 -> Text -> Text)
|
|
24
24
|
is
|
|
25
|
-
definition
|
|
26
|
-
|
|
27
|
-
render port suffix = reference port suffix
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
law
|
|
32
|
-
definition
|
|
33
|
-
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
example
|
|
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
|
|
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
|
|
52
|
-
definition
|
|
53
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
11
|
-
Branch
|
|
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
|
|
15
|
-
definition
|
|
16
|
-
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
end) = pair
|
|
20
|
-
end
|
|
21
|
-
example
|
|
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
|
|
28
|
-
definition
|
|
29
|
-
|
|
30
|
-
(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end) = tree
|
|
34
|
-
end
|
|
35
|
-
example
|
|
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
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
57
|
-
definition
|
|
58
|
-
|
|
59
|
-
reciprocalFirst (positivePair value) = 1 / value
|
|
60
|
-
end
|
|
61
|
-
example
|
|
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
|