Safe Haskell | Safe-Inferred |
---|---|

Language | Haskell2010 |

Cardano.Ledger.Binary.Coders provides tools for writing `EncCBOR`

and `DecCBOR`

instances (see module `Binary`

) in an intuitive way that mirrors the way one
constructs values of a particular type. Advantages include:

- Book-keeping details neccesary to write correct instances are hidden from the user.
- Inverse
`EncCBOR`

and`DecCBOR`

instances have visually similar definitions. - Advanced instances involving sparse-encoding, compact-representation, and
`Annotator`

instances are also supported.

A Guide to Visual inspection of Duality in Encode and Decode

`(Sum c)`

and`(SumD c)`

are duals`(Rec c)`

and`(RecD c)`

are duals`(Keyed c)`

and`(KeyedD c)`

are duals`(OmitC x)`

and`(Emit x)`

are duals`(Omit p ..)`

and`(Emit x)`

are duals if (p x) is True`(To x)`

and`(From)`

are duals if (x::T) and (forall (y::T). isRight (roundTrip y))`(E enc x)`

and`(D dec)`

are duals if (forall x . isRight (roundTrip' enc dec x))`(f !> x)`

and`(g <! y)`

are duals if (f and g are duals) and (x and y are duals)

Duality properties of `(Summands name decodeT)`

and ```
(SparseKeyed name (init::T) pick
required)
```

also exist but are harder to describe succinctly.