janestreet / ppx_sexp_conv

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

Attribute format for sexp_opaque #26

Closed peblair closed 4 years ago

peblair commented 5 years ago

sexp_opaque is useful for omitting certain fields from a serialized output, but leads to some unintended interactions with other ppx libraries. For example, consider the following:

type foo =
  | Bar of int sexp_opaque
[@@deriving sexp, yojson]

Leads to the following compilation error:

File "_none_", line 1:
Error: Unbound value sexp_opaque_to_yojson

Unfortunately, there is no real way to write sexp_opaque_to_json. Consider the following (proposed) example instead:

type foo =
  | Bar of int [@sexp_opaque]
[@@deriving sexp, yojson]

This would allow things to at least compile. Would you consider adding such a feature?

ghost commented 5 years ago

Yes, actually we have been thinking about doing this for a while but never took the time to implement it.

bcc32 commented 5 years ago

We've made this change, and the next opam release should support the @sexp.opaque attribute: see the v0.13-preview.120.28+212 readme

peblair commented 5 years ago

🙏 Super! Thanks!

shonfeder commented 4 years ago

Looks like this can be closed?

bcc32 commented 4 years ago

Ah, yes, this is available in OPAM now, so I'm closing this issue. Thanks for the suggestion!