-
Notifications
You must be signed in to change notification settings - Fork 49
Description
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.
- Background
when we want to express @@deriving for a type that's already been declared, we can do it thus:
type t = <type-name> = <type-expression> [@@deriving ...]
but there is no equivalent for extensible variants. If we have an extensible variant type "exn" that has already been extended, viz.
type exn += Failure of string
then how do we express that we want to @@derive functions for it? The form
type exn += Failure = Stdlib.Failure
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:
type exn += Failure of string [@rebind Stdlib.Failure] [@@deriving ....]
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
type exn += Failure = Stdlib.Failure
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.