~/bend-docscommunity

LAWS.bend open laws/TODOs

raw source on the hub · import hhefesto-wire@1.0.0.0/LAWS.bend as LAWS

Wire's laws: what a connection's bytes mean does not depend on how they come, and middlewares compose as functions do.

2 imports
import Base
import ./Wire.bend as W

Laws

law feed_cut provedin PROOF.bendsource · line 11 · raw

@bs:List<&2, U32> -> @rev:List<&2, U32> -> @+seen:U32 -> @cs:List<&2, U32> -> {0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.feed(0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.cut(bs, rev, seen), cs) == 0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.cut(List.append(&2, U32, bs, cs), rev, seen) : 0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Cut}

Where a head ends does not depend on how its bytes were cut into pieces: the bytes fed after a cut are the cut of all of them. So the server, which feeds each piece TCP gives it as it comes, reads what the bytes, whole, mean.

law head_then provedin PROOF.bendsource · line 21 · raw

@h:List<&2, U32> -> @bs:List<&2, U32> -> @whole:{0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.cut(h, [], 0) == 0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Head{h, []} : 0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Cut} -> {0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.cut(List.append(&2, U32, h, bs), [], 0) == 0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Head{h, bs} : 0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Cut}

A whole head is found whatever bytes follow it, and they are left as they are: on a kept-alive connection the next request's bytes, pipelined or not, are not touched by this one's reading.

law body_then provedin PROOF.bendsource · line 29 · raw

@body:List<&2, U32> -> @rest:List<&2, U32> -> {0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.split(List.length(&2, U32, body), List.append(&2, U32, body, rest)) == (body, rest) : Pair(List<&2, U32>, List<&2, U32>)}

The body is its Content-Length's bytes, and what follows it is the next request's, whatever it is.

law mid_id_left provedin PROOF.bendsource · line 36 · raw

@m:0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Mid -> @app:0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.App -> @r:0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Req -> {0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.mid.then(0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.mid.id, m, app, r) == m(app, r) : IO(0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Resp)}

Middlewares: the identity and composition, a monoid (on every application and request: functions are equal when they agree)

law mid_id_right provedin PROOF.bendsource · line 42 · raw

@m:0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Mid -> @app:0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.App -> @r:0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Req -> {0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.mid.then(m, 0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.mid.id, app, r) == m(app, r) : IO(0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Resp)}

law mid_assoc provedin PROOF.bendsource · line 48 · raw

@f:0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Mid -> @g:0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Mid -> @h:0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Mid -> @app:0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.App -> @r:0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Req -> {0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.mid.then(0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.mid.then(f, g), h, app, r) == 0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.mid.then(f, 0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.mid.then(g, h), app, r) : IO(0xb8e08f92b233e37463500e01c2e5b973/Wire.wr.Resp)}