Fun.GenericGeneric functions.
See the generic function template to write your own.
module Fmt : sig ... endCustom formatter key.
val pp : 'a Type.Gist.t -> Stdlib.Format.formatter -> 'a -> unitpp g ppf v formats v as described by g on ppf with a pseudo OCaml syntax similar to what you would see in the toplevel. The function can be selectively overriden on a gist with the Fmt metadata key. Fields whose Type.Gist.Meta.Ignore is true are not printed.
module Equal : sig ... endCustom equality key.
val equal : 'a Type.Gist.t -> 'a -> 'a -> boolequal g v0 v1 determines the equality of values v0 and v1 as described by g. The function can be selectively overriden on a gist with the Equal metadata key. Fields whose Type.Gist.Meta.Ignore is true are ignored (are always equal).
The function raises Invalid_argument on functional values and abstract types without representation; you can ignore them by using Equal.ignore for their Equal key.
module Compare : sig ... endCustom comparison key.
val compare : 'a Type.Gist.t -> 'a -> 'a -> intcompare g v0 v1 compares values v0 and v1 as described by g. The function can be selectively overriden on a gist with the Compare metadata key. Fields whose Type.Gist.Meta.Ignore is true are ignored (are always equal).
The function raises Invalid_argument on function values and abstract types without representation; you can ignore them by using Compare.ignore for their Compare key.
module Random : sig ... endCustom random generator and random sizing keys.
val random :
'a Type.Gist.t ->
?size:int ->
?state:Stdlib.Random.State.t ->
unit ->
'arandom g ~state () generates a random value described by g. state is the random state to use, defaults to Random.get_state ().
FIXME do something with Type.Gist.Meta.Ignore.
size is an indicative strictly positive, size factor to let users control an upper bound on the size and complexity of generated values. It should be used by generators to proportionally bound the length of sequences or the number of nodes in trees. It can be altered by gists via the Random.Size key.
The function raises Invalid_argument on functional values (may be lifted in the future) and abstract types without representation; you can represent them by using a suitable Random.Gen.const constant value for the Random.Gen key.
module Unmagic : sig ... endCustom unmagic key.
val unmagic : 'a Type.Gist.t -> 'b -> ('a, string) Stdlib.resultunmagic g v is Ok v if the memory layout of v is compatible with g.
Note. At the moment a few things are unsupported: bigarrays, functional values.
val safer_unmarshal :
'a Type.Gist.t ->
string ->
int ->
('a, string) Stdlib.resultsafer_unmarshal g s pos is unmagic g (Marshall.from_string s pos).