packages feed

th-extras 0.0.0.1 → 0.0.0.2

raw patch · 2 files changed

+74/−4 lines, 2 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Language.Haskell.TH.Extras: argTypesOfCon :: Con -> [Type]
+ Language.Haskell.TH.Extras: composeExprs :: [ExpQ] -> ExpQ
+ Language.Haskell.TH.Extras: headOfType :: Type -> Name
+ Language.Haskell.TH.Extras: nameOfBinder :: TyVarBndr -> Name
+ Language.Haskell.TH.Extras: nameOfCon :: Con -> Name
+ Language.Haskell.TH.Extras: occursInType :: Name -> Type -> Bool
+ Language.Haskell.TH.Extras: varsBoundInCon :: Con -> [TyVarBndr]

Files

src/Language/Haskell/TH/Extras.hs view
@@ -1,10 +1,11 @@-{-# LANGUAGE CPP #-}+{-# LANGUAGE CPP, TemplateHaskell #-} module Language.Haskell.TH.Extras where  import Control.Monad import Data.Generics import Data.Maybe import Language.Haskell.TH+import Language.Haskell.TH.Syntax  intIs64 :: Bool intIs64 = toInteger (maxBound :: Int) > 2^32@@ -12,6 +13,37 @@ replace :: (a -> Maybe a) -> (a -> a) replace = ap fromMaybe +composeExprs :: [ExpQ] -> ExpQ+composeExprs [] = [| id |]+composeExprs [f] = f+composeExprs (f:fs) = [| $f . $(composeExprs fs) |]++nameOfCon :: Con -> Name+nameOfCon (NormalC  name _) = name+nameOfCon (RecC     name _) = name+nameOfCon (InfixC _ name _) = name+nameOfCon (ForallC _ _ con) = nameOfCon con++-- |WARNING: discards binders in GADTs and existentially-quantified constructors+argTypesOfCon :: Con -> [Type]+argTypesOfCon (NormalC  _ args) = map snd args+argTypesOfCon (RecC     _ args) = [t | (_,_,t) <- args]+argTypesOfCon (InfixC x _ y)    = map snd [x,y]+argTypesOfCon (ForallC _ _ con) = argTypesOfCon con++nameOfBinder :: TyVarBndr -> Name+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 700+nameOfBinder (PlainTV n)    = n+nameOfBinder (KindedTV n _) = n+#else+nameOfBinder = id+type TyVarBndr = Name+#endif++varsBoundInCon :: Con -> [TyVarBndr]+varsBoundInCon (ForallC bndrs _ con) = bndrs ++ varsBoundInCon con+varsBoundInCon _ = []+ namesBoundInPat :: Pat -> [Name] namesBoundInPat (VarP name)             = [name] namesBoundInPat (TupP pats)             = pats >>= namesBoundInPat@@ -68,4 +100,37 @@         names = decs >>= namesBoundInDec         genericalizedNames = [ (n, genericalizeName n) | n <- names]         fixName = replace (`lookup` genericalizedNames)++headOfType :: Type -> Name+headOfType (ForallT _ _ ty) = headOfType ty+headOfType (VarT name) = name+headOfType (ConT name) = name+headOfType (TupleT n) = tupleTypeName n+headOfType ArrowT = ''(->)+headOfType ListT = ''[]+headOfType (AppT t _) = headOfType t++#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 612+headOfType (SigT t _) = headOfType t+#endif++#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+headOfType (UnboxedTupleT n) = unboxedTupleTypeName n+#endif++occursInType :: Name -> Type -> Bool+occursInType var ty = case ty of+        ForallT bndrs _ ty+            | any (var ==) (map nameOfBinder bndrs)+                -> False+            | otherwise+                -> occursInType var ty+        VarT name+            | name == var -> True+            | otherwise   -> False+        AppT ty1 ty2 -> occursInType var ty1 || occursInType var ty2+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 612+        SigT ty _ -> occursInType var ty+#endif+        _ -> False 
th-extras.cabal view
@@ -1,5 +1,5 @@ name:                   th-extras-version:                0.0.0.1+version:                0.0.0.2 stability:              experimental  cabal-version:          >= 1.6@@ -11,8 +11,13 @@ homepage:               https://github.com/mokus0/th-extras  category:               Template Haskell-synopsis:               A grab bag of useful functions for use with Template Haskell-description:            A grab bag of useful functions for use with Template Haskell+synopsis:               A grab bag of functions for use with Template Haskell+description:            A grab bag of functions for use with Template Haskell.+                        .+                        This is basically the place I put all my ugly CPP hacks to support+                        the ever-changing interface of the template haskell system by+                        providing high-level operations and making sure they work on as many+                        versions of Template Haskell as I can.  tested-with:            GHC == 6.8.3, GHC == 6.10.4, GHC == 6.12.3,                         GHC == 7.0.4, GHC == 7.2.1, GHC == 7.2.2