Frama-C API - Datatype
A datatype provides useful values for types. It is a high-level API on top of module Type.
Type declarations
type 'a t = private {equal : 'a -> 'a -> bool;compare : 'a -> 'a -> int;hash : 'a -> int;copy : 'a -> 'a;pretty : Stdlib.Format.formatter -> 'a -> unit;mem_project : (Project_skeleton.t -> bool) -> 'a -> bool;
}Values associated to each datatype. Some others are provided directly in module Type.
module type Ty = sig ... endA type with its type value.
module type S_no_copy = sig ... endAll values associated to a datatype, excepted copy.
module type S = sig ... endAll values associated to a datatype.
Getters from a type value
val equal : 'a Type.t -> 'a -> 'a -> boolval compare : 'a Type.t -> 'a -> 'a -> intval hash : 'a Type.t -> 'a -> intval copy : 'a Type.t -> 'a -> 'aval pretty : 'a Type.t -> Stdlib.Format.formatter -> 'a -> unitval mem_project : 'a Type.t -> (Project_skeleton.t -> bool) -> 'a -> boolEasy builders
Must be used if you want to implement a required function by fun x -> x. Only useful for implementing rehash and copy.
Must be used for equal in order to implement it by compare x y = 0 (with your own compare function).
val never_any_project : (Project_skeleton.t -> bool) -> 'a -> boolMust be used for mem_project if values of your type does never contain any project.
Each values in these modules are undefined. The usual way to use it is: module X: Datatype.S = struct include Undefined type t = ... let reprs = ... let name = ... let mem_project = ... (* Usually, Datatype.never_any_project *) (* define only useful functions for this datatype *) end
module Serializable_undefined : UndefinedSame as Undefined, but the type is supposed to be marshallable by the standard OCaml way (in particular, no hash-consing or projects inside the type).
Generic builders
module type Make_input = sig ... endInput signature of Make and Make_with_collections. Values to implement in order to get a datatype. Feel free to use easy builders (see above) for easy implementation.
module type Set = sig ... endA standard OCaml set signature extended with datatype operations.
module type Map = sig ... endA standard OCaml map signature extended with datatype operations.
module type Hashtbl_with_descr = sig ... endMarshallable collectors with hashtbl-like interface.
module type Hashtbl = sig ... endA standard OCaml hashtbl signature extended with datatype operations.
module type S_with_hashtbl = sig ... endA datatype for a type t extended with predefined hashtbl over t.
module type S_with_set_and_map = sig ... endA datatype for a type t extended with predefined set and map over t.
module type S_with_collections = sig ... endA datatype for a type t extended with predefined set, map and hashtbl over t.
module Make_with_set_and_map (X : Make_input) : S_with_set_and_map with type t = X.tGeneric comparable datatype builder: functions equal and compare must not be undefined.
module With_set_and_map (X : S) : S_with_set_and_map with type t = X.tAdd sets and maps to an existing datatype, provided the equal and compare are not undefined.
module Make_with_hashtbl (X : Make_input) : S_with_hashtbl with type t = X.tGeneric comparable datatype builder: functions equal and hash must not be undefined.
module With_hashtbl (X : S) : S_with_hashtbl with type t = X.tAdd hashtables modules to an existing datatype, provided the equal and hash functions are not undefined.
module Make_with_collections (X : Make_input) : S_with_collections with type t = X.tGeneric comparable datatype builder: functions equal, compare and hash must not be undefined.
module With_collections (X : S) : S_with_collections with type t = X.tAdd sets, maps and hashtables modules to an existing datatype, provided the equal, compare and hash functions are not undefined.
Predefined datatype
module Unit : S_with_collections with type t = unitval unit : unit Type.tmodule Bool : S_with_collections with type t = boolval bool : bool Type.tmodule Int : S_with_collections with type t = intval int : int Type.tmodule Int32 : S_with_collections with type t = int32val int32 : int32 Type.tmodule Int64 : S_with_collections with type t = int64val int64 : int64 Type.tmodule Nativeint : S_with_collections with type t = nativeintval nativeint : nativeint Type.tmodule Float : S_with_collections with type t = floatval float : float Type.tmodule Char : S_with_collections with type t = charval char : char Type.tmodule String : S_with_collections with type t = stringval string : string Type.tval formatter : Stdlib.Format.formatter Type.tmodule Integer : S_with_collections with type t = Fc_internal_z.tval integer : Fc_internal_z.t Type.tmodule Rational : S_with_collections with type t = Q.tval rational : Rational.t Type.tGeneric functors for polymorphic types
module type Polymorphic = sig ... endOutput signature of Polymorphic.
module Polymorphic (P : sig ... end) : Polymorphic with type 'a poly = 'a P.tFunctor for polymorphic types with only 1 type variable.
module type Polymorphic2 = sig ... endOutput signature of Polymorphic2.
module Polymorphic2 (P : sig ... end) : Polymorphic2 with type ('a, 'b) poly = ('a, 'b) P.tFunctor for polymorphic types with 2 type variables.
module type Polymorphic3 = sig ... endOutput signature of Polymorphic3.
module Polymorphic3 (P : sig ... end) : Polymorphic3 with type ('a, 'b, 'c) poly = ('a, 'b, 'c) P.tFunctor for polymorphic types with 3 type variables.
module type Polymorphic4 = sig ... endOutput signature of Polymorphic4.
module Polymorphic4 (P : sig ... end) : Polymorphic4 with type ('a, 'b, 'c, 'd) poly = ('a, 'b, 'c, 'd) P.tFunctor for polymorphic types with 4 type variables.
Predefined functors for polymorphic types
module Poly_pair : Polymorphic2 with type ('a, 'b) poly = 'a * 'bmodule Pair_with_collections (T1 : S) (T2 : S) : S_with_collections with type t = T1.t * T2.tmodule Poly_ref : Polymorphic with type 'a poly = 'a Stdlib.refmodule Poly_option : Polymorphic with type 'a poly = 'a optionmodule Option_with_collections (T : S) : S_with_collections with type t = T.t optionmodule Poly_list : Polymorphic with type 'a poly = 'a listmodule List_with_collections (T : S) : S_with_collections with type t = T.t listmodule Poly_array : Polymorphic with type 'a poly = 'a arraymodule Array_with_collections (T : S) : S_with_collections with type t = T.t arraymodule Poly_queue : Polymorphic with type 'a poly = 'a Stdlib.Queue.toptlabel_func lab dft ty1 ty2 is equivalent to func ~label:(lab, Some dft) ty1 ty2
val func2 : ?label1:(string * (unit -> 'a) option) -> 'a Type.t -> ?label2:(string * (unit -> 'b) option) -> 'b Type.t -> 'c Type.t -> ('a -> 'b -> 'c) Type.tval func3 : ?label1:(string * (unit -> 'a) option) -> 'a Type.t -> ?label2:(string * (unit -> 'b) option) -> 'b Type.t -> ?label3:(string * (unit -> 'c) option) -> 'c Type.t -> 'd Type.t -> ('a -> 'b -> 'c -> 'd) Type.tmodule type Sub_caml_weak_hashtbl = sig ... endmodule Caml_weak_hashtbl (D : S) : sig ... end