-
Notifications
You must be signed in to change notification settings - Fork 101
Open
Description
Hello!
I'm working on a Ppxlib deriving extension which transforms types into functions (specifically deriving serialization decoders).
I would like to somehow make all of the generated functions encapsulated into a functor that I can then instantiate with a module.
E.g.
(*In file `file.ml` *)
type a = int [@deriving my_ext]
(* makes `a_fun`*)
type b = int * string [@deriving my_ext]
(* makes `b_fun`*)
(* I somehow want to have the above `a_fun` and `b_fun` *) placed into a functor like `File_my_ext` *)
let My_gen_mod = File_my_ext(<MODULE>)
One possible solution is to make it so that
type a = int [@deriving my_ext]
type b = int * string [@deriving my_ext]
generates code like
module File_my_ext (Input : Sig) = struct end
type a = int [@deriving my_ext]
module File_my_ext (Input : Sig) = struct
include File_my_ext(Input)
let a_fun = <FUN>
end
type b = int * string [@deriving my_ext]
module File_my_ext (Input : Sig) = struct
include File_my_ext(Input)
let b_fun = <FUN>
end
I believe this would work, though it feels quite clunky as I am having to create all of these intermediary functors and instantiate them along the way. Is there a more natural way to do this?
If its relevant, that top level of my extension consists of
Deriving.add name ~str_type_decl |> Deriving.ignore
for some implementation of str_type_decl
Thanks!!
Metadata
Metadata
Assignees
Labels
No labels