<commit_before>ppx_deriving
============

_ppx_deriving_ is a library that simplifies type-driven code generation that works on OCaml >=4.02.

_ppx_deriving_ includes a set of useful plugins: Show, (hopefully more in near future).

Installation
------------

_ppx_deriving_ can be installed via [OPAM](http://opam.ocaml.org) (not yet):

    opam install ppx_deriving

Usage
-----

From a user's perspective, _ppx_deriving_ is triggered by a `[@@deriving Plugin]` annotation attached to a type declaration in structure or signature:

    type point2d = float * float
    [@@deriving Show]

It's possible to invoke several plugins by separating their names with commas:

    type point3d = float * float * float
    [@@deriving Show, Eq]

It's possible to pass options to a plugin by appending a record to plugin's name:

    type t = string
    [@@deriving Compare { suffix = "_t" }]

It's possible to make _ppx_deriving_ ignore a missing plugin rather than raising an error by passing an `optional = true` option, for example, to enable conditional compilation:

    type addr = string * int
    [@@deriving Json { optional = true }]

Plugin conventions
------------------

It is expected that all _ppx_deriving_ plugins will follow the same conventions, thus simplifying usage.

  * By default, the functions generated by a plugin for a `type foo` are called `fn_foo` or `foo_fn`. The defaults can be overridden by an `affix` plugin option.

  * There may be additional attributes attached to the AST. In case of a plugin named `Eq` and attributes named `compare` and `skip`, the plugin must recognize all of `compare`, `skip, `eq.compare` and `eq.skip` annotations. However, if it detects that at least one namespaced (e.g. `eq.compare`) attribute is present, it must not look at any non-namespaced attributes. As a result, different plugins can avoid interference even if they share attribute names.

Plugin: Show
------------

_Show_ derives a function that inspects a value; that is, pretty-prints it with OCaml syntax. However, _Show_ offers more insight into the structure of values than the Obj-based pretty printers (e.g. `Printexc`), and more flexibility than the toplevel printer.


    # module M = struct
      type t = int * string [@@deriving Show]
    end;;
    module M : sig
      type t = [ `A | `B of int ]
      val pp_t : Format.formatter -> [< `A | `B of int ] -> unit
      val show_t : [< `A | `B of int ] -> string
    end

    # M.show_t (`B 1);;
    - : bytes = "`B 1"<commit_msg>Fix typo.<commit_after>ppx_deriving
============

_ppx_deriving_ is a library that simplifies type-driven code generation that works on OCaml >=4.02.

_ppx_deriving_ includes a set of useful plugins: Show, (hopefully more in near future).

Installation
------------

_ppx_deriving_ can be installed via [OPAM](http://opam.ocaml.org) (not yet):

    opam install ppx_deriving

Usage
-----

From a user's perspective, _ppx_deriving_ is triggered by a `[@@deriving Plugin]` annotation attached to a type declaration in structure or signature:

    type point2d = float * float
    [@@deriving Show]

It's possible to invoke several plugins by separating their names with commas:

    type point3d = float * float * float
    [@@deriving Show, Eq]

It's possible to pass options to a plugin by appending a record to plugin's name:

    type t = string
    [@@deriving Compare { suffix = "_t" }]

It's possible to make _ppx_deriving_ ignore a missing plugin rather than raising an error by passing an `optional = true` option, for example, to enable conditional compilation:

    type addr = string * int
    [@@deriving Json { optional = true }]

Plugin conventions
------------------

It is expected that all _ppx_deriving_ plugins will follow the same conventions, thus simplifying usage.

  * By default, the functions generated by a plugin for a `type foo` are called `fn_foo` or `foo_fn`. The defaults can be overridden by an `affix` plugin option.

  * There may be additional attributes attached to the AST. In case of a plugin named `Eq` and attributes named `compare` and `skip`, the plugin must recognize all of `compare`, `skip`, `eq.compare` and `eq.skip` annotations. However, if it detects that at least one namespaced (e.g. `eq.compare`) attribute is present, it must not look at any non-namespaced attributes. As a result, different plugins can avoid interference even if they share attribute names.

Plugin: Show
------------

_Show_ derives a function that inspects a value; that is, pretty-prints it with OCaml syntax. However, _Show_ offers more insight into the structure of values than the Obj-based pretty printers (e.g. `Printexc`), and more flexibility than the toplevel printer.


    # module M = struct
      type t = int * string [@@deriving Show]
    end;;
    module M : sig
      type t = [ `A | `B of int ]
      val pp_t : Format.formatter -> [< `A | `B of int ] -> unit
      val show_t : [< `A | `B of int ] -> string
    end

    # M.show_t (`B 1);;
    - : bytes = "`B 1"
{'fraction_non_alphanumeric': 0.10093756233792141, 'fraction_numerical': 0.0027927388789148215, 'mean_word_length': 3.341125541125541, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2667955', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1400, 'n_words': 680}