-
Notifications
You must be signed in to change notification settings - Fork 47
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
achieving @@deriving for extensible variants that have already been extended #119
Comments
This seems very ad-hoc to me. I would rather:
One issue with the second approach is that the most natural syntax creates an ambiguity between "a rebind that leaves the parameters out" and "a rebind of constructors without parameters", which is not so nice. (But if people really want to insist on their intent to rebind a parameter-less constructor, maybe they can use the GADT syntax?) |
I don't believe you can use Changing the Ocaml language: well, I can't suggest that, b/c after all, we're talking about a macro-preprocessor, and it would be a great ask for the macro-preprocessor to demand changes to the language for its own convenience, right? Also, this is a corner-case, after all. And I agree with you that there's the problem that if we want to support both "rebind that omits constructor arguments" and "rebind that includes constructor arguments" then there's the ambiguity of an argument-less constructor. This is why I suggested a macro-processor-only solution: the need is only in the macro-processor, and hence the solution could be only in the macro-processor. Your thoughts? |
Also, the reason I started thinking about this, is support for the extensible type And if it is that way is defined properly, then every deriver could support it the same way. P.S. the actual code for this is pretty trivial: I can code it in a few hours in my |
Here's a (working) example of what I mean:
This yields
|
I'm trying to figure out the right way to express @@deriving directives for extensible variants that have already been extended, and thought that I'd see if you all had some thoughts.
when we want to express @@deriving for a type that's already been declared, we can do it thus:
but there is no equivalent for extensible variants. If we have an extensible variant type "exn" that has already been extended, viz.
then how do we express that we want to @@derive functions for it? The form
doesn't help, b/c it doesn't carry the type-arguments of the constructor.
(2) I propose we can do this in two stages:
The first stage is the @@deriving rewriter that generats functions based on this type, as if "Failure" is freshly extending "exn". The second stage rewrites (directed by the @Rebind) the rebind-extension-constructor to
This seems straightforward, and I don't see any problems, but I figured I'd ask if you all had thought about this, and whether it was problematic in some way I haven't understood.
The text was updated successfully, but these errors were encountered: