Skip to content

Commit

Permalink
more doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
keigoi committed Oct 16, 2024
1 parent 9553805 commit 5b54bb5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src_plugins/show/ppx_deriving_show.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5b54bb5

Please sign in to comment.