Skip to content

Support for customizing encoded variant values. #36

@mrmurphy

Description

@mrmurphy

I'd really love the ability to customize the string representation of non-polymorphic variants. Maybe something like this?

[@decco]
type purchaseType =
  | [@decco.as "premium_subscription"] PremiumSubscription
  | [@decco.as "plus_purchases"] PlusPurchase
  | [@decco.as "gift"] Gift;

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions