From 5b54bb51d57287a5331aa576b4dcd31b24118fc5 Mon Sep 17 00:00:00 2001 From: Keigo Imai Date: Wed, 16 Oct 2024 23:17:33 +0900 Subject: [PATCH] more doc comments --- src_plugins/show/ppx_deriving_show.ml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src_plugins/show/ppx_deriving_show.ml b/src_plugins/show/ppx_deriving_show.ml index 8588b6b..6de3bf8 100644 --- a/src_plugins/show/ppx_deriving_show.ml +++ b/src_plugins/show/ppx_deriving_show.ml @@ -49,6 +49,15 @@ let fresh_type_maker type_decl = bound := newvar :: !bound; Typ.var newvar +(** [pp_type_of_decl decl] returns type for [pp_xxx] where xxx is the type name. + For example, for [type ('a, 'b) map] it produces + [(formatter -> 'a -> unit) -> (formatter -> 'b -> unit) -> formatter -> ('a, 'b) map -> unit]. + For GADTs, the optional parameter [refined_param_pos] specifies the index of refined + parameters i.e., [0] for ['a] in [type ('a, 'b) map] and [1] for ['b]. + If present, the type parameter is rendered as any [type _] type, to mark the type parameter is + actually ignored. For example, for [type ('a, 'b) map] with [refined_param_pos=[1]], it produces + [(formatter -> 'a -> unit) -> (formatter -> _ -> unit) -> formatter -> ('a, 'b) map -> unit] + (see [_] instead of ['b] in the type for the second argument). *) let pp_type_of_decl ?(refined_param_pos=[]) type_decl = let loc = type_decl.ptype_loc in 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 = type_decl [%type: Ppx_deriving_runtime.Format.formatter -> [%t typ] -> Ppx_deriving_runtime.unit] +(** Same as [pp_type_of_decl] but type parameters are rendered as locally abstract types rather than + type variables. *) let pp_type_of_decl_newtype ?(refined_param_pos=[]) type_decl = let loc = type_decl.ptype_loc in 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 = type_decl [%type: Ppx_deriving_runtime.Format.formatter -> [%t typ] -> Ppx_deriving_runtime.unit] +(** [show_type_of_decl decl] returns type for [show_xxx] where xxx is the type name. + The optional parameter [refined_param_pos] behaves same as [pp_type_of_decl]. *) let show_type_of_decl ?(refined_param_pos=[]) type_decl = let loc = type_decl.ptype_loc in let typ = Ppx_deriving.core_type_of_type_decl type_decl in