package ppx_repr

  1. Overview
  2. Docs

A Plugin.t is a pair of functions that extend a representable type with specialised generic operations: one to supply the implementation of the specialistion, and one to supply its type.

For instance, the generic operation equal : 'a Repr.t -> 'a -> 'a -> equal could be packaged as the following plugin:

create
  ~intf:(fun loc t -> [%type: [%t t] -> [%t t] -> bool])
  ~impl:(fun loc t -> [%expr Repr.unstage (Repr.equal [%e t])])

That is:

  • given some type t, its equality function has type t -> t -> bool,
  • given a runtime representation of t, we can derive an equality function via Repr.equal.
type t
val create : ?type_name:[ `before | `after ] -> impl:(Ppxlib.location -> Ppxlib.expression -> Ppxlib.expression) -> intf:(Ppxlib.location -> Ppxlib.core_type -> Ppxlib.core_type) -> string -> t
val derive_str : t -> loc:Ppxlib.location -> type_name:string -> params:string list -> expr:Ppxlib.expression -> Ppxlib.structure_item
val derive_sig : t -> loc:Ppxlib.location -> type_name:string -> params:Ppxlib.core_type list -> ctyp:Ppxlib.core_type -> Ppxlib.signature_item
val defaults : t list

Default set of plugins, using the generic operations provided by Repr.

OCaml

Innovation. Community. Security.