Skip to content
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

use ppx to reduce boilerplate code #31

Open
5 of 10 tasks
vogler opened this issue Jan 11, 2016 · 2 comments
Open
5 of 10 tasks

use ppx to reduce boilerplate code #31

vogler opened this issue Jan 11, 2016 · 2 comments
Assignees
Labels
cleanup Refactoring, clean-up type-safety Type-safety improvements

Comments

@vogler
Copy link
Collaborator

vogler commented Jan 11, 2016

Use type-driven code generation to get rid of boilerplate (see ppx_deriving):

@vogler vogler added the cleanup Refactoring, clean-up label Jan 11, 2016
@vogler vogler self-assigned this Jan 11, 2016
@vogler vogler added the type-safety Type-safety improvements label Jul 28, 2016
keremc pushed a commit to keremc/analyzer that referenced this issue Mar 15, 2021
Add a package setting toplevel printers
@sim642 sim642 self-assigned this May 11, 2021
@sim642
Copy link
Member

sim642 commented Jun 12, 2021

At some point I found ppx_yojson, which attempts to simplify manual creation of Yojson values, e.g. by converting OCaml record-like syntax to a JSON object. It's not for deriving anything but just avoids having to construct Yojson values directly using its constructors.

This might be useful for manual implementations of to_yojson, which @keremc is adding more of. Although I think all those manual implementations are simple enough (e.g. a single string) that this isn't really worth it, but I'm still mentioning it here so I can close the tab...

@sim642
Copy link
Member

sim642 commented Apr 24, 2022

I happened upon ppx_type_directed_value, which Jane Street just has, but I've never heard of anyone using. Its idea being to make custom deriving plugins easier to define by not having to write a ppx deriver from scratch but just define the behavior for product and sum types and have it automagically work for all tuples, records, etc.

It sounds like a nice way to define our own lattice derivers, but it adds the Jane Street Base dependency and has notable performance implications:

The usage of this PPX does incur a runtime cost proportional to the size of the type (e.g. number of fields/constructors/elements in a record/variant/tuple). In particular, if the type-directed value is a function type, there will be a runtime cost on every invocation of the function.

In their benchmarking example they reimplement equality deriving, which via this ppx is ~4× slower than a direct equality deriver. So I'm a bit skeptical if it'd be fast enough to replace our currently hand-written lattice definitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Refactoring, clean-up type-safety Type-safety improvements
Projects
None yet
Development

No branches or pull requests

2 participants