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

omit fields set to their default value in encoding? #170

Open
c-cube opened this issue Feb 8, 2022 · 0 comments
Open

omit fields set to their default value in encoding? #170

c-cube opened this issue Feb 8, 2022 · 0 comments

Comments

@c-cube
Copy link
Collaborator

c-cube commented Feb 8, 2022

When encoding a value, it seems like it's wasteful to write a field whose value is the default one. That's especially true if there's many such fields.

Alternatively, could we even encode, not from a datatype (Foo_types.bar), but from its smart constructor? As in, why build a value of type Foo_types.bar just to encode it immediately, when we can have val write_bar : ?x:int -> ?y:bool -> ?z:string -> encoder -> unit. That should make it more clear which fields are set or not.

edit: of course I forget, but a cool aspect of writing directly from the function, is that one could potentially replace lists by _ Seq.t so they're generated on demand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant