Module Generic_core.Desc_fun

module Desc_fun: Generic_core_desc_fun
Computing the low level description of types.

type desc_fun = {
   f : 'a. 'a Ty.ty -> 'a Desc.t;
}
Type of the generic view: a desc_fun takes a type witness 'a ty and computes the description 'a desc
val view : 'a Ty.ty -> 'a Desc.t
Computes the generic view.
Raises Type_pattern_match_failure if the type doesn't have a view yet. You can use Generic_core_desc_fun.ext to extend view to cover those cases.
val ext : 'a Ty.pat -> desc_fun -> unit
ext pattern new_case extends desc with a new_case corresponding to the types that match pattern.
Raises Type_pattern_overwrite when trying to extend desc with a case that is already covered.

Extensible variants

Since extensible variants are types that can be extended after being declared, their description must necessarily be extensible as well. Therefore, to define the generic view for an extensible variant, we will first declare it with Generic_core_desc_fun.ext_register, then add its constructors one by one using Generic_core_desc_fun.ext_add_con. The functions ext_{conap,iter,fold} all act on extensible variants and raise Invalid_argument in case the type isn't extensible.
val ext_register : 'a Ty.ty -> string -> unit
Extensible variants are declared with this function.
Raises Pattern_overwrite the type already has a desc view.
val ext_add_con : 'a Ty.ty -> Desc.Ext.con -> unit
Adds a constructor to an extensible variant.
val ext_conap : 'a Ty.ty -> 'a -> 'a Desc.Con.conap
Computes the constructor application view for a value of an extensible variant.
Raises
val ext_iter : 'a Ty.ty -> ('a Desc.Con.t -> unit) -> unit
ext_iter t f executes f on each constructor registered with the extensible variant witnessed by t.
Raises
val ext_fold : 'a Ty.ty -> ('a Desc.Con.t -> 'b -> 'b) -> 'b -> 'b
ext_fold t is similar to List.fold_right executed on the list of constructors of the extensible variant witnessed by t.
Raises