Module Generic_core_desc.Con

module Con: sig .. end
Generic representation of variant constructors.

type ('a, 'v) arguments = 
| Product of 'a Product.t
| Record of ('a, 'v) Generic_core_desc.Fields.t
The arguments of a constructors are either a tuple or an inline record.
type ('t, 'v) desc = {
   name : string; (*
name of the constructor
*)
   args : ('t, 'v) arguments; (*
arguments of the constructor
*)
   embed : 't -> 'v; (*
applies the constructor to the arguments.
*)
   proj : 'v -> 't option; (*
tries to deconstruct that constructor
*)
}
Constructor description.

('t, 'v) desc describes one of the constructors of variant 'v of type 't.

Caveat.

A constructor C of (a * b) is treated differently as constructor C of a * b. We must therefore represent them differently: the first one with : { args = Product.p1 (Pair a b) ; ...} and the second one with: { args = Product.p2 a b ; ...}

Caution!

embed must not inspect its arguments either by pattern matching on them or by applying a function on them. embed should only apply the data constructor to its argument, for instance the embed function for the data-constructor Some : 'a -> 'a option is embed = fun x -> Some x.

val product : ('t, 'v) desc -> 't Product.t
type 'v con = 
| Con : ('t, 'v0) desc -> 'v0 con
Constructor. The type 't of the constructor arguments is hidden by existential quantification.
type 'v t = 'v con 
Synonym for convenience.
val name : 'v con -> string
val make : string ->
('a, 'b) arguments ->
('a -> 'b) -> ('b -> 'a option) -> 'b con
Builds a con using the corresponding field values
val c0 : string -> 'a -> 'a con
Builds a constant constructor. Example: c0 "None" None
val arity : 'a con -> int
The arity of a constructor is the number of its arguments. Caveat: C of int * bool has arity 2 whereas C of (int * bool) has arity 1: a single argument which is a pair.
type 'v conap = 
| Conap : ('a, 'v0) desc * 'a -> 'v0 conap
Constructor Application. A pair of a constructor and its arguments.
val conap : 'v con -> 'v -> 'v conap option
val con : 'v conap -> 'v con
Returns the constructor of a constructor application O(1).
val subterms_prod : 'v conap -> Product.dynprod
Returns the arguments of a constructor application as a dynamic product. O(1).
val subterms : 'v conap -> Ty.dyn list
Returns the arguments of a constructor application as a list of dynamic values. O(1).
module Build: sig .. end
Helper module for building the argument types.