diff --git a/Math/LinearMap/Category/Instances/Deriving.hs b/Math/LinearMap/Category/Instances/Deriving.hs
--- a/Math/LinearMap/Category/Instances/Deriving.hs
+++ b/Math/LinearMap/Category/Instances/Deriving.hs
@@ -1450,7 +1450,11 @@
  (tvbs, cxt, (a,c)) <- do
    (tvbs', cxt', a') <- deQuantifyType cxtv
    let extractImplementationType (AppT tc (VarT tvb)) atvbs
+#if MIN_VERSION_template_haskell(2,17,0)
+              = extractImplementationType tc $ atvbs++[PlainTV tvb SpecifiedSpec]
+#else
               = extractImplementationType tc $ atvbs++[PlainTV tvb]
+#endif
        extractImplementationType (ConT aName) atvbs = do
          D.reifyDatatype aName >>= \case
           D.DatatypeInfo{ D.datatypeVariant = D.Newtype
@@ -1459,14 +1463,25 @@
                            D.ConstructorInfo
                               { D.constructorFields = [c''] } ]
                         }
+#if MIN_VERSION_template_haskell(2,17,0)
+             -> let replaceTVs :: [TyVarBndr ()] -> [TyVarBndr Specificity] -> Type -> Type
+                    replaceTVs (PlainTV infoTV _:infoTVs)
+                               (PlainTV instTV _:instTVs)
+                        = replaceTVs infoTVs instTVs . replaceTV infoTV instTV
+                    replaceTVs (KindedTV infoTV flag _:infoTVs) instTVs
+                        = replaceTVs (PlainTV infoTV flag:infoTVs) instTVs
+                    replaceTVs infoTVs (KindedTV instTV flag _:instTVs)
+                        = replaceTVs infoTVs (PlainTV instTV flag:instTVs)
+#else
              -> let replaceTVs :: [TyVarBndr] -> [TyVarBndr] -> Type -> Type
-                    replaceTVs [] [] = id
                     replaceTVs (PlainTV infoTV:infoTVs) (PlainTV instTV:instTVs)
                         = replaceTVs infoTVs instTVs . replaceTV infoTV instTV
                     replaceTVs (KindedTV infoTV _:infoTVs) instTVs
                         = replaceTVs (PlainTV infoTV:infoTVs) instTVs
                     replaceTVs infoTVs (KindedTV instTV _:instTVs)
                         = replaceTVs infoTVs (PlainTV instTV:instTVs)
+#endif
+                    replaceTVs [] [] = id
                     replaceTVs infoTVs instTVs
                         = error $ "infoTVs = "++show infoTVs++", instTVs = "++show instTVs
                     replaceTV :: Name -> Name -> Type -> Type
@@ -1592,7 +1607,13 @@
         
         tySyns <- sequence [
 #if MIN_VERSION_template_haskell(2,15,0)
-           NewtypeInstD [] (Just tvbs)
+           NewtypeInstD [] (Just (
+#if MIN_VERSION_template_haskell(2,17,0)
+                                  map (fmap $ const ()) tvbs
+#else
+                                  tvbs
+#endif
+                                      ))
               <$> (AppT (ConT ''SubBasis) <$> a)
               <*> pure Nothing
               <*> (NormalC subBasisCstr . pure .
diff --git a/linearmap-category.cabal b/linearmap-category.cabal
--- a/linearmap-category.cabal
+++ b/linearmap-category.cabal
@@ -2,7 +2,7 @@
 -- documentation, see http://haskell.org/cabal/users-guide/
 
 name:                linearmap-category
-version:             0.5.0.0
+version:             0.5.0.1
 synopsis:            Native, complete, matrix-free linear algebra.
 description:         The term /numerical linear algebra/ is often used almost
                      synonymous with /matrix modifications/. However, what's interesting
@@ -63,7 +63,7 @@
                        data-default-class,
                        ieee754 >= 0.7 && < 0.9,
                        call-stack,
-                       template-haskell >=2.12 && <2.18,
+                       template-haskell >=2.12 && <2.20,
                        th-abstraction >=0.4 && <0.5,
                        QuickCheck >=2.11 && <2.15
   -- hs-source-dirs:      
