-
Notifications
You must be signed in to change notification settings - Fork 17
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GADT support #8
Comments
Unfortunately it's not possible to write such a function as it would be unsafe. Instead you need to wrap the type into a GADT to introduce the existential: type packed_obj = Obj : _ obj -> packed_obj Currently there is no special support in findlib for types that are wrapped in such a way. What we usually do is define a helper type: module For_sexp = struct
type t = OInt | OStr [@@deriving of_sexp]
end
type _ t = OInt : int t | OStr : string t
type packed = T : _ t -> packed
let packed_of_sexp sexp =
match For_sexp.t_of_sexp with
| OInt -> T OInt
| OStr -> T OStr |
Oh indeed, I see! Thank you very much for the reply @diml . |
I'm closing this issue because the specific question got answered. The general support of GADTs is a complicated topic and definitely not fully explored. Any proposals for how to support GADTs are welcome in separate issues. |
Dear ppx_sexp_conv devs,
thanks again for this great tool, it would be great if GADTs could be serialized both ways. This:
currently results in:
Note that
[@@deriving sexp_of]
works fine and it indeed is very useful!The text was updated successfully, but these errors were encountered: