module Type:Type value. A type value is a value representing a static ML monomorphic type.sig
..end
type 'a
t
ty
,
a value of type ty t
dynamically represents the type ty
. Such a value
is called a type value and should be unique for each static monomorphic
type.type
precedence =
| |
Basic |
| |
Call |
| |
Couple |
| |
List |
| |
NoPar |
Type.par
below.val par : precedence ->
precedence -> Format.formatter -> (Format.formatter -> unit) -> unit
par context myself fmt pp
is used to put parenthesis around the verbatim
prints by pp
according to the precedence myself
of the verbatim and to
the precedence context
of the caller of the pretty printer. fmt
is the
output formatter.
The typical use is the following:
let pretty_print p_caller fmt x =
let pp fmt = Format.fprintf "..." ... x ... in
let myself = Call in
par p_caller Call fmt pp
exception AlreadyExists of string
val register : name:string ->
value_name:string option ->
?pp:(precedence -> Format.formatter -> 'a -> unit) ->
?varname:('a -> string) -> 'a -> 'a t
register ~name ~value_name abstract pp repr
registers a new type
value from a value repr
representing this type.repr
should not be a polymorphic value. For registering
polymorphic types, use one of the dedicated functors. See module type
Type.POLYMORPHIC
.name
is a string representing the ML type
(e.g. "int" or "int -> bool")value_name = Some s
, then s
is a string denoting the type value
itself (e.g. "Type.int" or "Type.func Type.int Type.bool").value_name = None
, then the type is a dynamically-registered
type. In such a case, function Type.get_dynamic
may be used.pp
is a pretty printer for values of this type value. In this pretty
printer, each '@' must be preceded by another: '@@'.varname
is the prefix for the generated variable names of this
type value (no generable variable by default).AlreadyExists
if the given name is already used by another
type.val name : 'a t -> string
val pp_value_name : 'a t -> precedence -> Format.formatter -> unit
val register_pp : 'a t -> (precedence -> Format.formatter -> 'a -> unit) -> unit
register_pp ty pp
sets the pretty printer of ty
with pp
.exception NoPrinter of string
val pp : 'a t -> precedence -> Format.formatter -> 'a -> unit
pp ty fmt v
prints v
on fmt
according to the printer
registered for the type value ty
.
This function must be called from other pretty printers.
However, the printed verbatim contains formatting materials and so should
not be used for a direct output. Consider to use Type.use_pp
instead.NoPrinter
if there is no printer registered for ty
.val varname : 'a t -> ('a -> string) option
varname
of
Type.register
). Return None if there is no known prefix.val use_pp : 'a t -> Format.formatter -> 'a -> unit
use_pp ty fmt v
prints v
on fmt
according to the printer
registered for the type value ty
and to the formatting materials that
it contains.NoPrinter
if there is no printer registered for ty
.exception Not_dynamic of string
type
ty
val get_dynamic : string -> ty t
Not_dynamic
if no dynamic type value was registered with this
name.val is_dynamic : 'a t -> bool
val equal : 'a t -> 'b t -> bool
val compare : 'a t -> 'b t -> int
val hash : 'a t -> int
val unit : unit t
val bool : bool t
bool
.val int : int t
int
.val int32 : int32 t
in32t
.val int64 : int64 t
int64
.val nativeint : nativeint t
nativeint
.val float : float t
float
.val char : char t
char
.val string : string t
string
.val formatter : Format.formatter t
Format.formatter
.val no_pp : precedence -> Format.formatter -> 'a -> unit
Assert_failure
if fully applied.module type POLYMORPHIC =sig
..end
module Polymorphic:functor (
D
:
sig
val name :'a Type.t -> string
How to build a name for each monomorphic instance of the type value from the underlying type.
val value_name :string
The name of the built module.
type'a
tStatic polymorphic type corresponding to its dynamic counterpart to register.
val repr :'a -> 'a t
How to make the representant of each monomorphic instance of the polymorphic type value from an underlying representant.
val pp :(Type.precedence -> Format.formatter -> 'a -> unit) ->
Type.precedence -> Format.formatter -> 'a t -> unitHow to pretty print values with the help of a pretty printer for the underlying type. Useno_pp
if you don't want to register a pretty printer.
end
) ->
POLYMORPHIC
with type 'a poly = 'a D.t
module type POLYMORPHIC2 =sig
..end
POLYMORPHIC
for types with two type variables.
module Polymorphic2:functor (
D
:
sig
val name :'a Type.t -> 'b Type.t -> string
val value_name :string
type('a, 'b)
tval repr :'a -> 'b -> ('a, 'b) t
val pp :(Type.precedence -> Format.formatter -> 'a -> unit) ->
(Type.precedence -> Format.formatter -> 'b -> unit) ->
Type.precedence -> Format.formatter -> ('a, 'b) t -> unitend
) ->
POLYMORPHIC2
with type ('a, 'b) poly = ('a, 'b) D.t
module Ref:POLYMORPHIC
with type 'a poly = 'a ref
val t_ref : 'a t -> 'a Pervasives.ref t
Parameters.instantiate
.module Option:POLYMORPHIC
with type 'a poly = 'a option
val option : 'a t -> 'a option t
Parameters.instantiate
.module List:POLYMORPHIC
with type 'a poly = 'a list
val list : 'a t -> 'a list t
List.instantiate
.module Couple:POLYMORPHIC2
with type ('a, 'b) poly = 'a * 'b
val couple : 'a t -> 'b t -> ('a * 'b) t
Couple.instantiate
.module Function:sig
..end
Type.POLYMORPHIC2
with possibility to specify a label for
the function parameter.
val func : ?label:string * (unit -> 'a) option ->
'a t -> 'b t -> ('a -> 'b) t
val optlabel_func : string -> (unit -> 'a) -> 'a t -> 'b t -> ('a -> 'b) t
optlabel_func lab dft ty1 ty2
is an alias for
func ~label:(lab, Some dft) ty1 ty2
module StringTbl:sig
..end
module TyTbl:sig
..end
module Binding:sig
..end
val no_obj : unit -> unit