-
Notifications
You must be signed in to change notification settings - Fork 292
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
Use DeriveLift to generate persistent-template's Lift instances #1064
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GHC 8.0 and later come with the `DeriveLift` extension for deriving instances of `Language.Haskell.TH.Syntax.Lift`. `persistent-template` supports GHC 8.2 and up, so it is able to make use of this. Not only does `DeriveLift` make for much shorter code, but it also fixes warnings that you get when compiling `persistent-template` with GHC 8.10 or later: ``` [1 of 1] Compiling Database.Persist.TH ( Database/Persist/TH.hs, interpreted ) Database/Persist/TH.hs:267:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift SqlTypeExp’ | 267 | instance Lift SqlTypeExp where | ^^^^^^^^^^^^^^^ Database/Persist/TH.hs:278:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift FieldsSqlTypeExp’ | 278 | instance Lift FieldsSqlTypeExp where | ^^^^^^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:284:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift FieldSqlTypeExp’ | 284 | instance Lift FieldSqlTypeExp where | ^^^^^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:288:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift EntityDefSqlTypeExp’ | 288 | instance Lift EntityDefSqlTypeExp where | ^^^^^^^^^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:295:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift ReferenceDef’ | 295 | instance Lift ReferenceDef where | ^^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:302:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift EmbedEntityDef’ | 302 | instance Lift EmbedEntityDef where | ^^^^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:305:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift EmbedFieldDef’ | 305 | instance Lift EmbedFieldDef where | ^^^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:1693:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift EntityDef’ | 1693 | instance Lift EntityDef where | ^^^^^^^^^^^^^^ Database/Persist/TH.hs:1709:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift FieldDef’ | 1709 | instance Lift FieldDef where | ^^^^^^^^^^^^^ Database/Persist/TH.hs:1712:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift UniqueDef’ | 1712 | instance Lift UniqueDef where | ^^^^^^^^^^^^^^ Database/Persist/TH.hs:1715:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift CompositeDef’ | 1715 | instance Lift CompositeDef where | ^^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:1718:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift ForeignDef’ | 1718 | instance Lift ForeignDef where | ^^^^^^^^^^^^^^^ Database/Persist/TH.hs:1724:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift FieldCascade’ | 1724 | instance Lift FieldCascade where | ^^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:1730:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift CascadeAction’ | 1730 | instance Lift CascadeAction where | ^^^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:1736:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift HaskellName’ | 1736 | instance Lift HaskellName where | ^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:1738:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift DBName’ | 1738 | instance Lift DBName where | ^^^^^^^^^^^ Database/Persist/TH.hs:1740:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift FieldType’ | 1740 | instance Lift FieldType where | ^^^^^^^^^^^^^^ Database/Persist/TH.hs:1746:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift PersistFilter’ | 1746 | instance Lift PersistFilter where | ^^^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:1757:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift PersistUpdate’ | 1757 | instance Lift PersistUpdate where | ^^^^^^^^^^^^^^^^^^ Database/Persist/TH.hs:1765:10: warning: [-Wmissing-methods] • No explicit implementation for ‘liftTyped’ • In the instance declaration for ‘Lift SqlType’ | 1765 | instance Lift SqlType where | ^^^^^^^^^^^^ ``` This is because `DeriveLift` fills in implementations of `liftTyped`, a method that was introduced to `Lift` in `template-haskell-2.16.0.0` (bundled with GHC 8.10). Note that not all `Lift` instances currently used by `persistent-template` can be derived, since the code that `DeriveLift` would produce would not be equivalent to some of the more exotic hand-written instances. These include the `Lift` instances for `SqlTypeExp`, `FieldsSqlTypeExp`, `FieldSqlTypeExp`, and `EntityDefSqlTypeExp`. For these instance, I simply define `liftTyped` implementations using CPP.
parsonsmatt
approved these changes
Mar 31, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is awesome, thanks! 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GHC 8.0 and later come with the
DeriveLift
extension for deriving instances ofLanguage.Haskell.TH.Syntax.Lift
.persistent-template
supports GHC 8.2 and up, so it is able to make use of this. Not only doesDeriveLift
make for much shorter code, but it also fixes warnings that you get when compilingpersistent-template
with GHC 8.10 or later:This is because
DeriveLift
fills in implementations ofliftTyped
, a method that was introduced toLift
intemplate-haskell-2.16.0.0
(bundled with GHC 8.10).Note that not all
Lift
instances currently used bypersistent-template
can be derived, since the code thatDeriveLift
would produce would not be equivalent to some of the more exotic hand-written instances. These include theLift
instances forSqlTypeExp
,FieldsSqlTypeExp
,FieldSqlTypeExp
, andEntityDefSqlTypeExp
. For these instance, I simply defineliftTyped
implementations using CPP.After submitting your PR: