module Ext:sig..end
We define an abstract type 'a extensible to describe
the type 'a with the following operations:
type con = {
|
con : |
('a0,...'an) t is
described by a value of type con which is a partial
polymorphic function that computes the constructor
representation for any closed type expression
(s0,...,sn) t (without any type variable).
Thus the con function may only be called on the witnesses
of type (s0,...sn) t ty.
This design supports GADTs by default.
type cons
type 'a extensible = {
|
name : |
|
ty : |
|
cons : |
type'at ='a extensible
val create : unit -> consval add_con : 'a extensible -> con -> unitadd_con ext c adds c to the constructors of
extensible type described by extval fold : 'a extensible ->
('a Generic_core_desc.Con.t -> 'b -> 'b) -> 'b -> 'bfold ext computes List.foldr on the constructor list.val iter : 'a extensible ->
('a Generic_core_desc.Con.t -> unit) -> unitval con_list : 'a extensible -> 'a Generic_core_desc.Con.t listval con : 'a extensible -> 'a -> 'a Generic_core_desc.Con.tcon ext xInvalid_argument if the type is not extensible.Not_found if the constructor hasn't been added previously.xval conap : 'a extensible -> 'a -> 'a Generic_core_desc.Con.conapInvalid_argument if the type is not extensible.Not_found if the constructor hasn't been added previously.val fix : 'a extensible -> 'a -> 'a
umarshall (marshall x) <> x
In particular pattern matching the deserialized value
doesn't work as expected. fix fixes that: when
given a deserialized value, it returns a value
structurally equal to the one that was serialized:
fix (unmarshall (marshall x)) = x
In details, when an extensible value has been
deserialized, it's memory representation will be
different from that of the value before it was
serialized. This is because constructors of extensible
variants are implemented as object blocks (same as OCaml
objects), and they get assigned a unique identifier when
created. fix ext x will replace the constructor
of x with the original constructor object that is
stored in the 'a extensible datastructure ext.
Raises
Invalid_argument if the type is not extensible.Not_found if the constructor hasn't been added
previously.