Skip to content

Commit

Permalink
Standardize how to encode/decode multi-let expressions (#271)
Browse files Browse the repository at this point in the history
In #266 I forgot to specify how to
encode `let` expressions with multiple bindings.  This changes the encoding
to encode a `let` expression with multiple bindings as a single list with
three elements per binding.

This is not compatible with the previous encoding which would omit the type
annotation when absent instead of using `null`
  • Loading branch information
Gabriella439 committed Nov 13, 2018
1 parent 33cab24 commit ab9f13d
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions standard/binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -718,18 +718,12 @@ The `missing` keyword is also treated as another import type:

### `let` expressions

`let` expressions differ in their encoding depending on whether or not they have
a type annotation:
`let` expressions use three list elements per binding and also use a `null` to
represent the absence of a type annotation:


encode(a₀) = a₁ encode(b₀) = b₁
──────────────────────────────────────────────────
encode(let x = a₀ in b₀) = [ 25, "x", a₁, b₁ ]


encode(a₀) = a₁ encode(A₀) = A₁ encode(b₀) = b₁
───────────────────────────────────────────────────────────────
encode(let x : A₀ = a₀ in b₀) = [ 25, "x", A₁, a₁, b₁ ]
encode(A₀) = A₁ encode(a₀) = a₁ encode(b₀) = b₁ ... encode(z₀) = z₁
──────────────────────────────────────────────────────────────────────────────────────────
encode(let x : A₀ = a₀ let y = b₀ ... in z₀) = [ 25, "x", A₁, a₁, "y", null, b₁, ..., z₁ ]


### Type annotations
Expand Down Expand Up @@ -1308,14 +1302,9 @@ The decoding rules are the exact opposite of the encoding rules:
Decode a CBOR array beginning with a `25` as a `let` expression:


decode(a₁) = a₀ decode(b₁) = b₀
──────────────────────────────────────────────────
decode([ 25, "x", a₁, b₁ ]) = let x = a₀ in b₀


decode(a₁) = a₀ decode(A₁) = A₀ decode(b₁) = b₀
───────────────────────────────────────────────────────────────
decode([ 25, "x", A₁, a₁, b₁ ]) = let x : A₀ = a₀ in b₀
decode(A₁) = A₀ decode(a₁) = a₀ decode(b₁) = b₀ ... decode(z₁) = z₀
──────────────────────────────────────────────────────────────────────────────────────────
decode([ 25, "x", A₁, a₁, "y", null, b₁, ..., z₁ ]) = let x : A₀ = a₀ let y = b₀ ... in z₀


### Type annotations
Expand Down

0 comments on commit ab9f13d

Please sign in to comment.