A library of bidirectional binary format combinators.
This is mainly based on “Composing Bidirectional Programs Monadically”, which demonstrates an approach for defining data-dependent (i.e. monadic) codecs.
Simple image format:
open Bidi_combinators
type t = {
width : int;
height : int;
data : int32 array;
}
let width x = x.width
let height x = x.height
let data x = x.data
let format : t Format.value =
let open Format.Syntax in
let* width = width @= Format.int16_be
and+ height = height @= Format.int16_be in
let+ data = data @= Format.Array.repeat_len Format.int32_be (width * height) in
{ width; height; data }
More examples can be found in the examples directory.
- “Composing Bidirectional Programs Monadically” [doi:10.1007/978-3-030-17184-1_6]
- Towards monadic bidirectional serialization
- codec: Easy bidirectional serialization in Haskell [hackage:codec] [github:chpatrick/codec]
- tomland: Bidirectional TOML serialization [hackage:tomland] [github:kowainik/tomland]
- autodocodec: Self-documenting encoder and decoder [hackage:autodocodec] [github:NorfairKing/autodocodec]