-
Notifications
You must be signed in to change notification settings - Fork 56
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
Ocaml adapters support for bucklescript #153
Conversation
Good question. The short answers are "it's an internal design issue that requires some extra thinking" and "they're not used at the same time; they're the same thing, duplicated". Right now, each kind of node of the AST has its own set of options. For example, it makes sense for a variant type to support the option There are clearly use cases for json adapters outside of variants and records so this is on the roadmap. Obvious examples include simple types that don't follow json idioms (e.g. converting For the moment, I'd suggest you proceed with a similar technique and support json adapters only for records and for variants. |
No, I don't like the results produced by ocamlformat. I use ocp-indent to normalize indentation, that's it. We can set up a pre-commit hook to run ocp-indent and check line length automatically, see #110 |
Just added tests for adapters, @rgrinberg I think this is ready for review. I'd like to limit the scope of this PR to sum type only, as I'm not sure how record adapters supposed to work. |
A nudge to remind about this PR. @mjambon @rgrinberg |
Yeah, sorry about that. Let me give this an initial review right now. |
I merged the PR with a couple of minor cleanups and analogous record adapter support. Ignoring the field entirely for records isn't right, and there's no need to error out if we can provide simple support. One thing that's a bit worrying is that the interface of both runtimes is differing. That's an issue as we would like to them to converge to a single interface with multiple implementations at some point. |
…nd atdgen (2.1.0) CHANGES: * Fix bug preventing generated code from compiling when using json adapters on recursive types. * Improve automatic error messages shown in case of failed validation. Now include the validator's name or code. * Add support for json adapters in the bucklescript backend. (ahrefs/atd#153)
I started working on adapters support for bucklescript and made a little progress on decoding variants. (I haven't yet committed test cases before getting some initial feedback, but I played around with it on a real project and was able to decode fairly convoluted variant type)
Is there a reason to have separate
json_sum_adapter
andjson_record_adapter
fields? When are they used at the same time?P.S: I tried to follow common indentation/formatting, but it looks arbitrary. Do you use
ocamlformat
?