Module Gist.Variant

Operating on variants.

Variant cases

type 'v case = 'v product

The type for representing variant cases of a variant of type 'v. The Product.name is the constructor name.

Variants

type 'a gist := 'a t
type 'v t = 'v variant

The type for representing variants of type 'v.

val make : ?meta:'v Meta.t -> string -> ('v -> 'v case) -> 'v case list -> 'v variant

v type_name project cases is a variant with type name type_name with deconstructor project and case enumeration cases.

val meta : 'v variant -> 'v Meta.t

meta v is the metadata of v.

val type_name : 'v variant -> type_name

type_name v is the type name of v.

val project : 'v variant -> 'v -> 'v case

project v is the projection function (case selector) of v.

val cases : 'v variant -> 'v case list

cases v are the variant's cases.

Stdlib variants as variants

The sum type has specializations for these variants. You should like use that if appropriate in your descriptions, see sums. Consumers of the representation can always generalize with Sum.to_variant which invokes these functions.

val of_option : ?meta:'a option Meta.t -> 'a gist -> 'a option variant

of_option represents options of the given representation type as a variant.

val of_either : ?meta:('a, 'b) Stdlib.Either.t Meta.t -> 'a gist -> 'b gist -> ('a, 'b) Stdlib.Either.t variant

of_option represents eithers of the given representation type as a variant.

val of_result : ?meta:('a, 'b) Stdlib.result Meta.t -> 'a gist -> 'b gist -> ('a, 'b) Stdlib.result variant

of_result represents results of the given representation types as a variant.

val of_list : ?meta:'a list Meta.t -> 'a gist -> 'a list variant

of_list represents lists of the given representation type as a variant.