lawspec 0.25.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +109 -1
- package/NORMALIZATION-LICENSES.txt +296 -0
- package/README.md +13 -4
- package/api.mjs +0 -8
- package/bin/lawspec.mjs +114 -79
- package/build.json +99 -117
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- package/doctor.mjs +14 -4
- package/examples/native-payments/clojure/lawspec.json +1 -1
- package/examples/native-payments/csharp/lawspec.json +1 -1
- package/examples/native-payments/elixir/lawspec.json +1 -1
- package/examples/native-payments/erlang/lawspec.json +1 -1
- package/examples/native-payments/fsharp/lawspec.json +1 -1
- package/examples/native-payments/gleam/lawspec.json +1 -1
- package/examples/native-payments/go/lawspec.json +1 -1
- package/examples/native-payments/groovy/lawspec.json +1 -1
- package/examples/native-payments/haskell/lawspec.json +1 -1
- package/examples/native-payments/java/lawspec.json +1 -1
- package/examples/native-payments/javascript/lawspec.json +1 -1
- package/examples/native-payments/kotlin/lawspec.json +1 -1
- package/examples/native-payments/prolog/lawspec.json +20 -0
- package/examples/native-payments/prolog/src/domain/payments.pl +23 -0
- package/examples/native-payments/prolog/tests/domain/payment_generators.pl +17 -0
- package/examples/native-payments/python/lawspec.json +1 -1
- package/examples/native-payments/rust/lawspec.json +1 -1
- package/examples/native-payments/scala/lawspec.json +1 -1
- package/examples/native-payments/swift/lawspec.json +1 -1
- package/examples/native-payments/typescript/lawspec.json +1 -1
- package/examples/packages/orders/lawspec.json +1 -1
- package/examples/packages/orders/orders.lawspec +27 -25
- package/examples/packages/shop-domain/src/domain.lawspec +15 -14
- package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-1/src/rates.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/rates.lawspec +1 -0
- package/examples/rc1/authorization-snapshots.lawspec +24 -23
- package/examples/rc1/banner-filenames.lawspec +7 -6
- package/examples/rc1/bit-codec.lawspec +12 -11
- package/examples/rc1/bounded-witness-search.lawspec +52 -45
- package/examples/rc1/conflicting-requirements.lawspec +8 -7
- package/examples/rc1/constructive-witnesses.lawspec +40 -33
- package/examples/rc1/documentary-review.lawspec +9 -8
- package/examples/rc1/empty-domains.lawspec +16 -15
- package/examples/rc1/finite-integer-domains.lawspec +24 -23
- package/examples/rc1/law-metadata.lawspec +6 -5
- package/examples/rc1/native-payments.lawspec +17 -16
- package/examples/rc1/nesting/rrr.lawspec +4 -3
- package/examples/rc1/nesting/rru.lawspec +7 -6
- package/examples/rc1/nesting/rur.lawspec +7 -6
- package/examples/rc1/nesting/ruu.lawspec +10 -9
- package/examples/rc1/nesting/urr.lawspec +7 -6
- package/examples/rc1/nesting/uru.lawspec +10 -9
- package/examples/rc1/nesting/uur.lawspec +10 -9
- package/examples/rc1/nesting/uuu.lawspec +13 -12
- package/examples/rc1/order-workflow.lawspec +18 -17
- package/examples/rc1/parcel-measurements.lawspec +14 -13
- package/examples/rc1/picture-records.lawspec +6 -5
- package/examples/rc1/picture-tuples.lawspec +6 -5
- package/examples/rc1/record-payloads.lawspec +12 -11
- package/examples/rc1/recursive-records.lawspec +11 -10
- package/examples/rc1/refund-conformance.lawspec +7 -6
- package/examples/rc1/refund-policy.lawspec +15 -14
- package/examples/rc1/requirement-composition.lawspec +26 -25
- package/examples/rc1/structural-records.lawspec +13 -12
- package/examples/rc1-authoring.lawspec +6 -5
- 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 +19 -18
- 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 +68 -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 +7 -6
- 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 +161 -160
- 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 +7 -7
- package/explain.mjs +6 -4
- package/expression-presentation.mjs +8 -8
- package/files.mjs +1 -1
- package/index.d.ts +10 -528
- package/launcher.mjs +9 -2
- package/lsp.mjs +10 -6
- package/native-evidence.mjs +25 -12
- package/native-examples.mjs +3 -3
- package/package.json +2 -1
- package/starter-rc1.lawspec +6 -5
- package/starter.lawspec +16 -15
- package/templates.mjs +88 -5
- package/test-command.mjs +40 -4
- package/migrate.mjs +0 -135
- package/migration-bindings.mjs +0 -86
- package/migration-cases.mjs +0 -45
- package/migration-collections.mjs +0 -54
- package/migration-correspondence.mjs +0 -275
- package/migration-generation.mjs +0 -99
- package/migration-laws.mjs +0 -102
- package/migration-records.mjs +0 -166
- package/migration-source.mjs +0 -247
- package/migration-write.mjs +0 -156
|
@@ -5,13 +5,13 @@ unit example.composition
|
|
|
5
5
|
-- the spec handlers together. The native handlers share a Store: each case
|
|
6
6
|
-- opens one, and every native handler of the case is made with it.
|
|
7
7
|
|
|
8
|
-
type Problem is | UnknownLog | EmptyRecord end
|
|
8
|
+
type Problem is one of | UnknownLog | EmptyRecord end type
|
|
9
|
+
|
|
10
|
+
type Log is a record{
|
|
9
11
|
|
|
10
|
-
type Log is
|
|
11
|
-
Log
|
|
12
12
|
records :: List Text
|
|
13
|
-
appends :: Int64
|
|
14
|
-
end
|
|
13
|
+
appends :: Int64}
|
|
14
|
+
end type
|
|
15
15
|
|
|
16
16
|
handle Store
|
|
17
17
|
|
|
@@ -19,92 +19,96 @@ openStore :: Unit -> Store
|
|
|
19
19
|
closeStore :: Store -> Unit
|
|
20
20
|
|
|
21
21
|
resource Store is
|
|
22
|
-
acquire is openStore unitValue end
|
|
23
|
-
release store is closeStore store end
|
|
24
|
-
end
|
|
22
|
+
acquire is openStore unitValue end acquire
|
|
23
|
+
release store is closeStore store end release
|
|
24
|
+
end resource
|
|
25
25
|
|
|
26
26
|
ability Logs with Store is
|
|
27
27
|
create :: Text -> Unit
|
|
28
28
|
append :: Text -> Text -> Int64 fails with Problem
|
|
29
29
|
laws
|
|
30
|
-
law
|
|
31
|
-
definition
|
|
32
|
-
end
|
|
33
|
-
law
|
|
34
|
-
definition
|
|
35
|
-
end
|
|
36
|
-
end
|
|
30
|
+
law "|a new log takes its first record at offset zero| is
|
|
31
|
+
definition : for all (t :: Text) (r :: Text where r != "") => (create t; append t r) = 0 end for all end definition
|
|
32
|
+
end law
|
|
33
|
+
law "|an unknown log refuses records| is
|
|
34
|
+
definition : for all (t :: Text) (r :: Text) => append t r fails with UnknownLog end for all end definition
|
|
35
|
+
end law
|
|
36
|
+
end laws
|
|
37
|
+
end ability
|
|
37
38
|
|
|
38
39
|
ability Reader with Store is
|
|
39
40
|
size :: Text -> Maybe Int64
|
|
40
41
|
laws
|
|
41
|
-
law
|
|
42
|
-
definition
|
|
43
|
-
end
|
|
44
|
-
end
|
|
42
|
+
law "|an unknown log has no size| is
|
|
43
|
+
definition : for all (t :: Text) => size t = Nothing end for all end definition
|
|
44
|
+
end law
|
|
45
|
+
end laws
|
|
46
|
+
end ability
|
|
45
47
|
|
|
46
48
|
-- A client over Logs: it keeps the offset of its last write.
|
|
47
49
|
ability Writer with Store is
|
|
48
50
|
write :: Text -> Text -> Bool
|
|
49
51
|
lastOffset :: Maybe Int64
|
|
50
52
|
laws
|
|
51
|
-
law
|
|
52
|
-
definition
|
|
53
|
-
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
53
|
+
law "|a write to a new log is read back| is
|
|
54
|
+
definition :
|
|
55
|
+
for all (t :: Text) (r :: Text where r != "") => (create t; write t r; size t) = Just 1 end for all
|
|
56
|
+
end definition
|
|
57
|
+
end law
|
|
58
|
+
end laws
|
|
59
|
+
end ability
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
function empty (u :: Unit) -> KeyVal Text Log is prelude.keyValOf [] end function
|
|
59
62
|
|
|
60
63
|
-- One state for both abilities. It starts from a computed value, and the
|
|
61
64
|
-- clause for append updates it in one branch only.
|
|
62
65
|
handler store for Logs, Reader with state logs :: KeyVal Text Log start empty unitValue is
|
|
63
|
-
create t is ~logs := prelude.put t (Log [] 0) logs; unitValue end
|
|
64
|
-
append t r is
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if r
|
|
66
|
+
operation create t is ~logs := prelude.put t (Log record{ records = [] , appends = 0}) logs; unitValue end operation
|
|
67
|
+
operation append t r is
|
|
68
|
+
first matching case of prelude.lookup t logs :
|
|
69
|
+
when Nothing then raise UnknownLog
|
|
70
|
+
when Just log then
|
|
71
|
+
if r = "" then raise EmptyRecord else
|
|
69
72
|
(~logs := prelude.put t (log with records = Cons r log.records, appends = prelude.saturating (log.appends + 1)) logs;
|
|
70
|
-
log.appends)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
size t is
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
73
|
+
log.appends) end if
|
|
74
|
+
end case
|
|
75
|
+
end operation
|
|
76
|
+
operation size t is
|
|
77
|
+
first matching case of prelude.lookup t logs :
|
|
78
|
+
when Nothing then Nothing
|
|
79
|
+
when Just log then Just log.appends
|
|
80
|
+
end case
|
|
81
|
+
end operation
|
|
82
|
+
end handler
|
|
80
83
|
|
|
81
84
|
-- A clause may be a definition that gives Pair result state: `op by f`.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
end
|
|
87
|
-
end
|
|
85
|
+
procedure writeTo (t :: Text) (r :: Text) (last :: Maybe Int64) -> Pair Bool (Maybe Int64) uses Logs is
|
|
86
|
+
first matching case of prelude.attempt (append t r) :
|
|
87
|
+
when Left problem then Pair false last
|
|
88
|
+
when Right offset then Pair true (Just offset)
|
|
89
|
+
end case
|
|
90
|
+
end procedure
|
|
88
91
|
|
|
89
|
-
|
|
92
|
+
function lastOf (last :: Maybe Int64) -> Pair (Maybe Int64) (Maybe Int64) is Pair last last end function
|
|
90
93
|
|
|
91
94
|
handler logWriter for Writer with state last :: Maybe Int64 start Nothing is
|
|
92
|
-
write by writeTo
|
|
93
|
-
lastOffset by lastOf
|
|
94
|
-
end
|
|
95
|
+
operation write by writeTo end operation
|
|
96
|
+
operation lastOffset by lastOf end operation
|
|
97
|
+
end handler
|
|
95
98
|
|
|
96
99
|
-- The reference composition: every ability answered by spec handlers.
|
|
97
|
-
handlers reference is store, logWriter end
|
|
98
|
-
|
|
99
|
-
law
|
|
100
|
-
definition
|
|
101
|
-
|
|
102
|
-
(create t; append t a; append t b; size t) = Just 2
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
law
|
|
107
|
-
definition
|
|
108
|
-
|
|
109
|
-
end
|
|
110
|
-
end
|
|
100
|
+
handlers reference is store, logWriter end handlers
|
|
101
|
+
|
|
102
|
+
law "|sizes count records| is
|
|
103
|
+
definition :
|
|
104
|
+
for all (t :: Text) (a :: Text where a != "") (b :: Text where b != "") =>
|
|
105
|
+
(create t; append t a; append t b; size t) = Just 2 end for all
|
|
106
|
+
end definition
|
|
107
|
+
end law
|
|
108
|
+
|
|
109
|
+
law "|a writer remembers where it wrote| is
|
|
110
|
+
definition :
|
|
111
|
+
for all (t :: Text) (r :: Text where r != "") => (create t; write t r; lastOffset) = Just 0 end for all
|
|
112
|
+
end definition
|
|
113
|
+
end law
|
|
114
|
+
end unit
|
|
@@ -5,7 +5,7 @@ unit example.concurrent
|
|
|
5
5
|
-- runs the commands in sequence and at the same time, and every history
|
|
6
6
|
-- must be linearizable. Sets and maps are checked key by key.
|
|
7
7
|
|
|
8
|
-
type WorkQueue is
|
|
8
|
+
type WorkQueue is a record{ id :: Int32} end type
|
|
9
9
|
|
|
10
10
|
newQueue :: Unit -> WorkQueue
|
|
11
11
|
async offer :: WorkQueue -> Int32 -> Unit
|
|
@@ -17,23 +17,23 @@ model queue :: shared WorkQueue behaves like Queue Int32 is
|
|
|
17
17
|
offer as offer
|
|
18
18
|
poll as poll
|
|
19
19
|
queueSize as size
|
|
20
|
-
end
|
|
20
|
+
end model
|
|
21
21
|
|
|
22
|
-
type Tags is
|
|
22
|
+
type Tags is a record{ id :: Int32} end type
|
|
23
23
|
|
|
24
24
|
newTags :: Unit -> Tags
|
|
25
25
|
async tag :: Tags -> Int32 -> Bool
|
|
26
26
|
async untag :: Tags -> Int32 -> Bool
|
|
27
27
|
async tagged :: Tags -> Int32 -> Bool
|
|
28
28
|
|
|
29
|
-
model tags :: shared Tags behaves like
|
|
29
|
+
model tags :: shared Tags behaves like SortedSet Int32 is
|
|
30
30
|
start newTags
|
|
31
31
|
tag as add
|
|
32
32
|
untag as remove
|
|
33
33
|
tagged as contains
|
|
34
|
-
end
|
|
34
|
+
end model
|
|
35
35
|
|
|
36
|
-
type Cache is
|
|
36
|
+
type Cache is a record{ id :: Int32} end type
|
|
37
37
|
|
|
38
38
|
newCache :: Unit -> Cache
|
|
39
39
|
async store :: Cache -> Int8 -> Int64 -> Maybe Int64
|
|
@@ -45,4 +45,5 @@ model cache :: shared Cache behaves like KeyVal Int8 Int64 is
|
|
|
45
45
|
store as put
|
|
46
46
|
fetch as get
|
|
47
47
|
evict as remove
|
|
48
|
-
end
|
|
48
|
+
end model
|
|
49
|
+
end unit
|
|
@@ -5,17 +5,18 @@ unit example.consistency
|
|
|
5
5
|
-- that replica has seen, so callers see stale totals, and the total is the
|
|
6
6
|
-- sum of the replicas. Its histories are not linearizable, but once every
|
|
7
7
|
-- hit is done the total must count them all: it is eventually consistent.
|
|
8
|
-
type Views is
|
|
8
|
+
type Views is a record{ id :: Int32} end type
|
|
9
9
|
|
|
10
10
|
newViews :: Unit -> Views
|
|
11
11
|
hit :: Views -> Int64
|
|
12
12
|
total :: Views -> Int64
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
function modelHit (n :: Int64 where n >= 0 && n <= 1000000) -> Pair Int64 Int64 is Pair (n + 1) (n + 1) end function
|
|
15
15
|
|
|
16
16
|
model views :: shared Views by Int64 is
|
|
17
17
|
consistency eventual
|
|
18
18
|
start newViews ~ 0
|
|
19
19
|
hit ~ modelHit
|
|
20
20
|
abstract total
|
|
21
|
-
end
|
|
21
|
+
end model
|
|
22
|
+
end unit
|
|
@@ -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
|