summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandroSerrano <>2019-09-10 20:00:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-09-10 20:00:00 (GMT)
commitf7d946cd897f66c9aba488c66d1eb5158dd04cbd (patch)
tree75707654bbc947ec4e7ecfa302e10cd49c00a228
parent5a3621320fc20312f5a0a92b4729c5a18df128b8 (diff)
version 0.2.1.0HEAD0.2.1.0master
-rw-r--r--kind-generics-th.cabal8
-rw-r--r--src/Generics/Kind/TH.hs21
-rw-r--r--tests/Main.hs15
3 files changed, 33 insertions, 11 deletions
diff --git a/kind-generics-th.cabal b/kind-generics-th.cabal
index fe05564..6bec778 100644
--- a/kind-generics-th.cabal
+++ b/kind-generics-th.cabal
@@ -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 @@ source-repository head
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 @@ test-suite tests
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
diff --git a/src/Generics/Kind/TH.hs b/src/Generics/Kind/TH.hs
index cc46d07..74c24b2 100644
--- a/src/Generics/Kind/TH.hs
+++ b/src/Generics/Kind/TH.hs
@@ -18,6 +18,10 @@ import GHC.Generics as Generics hiding (conIsRecord, conName, datatypeName)
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 @@ import Language.Haskell.TH.Datatype as THAbs
-- * @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 @@ deriveGenericK n = do
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 @@ deriveRepK dataName univVarNames dataVariant cons = do
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
diff --git a/tests/Main.hs b/tests/Main.hs
index ac66d27..f16878d 100644
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -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 @@ main =
, 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 @@ newtype TC4 :: Type -> Type where
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 @@ $(concat <$> traverse deriveGenericK
-- Tricky cases
, ''TC1, ''TC2, ''TC3, ''TC4, ''TC5
+#if MIN_VERSION_template_haskell(2,15,0)
+ , ''TC6
+#endif
])