You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is special treatment of Maybe when deriving instances using Generic -- Maybe fields become optional.
I think it might make sense to apply the same special treatment to the Proxy type -- Proxy fields should probably also be optional -- they can only have one value after all. (And requiring a null field seems a bit unnecessary)
AFAIK, Proxy is the only way to do a strict null check without writing custom instances so this may be a breaking change for some users. If we introduce e.g. a data Null = Null for this purpose then we can refer people to that instead. I'd like to have a module containing types that are only meant to be used to force JSON representations, it's not straight-forward to know to use Proxy here. We already have DotNetTime which would fit in there as well, and speaking of time we've had other requests for specific serializations for them. E.g. only allowing millisecond precision for UTCTime, but we want to allow more precision there, a ms precision type would be nice to have.
I would like to provide my motivation for wanting this change.
It is sometimes necessary to have a subset of the fields of a structure returned from the API. While it is possible to define two separate structures, it would be easier to have one parametrized structure.
It is currently impossible to define a custom f to get the desired behavior -- any FromJSON instance would require the field being present, the instance itself would only have the opportunity to look at the value of the field.
I would also be happy if we could introduce a custom functor for this purpose which would have special treatment. Changing the semantics of Proxy might not be such a good idea, and it wouldn't be obvious to newcomers why Proxy of all things would get special treatment.
#564 would solve that, by having a specific instances for field needs, we can make Maybe and Proxy just have own instances, and not try to hack it all into Generic and TH machinery in ad-hoc manner.
The #1038 will make omitting () and Proxy possible.
Proxy is the only way to do a strict null check without writing custom instances
Using omitNothingFields and allowOmittedFields users can control behavior in their ToJSON/FromJSON instances.
If there are some who want to allow omitted Maybe fields but do null check on some in the same record, they should probably write a manual instance. That behavior doesn't seem very uniform.
Activity
bergmark commentedon Aug 7, 2020
AFAIK, Proxy is the only way to do a strict null check without writing custom instances so this may be a breaking change for some users. If we introduce e.g. a
data Null = Nullfor this purpose then we can refer people to that instead. I'd like to have a module containing types that are only meant to be used to force JSON representations, it's not straight-forward to know to use Proxy here. We already have DotNetTime which would fit in there as well, and speaking of time we've had other requests for specific serializations for them. E.g. only allowing millisecond precision for UTCTime, but we want to allow more precision there, a ms precision type would be nice to have.iko-soy commentedon Oct 21, 2020
I would like to provide my motivation for wanting this change.
It is sometimes necessary to have a subset of the fields of a structure returned from the API. While it is possible to define two separate structures, it would be easier to have one parametrized structure.
It is currently impossible to define a custom
fto get the desired behavior -- anyFromJSONinstance would require the field being present, the instance itself would only have the opportunity to look at the value of the field.I would also be happy if we could introduce a custom functor for this purpose which would have special treatment. Changing the semantics of
Proxymight not be such a good idea, and it wouldn't be obvious to newcomers whyProxyof all things would get special treatment.phadej commentedon Oct 21, 2020
#564 would solve that, by having a specific instances for field needs, we can make
MaybeandProxyjust have own instances, and not try to hack it all intoGenericandTHmachinery in ad-hoc manner.Resolve #792: () and Proxy can be omitted
Complete omitField and omittedField things
phadej commentedon Jun 15, 2023
The #1038 will make omitting () and Proxy possible.
Using
omitNothingFieldsandallowOmittedFieldsusers can control behavior in their ToJSON/FromJSON instances.If there are some who want to allow omitted
Maybefields but do null check on some in the same record, they should probably write a manual instance. That behavior doesn't seem very uniform.Complete omitField and omittedField things
Complete omitField and omittedField things
Complete omitField and omittedField things
Complete omitField and omittedField things