There are a few ppx derivers available in opam, try opam search ppx
. As an example, you can use ppx_deriving, e.g., in the OCaml top-level,
# #use "topfind";;
# #require "ppx_deriving.std";;
# type 'a n_tree = NLeaf of 'a | NNode of 'a * 'a n_tree
[@@deriving show, eq, ord, iter, fold, map];;
type 'a n_tree = NLeaf of 'a | NNode of 'a * 'a n_tree
val pp_n_tree :
(Ppx_deriving_runtime.Format.formatter -> 'a -> Ppx_deriving_runtime.unit) ->
Ppx_deriving_runtime.Format.formatter ->
'a n_tree -> Ppx_deriving_runtime.unit = <fun>
val show_n_tree :
(Ppx_deriving_runtime.Format.formatter -> 'a -> Ppx_deriving_runtime.unit) ->
'a n_tree -> Ppx_deriving_runtime.string = <fun>
val equal_n_tree :
('a -> 'a -> Ppx_deriving_runtime.bool) ->
'a n_tree -> 'a n_tree -> Ppx_deriving_runtime.bool = <fun>
val compare_n_tree :
('a -> 'a -> Ppx_deriving_runtime.int) ->
'a n_tree -> 'a n_tree -> Ppx_deriving_runtime.int = <fun>
val iter_n_tree : ('a -> unit) -> 'a n_tree -> unit = <fun>
val fold_n_tree : ('a -> 'b -> 'a) -> 'a -> 'b n_tree -> 'a = <fun>
val map_n_tree : ('a -> 'b) -> 'a n_tree -> 'b n_tree = <fun>
CLICK HERE to find out more related problems solutions.