package ppx_gen_rec
Install
Dune Dependency
Authors
Maintainers
Sources
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.
Published: 07 May 2021
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.
Dev Dependencies (1)
-
ppx_deriving
with-test
Used by (2)
-
flow_parser
>= "0.80.0"
-
flowtype
>= "0.78.0"
Conflicts
None