kind-generics-th 0.2.0.0 → 0.2.1.0
raw patch · 3 files changed
+33/−11 lines, 3 filesdep +ghc-primdep ~template-haskelldep ~th-abstractionPVP ok
version bump matches the API change (PVP)
Dependencies added: ghc-prim
Dependency ranges changed: template-haskell, th-abstraction
API changes (from Hackage documentation)
Files
- kind-generics-th.cabal +5/−3
- src/Generics/Kind/TH.hs +13/−8
- tests/Main.hs +15/−0
kind-generics-th.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: kind-generics-th-version: 0.2.0.0+version: 0.2.1.0 synopsis: Template Haskell support for generating `GenericK` instances description: This package provides Template Haskell functionality to automatically derive @GenericK@ instances (from the@@ -23,9 +23,10 @@ library exposed-modules: Generics.Kind.TH build-depends: base >=4.12 && <5+ , ghc-prim >= 0.5.3 , kind-generics >=0.4- , template-haskell >=2.14 && <2.15- , th-abstraction >=0.2.8 && <0.4+ , template-haskell >=2.14 && <2.16+ , th-abstraction >=0.3.1 && <0.4 hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall@@ -36,6 +37,7 @@ build-depends: base >=4.12 && <5 , kind-generics >=0.4 , kind-generics-th+ , template-haskell >=2.14 && <2.16 hs-source-dirs: tests default-language: Haskell2010 ghc-options: -Wall
src/Generics/Kind/TH.hs view
@@ -18,6 +18,10 @@ import Language.Haskell.TH as TH import Language.Haskell.TH.Datatype as THAbs +#if MIN_VERSION_template_haskell(2,15,0)+import GHC.Classes (IP)+#endif+ -- | Given the 'Name' of a data type (or, the 'Name' of a constructor belonging -- to a data type), generate 'GenericK' instances for that data type. You will -- likely need to enable most of these language extensions in order for GHC to@@ -38,14 +42,10 @@ -- * @TypeFamilies@ deriveGenericK :: Name -> Q [Dec] deriveGenericK n = do- DatatypeInfo{ datatypeName = dataName-#if MIN_VERSION_th_abstraction(0,3,0)+ DatatypeInfo{ datatypeName = dataName , datatypeInstTypes = univVars-#else- , datatypeVars = univVars-#endif- , datatypeVariant = variant- , datatypeCons = cons+ , datatypeVariant = variant+ , datatypeCons = cons } <- reifyDatatype n cons' <- traverse resolveConSynonyms cons let deriveInsts :: [Type] -> [Type] -> Q [Dec]@@ -82,7 +82,7 @@ dataApp = pure $ SigT (foldr (flip AppT) (ConT dataName) argsToKeep) kind instanceD (pure []) (conT ''GenericK `appT` dataApp)- [ tySynInstD ''RepK $ tySynEqn [dataApp] $+ [ tySynInstDCompat ''RepK Nothing [dataApp] $ deriveRepK dataName argNamesToDrop variant cons' , deriveFromK cons' , deriveToK cons'@@ -246,6 +246,11 @@ go (UInfixT ty1 n ty2) = go (ConT n `AppT` ty1 `AppT` ty2) go (SigT ty _) = go ty go (ParensT ty) = ParensT <$> go ty+#if MIN_VERSION_template_haskell(2,15,0)+ go (AppKindT ty _) = go ty+ go (ImplicitParamT n ty) = go (ConT ''IP `AppT` LitT (StrTyLit n) `AppT` ty)+ -- Desugar (?n :: T) into (IP "n" T)+#endif -- Failure case go ty@ForallT{} = can'tRepresent "rank-n type" ty
tests/Main.hs view
@@ -1,8 +1,10 @@ {-# language AllowAmbiguousTypes #-}+{-# language CPP #-} {-# language DataKinds #-} {-# language EmptyCase #-} {-# language FlexibleInstances #-} {-# language GADTs #-}+{-# language ImplicitParams #-} {-# language MultiParamTypeClasses #-} {-# language PolyKinds #-} {-# language ScopedTypeVariables #-}@@ -80,6 +82,10 @@ , isGenericK @_ @TC4 @(_ ':&&: 'LoT0) , isGenericK @_ @(TC5 _) @'LoT0++#if MIN_VERSION_template_haskell(2,15,0)+ , isGenericK @_ @TC6 @'LoT0+#endif ] in insts `seq` pure () @@ -120,6 +126,12 @@ data TC5 :: Type -> Type where MkTC5 :: forall k (a :: k). k -> Proxy a -> TC5 k +#if MIN_VERSION_template_haskell(2,15,0)+-- Implicit parameters+data TC6 :: Type where+ MkTC6 :: (?n :: Bool) => TC6+#endif+ $(concat <$> traverse deriveGenericK [ -- Representation types ''V1, ''(:+:), ''(:*:), ''U1, ''M1, ''Field, ''(:=>:), ''Exists@@ -132,4 +144,7 @@ -- Tricky cases , ''TC1, ''TC2, ''TC3, ''TC4, ''TC5+#if MIN_VERSION_template_haskell(2,15,0)+ , ''TC6+#endif ])