package ppx_gen_rec
A ppx rewriter that transforms a recursive module expression into a `struct`.
Install
dune-project
Dependency
Authors
Maintainers
Sources
ppx_gen_rec-1.0.0.tbz
sha256=477d38eb1e193611e14dc6d55af5a5dab5e6436c4a46298209d0979687e2c063
md5=e4cdce94fd2c264f7d74fdb7146dda99
doc/README.html
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 = FooThe compiler treats it like you wrote:
module rec Foo : sig
type t = string
end = struct
type t = string
endIf 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
endUse 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 *)
endUsage
Just use module%gen rec instead of module rec:
module%gen rec Foo : sig
type t = string [@@deriving show]
end = FooLicense
ocaml-ppx_gen_rec is MIT licensed, as found in the LICENSE file.