th-utilities 0.2.1.0 → 0.2.2.0
raw patch · 4 files changed
+29/−11 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ TH.Utilities: dequalifyTyVars :: Data a => a -> a
Files
- ChangeLog.md +10/−0
- src/TH/Derive.hs +9/−2
- src/TH/Utilities.hs +8/−7
- th-utilities.cabal +2/−2
ChangeLog.md view
@@ -1,5 +1,15 @@ # ChangeLog +## 0.2.2.0++* Fixes derive and instantiator mechanisms to work with ghc 7.10 and+ earlier. Previously, invocation was broken when type variables were+ used.++* Fixes `freeVarsT` - it now looks through more constructors of `Type`.++* Adds `dequalifyTyVars` to dequalify every type variable.+ ## 0.2.0.1 * Fixes build on 7.8
src/TH/Derive.hs view
@@ -84,18 +84,25 @@ toStmt (varName, dec) = case fromPlainInstanceD dec of Just (preds, AppT (ConT ((== ''Deriving) -> True)) cls, []) -> bindS (varP varName)- [e| runDeriver $(proxyE (return cls))+ [e| runDeriver $(proxyE (return (unitTyVars cls))) preds cls |] Just (preds, ty, decs) -> bindS (varP varName)- [e| runInstantiator $(proxyE (return ty))+ [e| runInstantiator $(proxyE (return (unitTyVars ty))) preds ty decs |] _ -> fail $ "Expected deriver or instantiator, instead got:\n" ++ show dec++-- | Turn type variables into unit types.+unitTyVars :: Data a => a -> a+unitTyVars = everywhere (id `extT` modifyType)+ where+ modifyType (VarT _) = TupleT 0+ modifyType ty = ty -- | Useful function for defining 'Instantiator' instances. It uses -- 'Data' to generically replace references to the methods with plain
src/TH/Utilities.hs view
@@ -94,17 +94,18 @@ dequalify :: Name -> Name dequalify = mkName . nameBase +-- | Apply 'dequalify' to every type variable.+dequalifyTyVars :: Data a => a -> a+dequalifyTyVars = everywhere (id `extT` modifyType)+ where+ modifyType (VarT n) = VarT (dequalify n)+ modifyType ty = ty+ -- | Get the free type variables of a 'Type'. freeVarsT :: Type -> [Name] freeVarsT (ForallT tvs _ ty) = filter (`notElem` (map tyVarBndrName tvs)) (freeVarsT ty)-freeVarsT (AppT l r) = freeVarsT l ++ freeVarsT r-freeVarsT (SigT ty k) = freeVarsT ty ++ freeVarsT k freeVarsT (VarT n) = [n]-#if MIN_VERSION_template_haskell(2,11,0)-freeVarsT (InfixT x n r) = freeVarsT x ++ freeVarsT r-freeVarsT (UInfixT x n r) = freeVarsT x ++ freeVarsT r-#endif-freeVarsT _ = []+freeVarsT ty = concat $ gmapQ (const [] `extQ` freeVarsT) ty -- | Utility to conveniently handle change to 'InstanceD' API in -- template-haskell-2.11.0
th-utilities.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: f65b38d225125ec3f0a4ec974c8bcae0ae5358894abd8c118aa1a6b3c9b457e7+-- hash: fffcc9b9550bfe2e35141d3aadeb19bc6d5536025381f9c21188fc104a24b062 name: th-utilities-version: 0.2.1.0+version: 0.2.2.0 synopsis: Collection of useful functions for use with Template Haskell category: Template Haskell homepage: https://github.com/fpco/th-utilities#readme