TL;DR: combinators and GADTs allow to describe types in abstract enough a way that they can be converted into/from various serialization formats. Edit: the code is now available in its own repository on github, and on my opam repository under the name CConv. Optional interfaces to Yojson, Sexplib and Bencode are also provided.