package ppx_gen_rec

All checked builds pass
  1. Overview
  2. Docs
A ppx rewriter that transforms a recursive module expression into a `struct`

Install

dune-project
 Dependency

Authors

Maintainers

Sources

ppx_gen_rec-v2.0.0.tbz
sha256=fe6323e544f6d8a406572d6c8e01283a03f3c826327833ed58960d0ef43d9e59
sha512=23ecf170f0792c28d0535fba43d6ae51b0a063974ba1b729ebf0af3d8a088b31f4166296fa0e457623384f11142c8430bf13525f721dfbabc60688fad9c92ab9

Description

In a recursive module expression, the struct can be derived from the signature automatically by the compiler. This package does the same thing, but doing it this way allows ppx_deriving to transform the signature and struct separately.

Added to opam-repository:

README

ocaml-ppx_gen_rec

A ppx rewriter that transforms a recursive module expression into a struct.

If you write a recursive module like this:

module rec Foo : sig
  type t = string
end = Foo

The compiler treats it like you wrote:

module rec Foo : sig
  type t = string
end = struct
  type t = string
end

If you try to use ppx_deriving, you get a Undefined_recursive_module exception, because ppx_deriving generates the signature but not the implementation:

module rec Foo : sig
  type t = string [@@deriving show]
end = Foo

(* is like writing *)
module rec Foo : sig
  type t = string
  val show: t -> string
end = struct
  type t = string
  let show _ = raise Undefined_recursive_module
end

Use ppx_gen_rec before ppx_deriving to generate an explicit struct, which will cause ppx_deriving to generate an implementation:

module%gen rec Foo : sig
  type t = string [@@deriving show]
end = Foo

(* becomes... *)
module rec Foo : sig
  type t = string [@@deriving show]
end = struct
  type t = string [@@deriving show]
end

(* which becomes... *)
module rec Foo : sig
  type t = string
  val show: t -> string
end = struct
  type t = string
  let show t = (* show stuff *)
end

Usage

Just use module%gen rec instead of module rec:

module%gen rec Foo : sig
  type t = string [@@deriving show]
end = Foo

License

ocaml-ppx_gen_rec is MIT licensed, as found in the LICENSE file.

Dependencies (3)

  1. ppxlib >= "0.18.0"
  2. dune >= "2.0"
  3. ocaml

Dev Dependencies (1)

  1. ppx_deriving with-test

Optional Dependencies

None

Used by (1)

  1. flow_parser

Conflicts

None

Build status

Results of building ppx_gen_rec with each compiler on check.ci.ocaml.org, run of against opam-repository 7cdc698. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
2.0.0 (this version) good good good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure