TYB 0.2.0 → 0.2.1
raw patch · 3 files changed
+25/−25 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Generics.TH: containsType :: Quasi m => m Type -> Type -> m Bool
- Data.Generics.TH: containsTypes :: Quasi m => [m Type] -> Type -> m Bool
+ Data.Generics.TH: inType :: Quasi m => m Type -> Type -> m Bool
+ Data.Generics.TH: inTypes :: Quasi m => [m Type] -> Type -> m Bool
Files
- Data/Generics/TH.hs +13/−13
- TYB.cabal +1/−1
- examples/Syntax.hs +11/−11
Data/Generics/TH.hs view
@@ -33,7 +33,7 @@ , mkT, mkTs, mkQ, mkQs, mkM, mkMs -- * Type manipulation functions , eqType, eqTypes- , containsType, containsTypes+ , inType, inTypes , constructorsOf, typeOfName #if BENCHMARK -- * Benchmarking implementations@@ -42,7 +42,7 @@ #endif ) where --- Imports for the 'seen' table in 'containsType'+-- Imports for the 'seen' table in 'inType' import Control.Monad.State -- Imports for memoization tables@@ -515,7 +515,7 @@ -- type @t@. If the 'Type' is @t0@, returns an -- 'Exp' of type @t0 -> t0@. everywhereFor func topTy = do- everywhereBut (liftM not . containsType (argTypeOfName func))+ everywhereBut (liftM not . inType (argTypeOfName func)) (const (return (VarE 'id)) `extE` (eqType (argTypeOfName func), return (VarE func))) topTy @@ -529,7 +529,7 @@ -- that is of type @t@. If the 'Type' is @t0@, -- returns an 'Exp' of type @t0 -> m t0@. everywhereForM func topTy = do- everywhereButM' (liftM not . containsType (argTypeOfName func))+ everywhereButM' (liftM not . inType (argTypeOfName func)) (const (return (VarE 'return)) `extE` (eqType (argTypeOfName func), return (VarE func))) topTy @@ -867,7 +867,7 @@ let op = VarE func g t = do b <- eqType (return a1) t- c <- containsType (return a1) t+ c <- inType (return a1) t if b then return (op, not c) else return (AppE (VarE 'const) (VarE 'id), not c) everythingButAccL g topTy@@ -884,7 +884,7 @@ let op = VarE func g t = do b <- eqType (return a1) t- c <- containsType (return a1) t+ c <- inType (return a1) t if b then return (op, not c) else return (AppE (VarE 'const) (VarE 'id), not c) everythingButAccL' g topTy@@ -901,7 +901,7 @@ let op = VarE func g t = do b <- eqType (return a1) t- c <- containsType (return a1) t+ c <- inType (return a1) t if b then return (op, not c) else do h <- [|const id|] return (h, not c)@@ -1155,9 +1155,9 @@ eqTypes :: (Quasi m) => [m Type] -> Type -> m Bool eqTypes ts t = liftM or $ mapM (flip eqType t) ts --- |@containsType t1 t2 = True@ iff @t1@ is (even recursively) inside @t2@-containsType :: (Quasi m) => m Type -> Type -> m Bool-containsType t1 t2 =+-- |@inType t1 t2 = True@ iff @t1@ is (even recursively) inside @t2@+inType :: (Quasi m) => m Type -> Type -> m Bool+inType t1 t2 = evalStateT (flip rec t2 =<< lift (expandType =<< t1)) Set.empty where rec t1 t2 = do t2' <- expandType t2@@ -1174,9 +1174,9 @@ t' <- rec t1 t if t' then return True else check t1 ts --- |@containsTypes ts t2 = True@ iff any of @ts@ is (even recursively) inside @t2@-containsTypes :: (Quasi m) => [m Type] -> Type -> m Bool-containsTypes t1qs t2 = fmap or (mapM (`containsType` t2) t1qs)+-- |@inTypes ts t2 = True@ iff any of @ts@ is (even recursively) inside @t2@+inTypes :: (Quasi m) => [m Type] -> Type -> m Bool+inTypes t1qs t2 = fmap or (mapM (`inType` t2) t1qs) -------------------------------------------------------------------------------- -- Internal utilities
TYB.cabal view
@@ -1,5 +1,5 @@ Name: TYB-Version: 0.2.0+Version: 0.2.1 Synopsis: Template Your Boilerplate - a Template Haskell version of SYB Description: TYB is a generic-programming system that uses Template Haskell to generate boiler-plate traversals at compile
examples/Syntax.hs view
@@ -34,7 +34,7 @@ const_HsName c = $(everywhere (const [|id|] `extE` (eqType [t|HsName|], [|const c|])) [t|HsModule|]) const_HsName_But :: HsName -> HsModule -> HsModule-const_HsName_But c = $(everywhereBut (liftM not . containsType [t|HsName|])+const_HsName_But c = $(everywhereBut (liftM not . inType [t|HsName|]) (const [|id|] `extE` (eqType [t|HsName|], [|const c|])) [t|HsModule|]) ----------------------------------------@@ -69,10 +69,10 @@ where f :: HsName -> Int -> Int f _ = (+1) --- 148us if we only check eqType, 117us if we check both eqType and containsType+-- 148us if we only check eqType, 117us if we check both eqType and inType count_HsName_But :: HsModule -> Int count_HsName_But = $(let g t = do b <- eqType [t|HsName|] t- c <- containsType [t|HsName|] t+ c <- inType [t|HsName|] t if b then do h <- [|const 1|] return (h, True) else do h <- [|const 0|]@@ -81,7 +81,7 @@ count_HsName_But_Acc :: HsModule -> Int count_HsName_But_Acc x = $(let g t = do b <- eqType [t|HsName|] t- c <- containsType [t|HsName|] t+ c <- inType [t|HsName|] t if b then do h <- [|const (+1)|] return (h, True) else do h <- [|const id|]@@ -104,7 +104,7 @@ list_HsName_But :: HsModule -> [HsName] list_HsName_But = $(everythingBut [|(++)|] (\t -> do e <- mkQ [|[]|] 'f t- b <- liftM not (containsType [t|HsName|] t) + b <- liftM not (inType [t|HsName|] t) return (e,b)) [t|HsModule|]) where f :: HsName -> [HsName]@@ -117,7 +117,7 @@ list_HsName_Comp_But :: HsModule -> [HsName] list_HsName_Comp_But x = $(let g t = do b <- eqType [t|HsName|] t- c <- containsType [t|HsName|] t+ c <- inType [t|HsName|] t if b then do h <- [|(:)|] return (h, True) else do h <- [|const id|]@@ -148,7 +148,7 @@ list_HsName_Acc_But :: HsModule -> [HsName] list_HsName_Acc_But x = $(let rec memoF t = do is <- eqType [t|HsName|] t- contains <- containsType [t|HsName|] t+ contains <- inType [t|HsName|] t case (is, contains) of (True, _) -> [|\acc name -> name : acc|] (_, True) -> [|\acc -> $(thcase (g [|acc|]) (return t))|]@@ -160,7 +160,7 @@ list_HsName_AccR_But :: HsModule -> [HsName] list_HsName_AccR_But x = $(let h t = do b <- eqType [t|HsName|] t- c <- containsType [t|HsName|] t+ c <- inType [t|HsName|] t if b then do h <- [|(:)|] return (h, True) else do h <- [|const id|]@@ -174,7 +174,7 @@ list_HsName_AccL_But :: HsModule -> [HsName] list_HsName_AccL_But x = $(let h t = do b <- eqType [t|HsName|] t- c <- containsType [t|HsName|] t+ c <- inType [t|HsName|] t if b then do h <- [|(:)|] return (h, True) else do h <- [|const id|]@@ -188,7 +188,7 @@ list_HsName_AccL'_But :: HsModule -> [HsName] list_HsName_AccL'_But x = $(let h t = do b <- eqType [t|HsName|] t- c <- containsType [t|HsName|] t+ c <- inType [t|HsName|] t if b then do h <- [|(:)|] return (h, True) else do h <- [|const id|]@@ -218,7 +218,7 @@ prefix_HsName = $(everywhere (const [|id|] `extN` 'prefix) [t|HsModule|]) prefix_HsName_But :: HsModule -> HsModule-prefix_HsName_But = $(everywhereBut (liftM not . containsType [t|HsName|]) (const [|id|] `extN` 'prefix) [t|HsModule|])+prefix_HsName_But = $(everywhereBut (liftM not . inType [t|HsName|]) (const [|id|] `extN` 'prefix) [t|HsModule|]) ---------------------------------------- -- A useful helper for benchmarking