@@ -49,6 +49,15 @@ let fresh_type_maker type_decl =
4949 bound := newvar :: ! bound;
5050 Typ. var newvar
5151
52+ (* * [pp_type_of_decl decl] returns type for [pp_xxx] where xxx is the type name.
53+ For example, for [type ('a, 'b) map] it produces
54+ [(formatter -> 'a -> unit) -> (formatter -> 'b -> unit) -> formatter -> ('a, 'b) map -> unit].
55+ For GADTs, the optional parameter [refined_param_pos] specifies the index of refined
56+ parameters i.e., [0] for ['a] in [type ('a, 'b) map] and [1] for ['b].
57+ If present, the type parameter is rendered as any [type _] type, to mark the type parameter is
58+ actually ignored. For example, for [type ('a, 'b) map] with [refined_param_pos=[1]], it produces
59+ [(formatter -> 'a -> unit) -> (formatter -> _ -> unit) -> formatter -> ('a, 'b) map -> unit]
60+ (see [_] instead of ['b] in the type for the second argument). *)
5261let pp_type_of_decl ?(refined_param_pos =[] ) type_decl =
5362 let loc = type_decl.ptype_loc in
5463 let typ = Ppx_deriving. core_type_of_type_decl type_decl in
@@ -60,6 +69,8 @@ let pp_type_of_decl ?(refined_param_pos=[]) type_decl =
6069 type_decl
6170 [% type : Ppx_deriving_runtime.Format. formatter -> [% t typ] -> Ppx_deriving_runtime. unit ]
6271
72+ (* * Same as [pp_type_of_decl] but type parameters are rendered as locally abstract types rather than
73+ type variables. *)
6374let pp_type_of_decl_newtype ?(refined_param_pos =[] ) type_decl =
6475 let loc = type_decl.ptype_loc in
6576 let typ = Ppx_deriving. core_type_of_type_decl_with_newtype type_decl in
@@ -70,6 +81,8 @@ let pp_type_of_decl_newtype ?(refined_param_pos=[]) type_decl =
7081 type_decl
7182 [% type : Ppx_deriving_runtime.Format. formatter -> [% t typ] -> Ppx_deriving_runtime. unit ]
7283
84+ (* * [show_type_of_decl decl] returns type for [show_xxx] where xxx is the type name.
85+ The optional parameter [refined_param_pos] behaves same as [pp_type_of_decl]. *)
7386let show_type_of_decl ?(refined_param_pos =[] ) type_decl =
7487 let loc = type_decl.ptype_loc in
7588 let typ = Ppx_deriving. core_type_of_type_decl type_decl in
0 commit comments