package typerep

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

runtime type representations

type _ t =
  1. | Int : int t
  2. | Int32 : int32 t
  3. | Int64 : int64 t
  4. | Nativeint : nativeint t
  5. | Char : char t
  6. | Float : float t
  7. | String : string t
  8. | Bytes : bytes t
  9. | Bool : bool t
  10. | Unit : unit t
  11. | Option : 'a t -> 'a option t
  12. | List : 'a t -> 'a list t
  13. | Array : 'a t -> 'a array t
  14. | Lazy : 'a t -> 'a lazy_t t
  15. | Ref : 'a t -> 'a ref t
  16. | Function : ('dom t * 'rng t) -> ('dom -> 'rng) t
  17. | Tuple : 'a Typerep.Tuple.t -> 'a t
  18. | Record : 'a Typerep.Record.t -> 'a t
  19. | Variant : 'a Typerep.Variant.t -> 'a t
    (*

    The Named constructor both allows for custom implementations of generics based on name and provides a way to represent recursive types, the lazy part dealing with cycles

    *)
  20. | Named : ('a Typerep.Named.t * 'a t lazy_t option) -> 'a t
type packed =
  1. | T : 'a t -> packed
module Named : sig ... end
module Tuple : sig ... end
include Variant_and_record_intf.S with type 'a t := 'a t
include sig ... end
module Tag_internal : sig ... end
module Tag : sig ... end

Witness of a tag, that is an item in a variant type, also called an "applied variant Constructor"

module Variant_internal : sig ... end
module Variant : sig ... end
module Field_internal : sig ... end
module Field : sig ... end

Witness of a field, that is an item in a record type. The first parameter is the record type, the second is the type of the field. Example:

module Record_internal : sig ... end
module Record : sig ... end
val same : _ t -> _ t -> bool

same t t' will return a proof a equality if t and t' are the same type. One can think of two types being the same as two types whose values could be for example put in a list together. It is worth noting that this function *does not* operate compatiblity diffs between two different types with the same structure. Example:

module M1 = struct
  type t = {
    a : int;
    b : float;
  } [@@deriving typerep]
end
module M2 = struct
  type t = {
    a : int;
    b : float;
  } [@@deriving typerep]
end

let _ = [%test_result:bool] ~expect:false (same M1.typerep_of_t M2.typerep_of_t)

type a = int [@@deriving typerep]
type b = int [@@deriving typerep]

let _ = [%test_result:bool] ~expect:true (same typerep_of_a typerep_of_b)

This is meant to recover type equality hidden by existential constructors.

Basically this function does structural equality for everything except variant types, record types, and named types with no lazy definition exposed. This last case is about types that are defined [@@deriving typerep ~abstract].

val same_witness : 'a t -> 'b t -> ('a, 'b) Type_equal.t option
val same_witness_exn : 'a t -> 'b t -> ('a, 'b) Type_equal.t
val typename_of_t : 'a t -> 'a Typename.t
val head : 'a t -> 'a t

head ty is used to traverse the Named constructor. It might be used when one care to pattern match directly on the representation in a low level way rather than going through a full generic. head t is t if t is not of the form Named _