-
Notifications
You must be signed in to change notification settings - Fork 27
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
Support for customizing encoded variant values. #36
Comments
Yep, this is roughly the problem I was going for in #3. My approach to this so far has been the same as yours from the sound of it (custom decoders) and I agree that it seems labor-intensive for something that it seems could be automated. I think we could definitely do this, maybe by disallowing |
I love it, that sounds great.
…On Dec 5, 2019, 9:31 PM -0700, Ryan ***@***.***>, wrote:
Yep, this is roughly the problem I was going for in #3.
My approach to this so far has been the same as yours from the sound of it (custom decoders) and I agree that it seems labor-intensive for something that it seems could be automated.
I think we could definitely do this, maybe by disallowing ***@***.*** for any variant constructor that doesn't have parameters? The idea is that ***@***.*** could be added to any (not necessarily all) constructors on a type. If a constructor has ***@***.*** it would encode to (for encoders) or look for (for decoders) that value, and otherwise the variant would be treated as normal.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Is there an easy way to skip the array on encode? @decco
type order = {
name: string,
}
@decco
type rule =
| Order(order) Now: //rule_encode
["Order", {name: "John Smith"}] Request: //rule_encode
{name: "John Smith"} Not exactly sure how to accomplish this with a custom codec or if that is the best way to achieve this. |
I'd really love the ability to customize the string representation of non-polymorphic variants. Maybe something like this?
My current approach is to write a custom decoder in a new module for that specific type, doing the stringification and parsing by hand. That's fine, and it works, but it's a bit labor-intensive, so I find myself opting to use strings instead of variants in my code, just because I don't want to write codecs for them.
(may be related to #3)
I guess the challenge would be, what would the PPX do if I tried to use this decorator on a variant that contains data? Could we make a sensible compiler error for that?
The text was updated successfully, but these errors were encountered: