Module Gist.Abstract

Abstract type representations.

Abstract types

module Version : sig ... end

Versioned representations.

type 'a t

The type for representing an abstract type of type 'a.

val make : ?version_index:('a -> int) -> 'a Version.t list -> 'a t

make versions is an abstract type with public representations versions.The zero-based version_index function attributes versions from the versions list to values (default to Fun.const (List.length versions - 1)).

val is_opaque : 'a t -> bool

is_opaque a is true if and only if no representations are exposed by a. This means that Iarray.length (versions a) = 0.

val versions : 'a t -> 'a Version.t iarray

versions a is the list of public representations of a (if any).

Warning. In general versions may be partial views over values of type v. So generic processors should not assume that any version can deal with a given v, version a v will though.

val version_index : 'a t -> 'a -> int

version_index a v is the index of the version attributed to v in the array versions a.

  • raises Invalid_argument

    if is_opaque a is true.

val version : 'v t -> 'v -> 'v Version.t

version a v is Iarray.get (versions a) (version_index a v).

  • raises Invalid_argument

    if is_opaque a is true.

val find_version : Version.name -> 'a t -> 'a Version.t option

find_version n a is the version named n of a if any.

Gist processor helpers

val check_non_opaque : 'a gist -> 'a t -> unit

check_non_opaque g a assumes a is g's expressions and raises Invalid_argument _ with an error message that mentions g's name if a is opaque.

val check_compatible_version_index : 'a gist -> 'a t -> 'a -> 'a -> int

compatible_value g a i0 i1 raises Invalid_argument _ with an error message that mentions g's name if version_index a v0 <> version_index a i1 or returns the version index otherwise. This is to check that a binary operation on two values v0 and v1 is using the same version.

val get_gist : 'a gist -> 'a t -> 'a -> 'a gist

get_gist g a v gets the gist for value v. This uses check_non_opaque before using version and Version.gist.

val get_binop_gist : 'a gist -> 'a t -> 'a -> 'a -> 'a gist

get_binop_gist g a v0 v1 gets a gist for a binary operation. This uses both check_non_opaque and check_compatible_version_index to return the gist of the version that v0 and v1 share.