th-extras 0.0.0.8 → 0.0.0.9
raw patch · 3 files changed
+36/−32 lines, 3 filesdep ~template-haskellPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: template-haskell
API changes (from Hackage documentation)
- Language.Haskell.TH.Extras: tyConArity' :: Name -> Q ([TyVarBndrUnit], Int)
+ Language.Haskell.TH.Extras: tyConArity' :: Name -> Q ([TyVarBndr BndrVis], Int)
Files
- ChangeLog.md +4/−0
- src/Language/Haskell/TH/Extras.hs +22/−26
- th-extras.cabal +10/−6
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for th-extras +## 0.0.0.9 - 2026-02-11++* Support a bunch of new Type constructors in `substVarsWith`.+ ## 0.0.0.8 - 2024-04-14 * Allow th-abstraction-0.7
src/Language/Haskell/TH/Extras.hs view
@@ -1,4 +1,7 @@ {-# LANGUAGE CPP, TemplateHaskell #-}++{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}+ module Language.Haskell.TH.Extras where import Control.Monad@@ -7,7 +10,9 @@ import Data.Set (Set) import qualified Data.Set as Set import Language.Haskell.TH+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 914 import Language.Haskell.TH.Syntax+#endif import Language.Haskell.TH.Datatype.TyVarBndr intIs64 :: Bool@@ -179,13 +184,9 @@ -- Several of the following cases could all be covered by an "x -> x" case, but -- I'd rather know if new cases need to be handled specially in future versions -- of Template Haskell.-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 710- ForallT bndrs cxt t ->+ ForallT bndrs cxt1 t -> let bs' = Set.union bs (Set.fromList (map tvName bndrs))- in ForallT bndrs (map (subst bs') cxt) (subst bs' t)-#else- ForallT {} -> error "substVarsWith: ForallT substitutions have not been implemented for GHCs prior to 7.10"-#endif+ in ForallT bndrs (map (subst bs') cxt1) (subst bs' t) AppT f x -> AppT (subst bs f) (subst bs x) SigT t k -> SigT (subst bs t) k VarT v -> if Set.member v bs@@ -195,6 +196,7 @@ TupleT k -> TupleT k ArrowT -> ArrowT ListT -> ListT+ UnboxedTupleT k -> UnboxedTupleT k #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 800 InfixT t1 x t2 -> InfixT (subst bs t1) x (subst bs t2) ParensT t -> ParensT (subst bs t)@@ -216,9 +218,21 @@ PromotedTupleT k -> PromotedTupleT k StarT -> StarT #endif-#if defined (__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ > 700- UnboxedTupleT k -> UnboxedTupleT k+#if defined (__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 904+ PromotedInfixT t1 x t2 -> PromotedInfixT (subst bs t1) x (subst bs t2)+ PromotedUInfixT t1 x t2 -> PromotedUInfixT (subst bs t1) x (subst bs t2) #endif+#if defined (__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 900+ MulArrowT -> MulArrowT+#endif+#if defined (__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 900+ ForallVisT xs t -> ForallVisT xs (subst bs t)+#endif+#if defined (__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 808+ ImplicitParamT s t -> ImplicitParamT s (subst bs t)+ AppKindT f x -> AppKindT (subst bs f) (subst bs x)+#endif+ findVar v (tv:_) (AppT _ (VarT v')) | v == v' = tv findVar v (_:tvs) (AppT t (VarT _)) = findVar v tvs t findVar v _ _ = error $ "substVarsWith: couldn't look up variable substitution for " ++ show v@@ -227,12 +241,7 @@ -- | Determine the arity of a kind. -- Starting in template-haskell 2.8.0.0, 'Kind' and 'Type' became synonymous. kindArity :: Kind -> Int-#if defined (__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 706 kindArity k = case k of- StarK -> 0- ArrowK _ k2 -> 1 + kindArity k2-#else-kindArity k = case k of ForallT _ _ t -> kindArity t AppT (AppT ArrowT _) t -> 1 + kindArity t SigT t _ -> kindArity t@@ -240,7 +249,6 @@ ParensT t -> kindArity t #endif _ -> 0-#endif -- | Given the name of a type constructor, determine its full arity tyConArity :: Name -> Q Int@@ -260,26 +268,16 @@ tyConArity' n = do r <- reify n return $ case r of-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 800 TyConI (DataD _ _ ts mk _ _) -> (ts, fromMaybe 0 (fmap kindArity mk)) TyConI (NewtypeD _ _ ts mk _ _) -> (ts, fromMaybe 0 (fmap kindArity mk))-#else- TyConI (DataD _ _ ts _ _) -> (ts, 0)- TyConI (NewtypeD _ _ ts _ _) -> (ts, 0)-#endif _ -> error $ "tyConArity': Supplied name reified to something other than a data declaration: " ++ show n -- | Determine the constructors bound by a data or newtype declaration. Errors out if supplied with another -- sort of declaration. decCons :: Dec -> [Con] decCons d = case d of-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 800 DataD _ _ _ _ cs _ -> cs NewtypeD _ _ _ _ c _ -> [c]-#else- DataD _ _ _ cs _ -> cs- NewtypeD _ _ _ c _ -> [c]-#endif _ -> error "decCons: Declaration found was not a data or newtype declaration." -- | Determine the arity of a data constructor.@@ -289,7 +287,5 @@ RecC _ ts -> length ts InfixC _ _ _ -> 2 ForallC _ _ c' -> conArity c'-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 800 GadtC _ ts _ -> length ts RecGadtC _ ts _ -> length ts-#endif
th-extras.cabal view
@@ -1,5 +1,5 @@ name: th-extras-version: 0.0.0.8+version: 0.0.0.9 stability: experimental cabal-version: >= 1.10@@ -19,8 +19,11 @@ providing high-level operations and making sure they work on as many versions of Template Haskell as I can. tested-with:- GHC == 9.8.2- GHC == 9.6.4+ GHC == 9.14.1+ GHC == 9.12.2+ GHC == 9.10.3+ GHC == 9.8.4+ GHC == 9.6.7 GHC == 9.4.8 GHC == 9.2.8 GHC == 9.0.2@@ -40,10 +43,11 @@ Library hs-source-dirs: src+ ghc-options: -Wall exposed-modules: Language.Haskell.TH.Extras build-depends: base >= 4.9 && < 5- , containers- , template-haskell < 2.23+ , containers < 0.9+ , template-haskell < 2.25 , th-abstraction >= 0.4 && < 0.8- , syb+ , syb < 0.8 default-language: Haskell2010