janestreet / ppx_sexp_conv

Generation of S-expression conversion functions from type definitions
MIT License
88 stars 17 forks source link

Redirecting to a polymorphic field? #38

Closed cmxog closed 2 years ago

cmxog commented 2 years ago

Would it be possible to derive of_sexp for:

type 'a r = {
   field: 'a
} [@@deriving of_exp]

in such a way that instead of generating a representation of r form, it'd just use the of_exp representation of field?

ceastlund commented 2 years ago

I don't think there's a need to add a "deriving" annotation for that. It's easy enough to write by hand:

let t_of_sexp a_of_sexp sexp = { field = a_of_sexp sexp }

Adding more and more attributes for customizing derived sexps just complicates both the interface and the implementation of ppx_sexp_conv, so for things like this I'd rather not add them.