Module Acutis.Of_decodable

A functor that builds functions to render templates and construct type interfaces from decodable data.

Parameters

module _ : CONFIG
module D : DECODABLE

Signature

val apply : (D.t -> string) compiled -> D.t -> (string, message list) Stdlib.result

Apply data to a template. Ok str is the rendered output. Error str is an error message.

val interface : D.t -> interface compile_result

Compile a type interface from a generic format that can be represented with any decodable data. For example, if we use JSON, where assoc values are objects and seq values are arrays:

  • Simple types are represented by their names: "int", "float", "string", and "_".
  • Records are objects, e.g. {"a": "int", "b": "string"}.
  • Parameterized types and tagged record fields are arrays with two values, the name of the type and the parameter, e.g. ["nullable", "int"].
  • Tuples, enumerations, and unions are parameterized types with any number of values for their cases, e.g. ["enum", false, true].

The parameterized type names are:

  • dict
  • enum
  • enum_open
  • list
  • nullable
  • tag
  • tuple
  • union
  • union_open