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

Automatic Enum representation #7

Merged
merged 5 commits into from
Feb 22, 2018
Merged

Conversation

f-f
Copy link
Contributor

@f-f f-f commented Feb 21, 2018

We thought that writing enum representations by hand was a lot of characters (our domain has quite a lot of sum types in some places), so we automated it.

Example from our codebase:

data SubscriptionState
  = Upcoming
  | Active
  | Canceled
  deriving (Show, Eq, Generic, Data, Enum, Bounded)

Before defining enumUnjsonDef we had to write this:

instance Unjson SubscriptionState where
  unjsonDef = enumOf "SubscriptionState"
    [ ("Upcoming", Upcoming)
    , ("Active"  , Active)
    , ("Canceled", Canceled)
    ]

After:

instance Unjson SubscriptionState where
  unjsonDef = enumUnjsonDef

Downsides of this: pulls in the TypeApplication extension, which was introduced in GHC 8.0. But if this is a problem I guess we could just add some other ifs on the GHC version to pull this in when possible.

Copy link
Contributor

@23Skidoo 23Skidoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@23Skidoo
Copy link
Contributor

23Skidoo commented Feb 21, 2018

Looks like the Travis build is failing due to TypeApplications not being supported on GHC <= 7.10.3.

@23Skidoo
Copy link
Contributor

/cc @gracjan @mariuszrak

@gracjan
Copy link
Contributor

gracjan commented Feb 21, 2018

I don't have an opionin really. You can drop support of GHC < 7.10.3 if it goes about me.

@mariuszrak
Copy link
Contributor

LGTM

@23Skidoo
Copy link
Contributor

Pushed some patches for older GHCs compat, dropped support for GHC 7.6. 7.8+/7.10 will still be supported for a while.

@23Skidoo 23Skidoo merged commit 7f1ccc7 into scrive:master Feb 22, 2018
@23Skidoo
Copy link
Contributor

Merged, thanks!

@f-f
Copy link
Contributor Author

f-f commented Feb 22, 2018

Thank you! Sorry for the hassle, I'll be more backwards-compatible next time.

I guess we can go forward with the new release :)

@jonathanjouty
Copy link

Personally, I don't think it is unfair to only support GHC >= 8 for new releases.

@23Skidoo
Copy link
Contributor

Good rule of thumb is "support all GHC versions released in the last 3 years", which includes 7.10.3 at the moment.

@23Skidoo
Copy link
Contributor

@f-f Released version 0.15.0.0 on Hackage.

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

Successfully merging this pull request may close these issues.

None yet

5 participants