-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add support for extensible type attributes #60
Conversation
I think I really need this PR to finish mine (#57) because the current state of Repr makes it hard to have some functions that are not directly implemented but waiting in a functor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always love to read OCaml black magic! :)
Co-authored-by: Ioana Cristescu <[email protected]>
ec367f2
to
684d255
Compare
Thanks all for the reviews 🙂 Merging now. |
This adds support for attaching arbitrary metadata to type representations, in the form of a new AST node:
where an
'a Attribute.Map.t
can store arbitrary data (indexed by the type'a
).The motivation is to allow interpreters to attach custom info to typereps that is not generally useful (avoiding hard-coding this information directly in the typerep AST). For example, we currently have a variant case
Boxed : 'a t -> 'a t
that is just a flag for the binary encoders (and must be manually ignored by all the other derivers). The attribute mechanism allowstype_binary.ml
to define its ownBoxed
attribute to use instead.Another use-case for this feature is in allowing interpreters to effectively extend
Custom
by attaching hand-implemented functions to typereps. As a demonstration, the newtype_random.ml
deriver now supports custom value generators (a limitation that was raised in #58). This isn't yet exposed to external users (since users can't yet define their own interpreters either).The implementation of this feature uses
Higher
, and (for once) I think it's strictly necessary to support the heterogeneous map semantics. I've defined a helper functor that prevents this from spreading further than it needs to.