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

ppx: add [@drop_default] for record fields #17

Merged
merged 1 commit into from
Sep 9, 2024
Merged

Commits on Sep 9, 2024

  1. ppx: add [@drop_default] for record fields

    For now it only works for record fields annotated with `[@option]`, by
    dropping the field from JSON repr when the record value is `None`.
    
    What's missing is to also support `[@drop_default]` for fields annotated
    by `[@default X]` but we need to decide how to check for equality
    between the default value and the field value.
    
    One nice idea I had is to generate code like this:
    
    ```ocaml
    type t = { a : int [@default 0] [@drop_default] }
    ...
    let bnds =
      match [%equal int] a 0 with
      | true -> bnds
      | false -> ("a", a)::bnds
    in
    ...
    ```
    
    but this means this ppx will depends on another ppx which provides
    `[%equal t]` deriver but sadly `ppx_compare` doesn't work with melange
    now.
    andreypopp committed Sep 9, 2024
    Configuration menu
    Copy the full SHA
    97685ae View commit details
    Browse the repository at this point in the history