package ppx_gen_rec

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

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_gen_rec-v1.1.0.tbz
sha256=7061496354023c182f189f02ee3dc5a8ae54dbb75b66a5effb09226ce722913b
sha512=37dded76035765673947d1d5d5e49ae7d36f80baaf7b5315d78e1392546c93d12ee164ce23baec6007879d3a8277c860c130d27b09be77b0caf736c7144881f0

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.

Published: 09 Jul 2019

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. ocaml-migrate-parsetree >= "1.1.0" & < "2.0.0"
  2. dune
  3. ocaml

Dev Dependencies

None

Used by (2)

  1. flow_parser >= "0.80.0"
  2. flowtype >= "0.78.0"

Conflicts

None