template-haskell-util 0.1.0.0 → 0.1.0.1
raw patch · 33 files changed
+113/−27 lines, 33 filesbinary-addedPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
Files
- .git/#COMMIT_EDITMSG# +26/−0
- .git/COMMIT_EDITMSG +5/−4
- .git/COMMIT_EDITMSG~ +7/−2
- .git/index binary
- .git/logs/HEAD +4/−0
- .git/logs/refs/heads/master +4/−0
- .git/logs/refs/remotes/origin/master +3/−0
- .git/objects/08/4a706a37d6164dfb1fab5dcd4e098bcdfe0ffa +2/−0
- .git/objects/0a/5c8b86bc82d2e802c87753d0d281666fb1d2cf binary
- .git/objects/11/85ce856677a3fab9b4b8152e7188867948cead binary
- .git/objects/1b/fe09ade13ffc3e9646506a8bd07d9f06282ca8 +3/−0
- .git/objects/1f/09cdb8471418bfb9d426a81124fc05387864de binary
- .git/objects/22/06167d3bd9beff796b124fc62b10cf920ddedc +1/−0
- .git/objects/26/b3e7dc8604f16cd517c71a150db8e193d71710 binary
- .git/objects/3b/c5e4c57a4d26371071febf2c9201f648327754 binary
- .git/objects/40/e84137de681e2b3710c60e78cca1b541967f6b binary
- .git/objects/45/ff6c45a9cb2bee78bb34a530229037cfac04dd binary
- .git/objects/48/c8e4a7b86032067949768c343e0673410a676c binary
- .git/objects/4a/96e90bdb920aa512ecdbdaa5f8d901f67e4a9a binary
- .git/objects/60/f79d207a4fdc123ed588c5e07108374dc4c596 binary
- .git/objects/78/3415d3261400ad2ad430037813a214e5742735 binary
- .git/objects/80/0d936c649cb85b2c545007389fdd4a161b8241 binary
- .git/objects/83/0ac91299ed1575b3936ea9e541fedc2c38399e binary
- .git/objects/83/775c596675f20802bddca97764740eed061457 binary
- .git/objects/98/b8bcf2f60d6e4d17e63fd4a4802182ad732501 binary
- .git/objects/9d/75ddda94952b2353bcb98b30ffa96708137edb binary
- .git/objects/b9/913ee76376fa16f1fbd6d525f8da421f33df57 binary
- .git/objects/be/3fb7a2051f825f8d2a8b3d299a604abf2b5244 +1/−0
- .git/refs/heads/master +1/−1
- .git/refs/remotes/origin/master +1/−1
- README.md +7/−6
- src/Language/Haskell/TH/Utils.hs +46/−12
- template-haskell-util.cabal +2/−1
@@ -0,0 +1,26 @@++# Please enter the commit message for your changes. Lines starting+# with '#' will be ignored, and an empty message aborts the commit.+# On branch master+# Your branch is up-to-date with 'origin/master'.+#+# Changes to be committed:+# modified: src/Language/Haskell/TH/Utils.hs+# modified: template-haskell-util.cabal+#+# Changes not staged for commit:+# deleted: dist/build/HStemplate-haskell-util-0.1.0.0.o+# deleted: dist/build/Language/Haskell/TH/Utils.hi+# deleted: dist/build/Language/Haskell/TH/Utils.o+# deleted: dist/build/autogen/Paths_template_haskell_util.hs+# deleted: dist/build/autogen/cabal_macros.h+# deleted: dist/build/libHStemplate-haskell-util-0.1.0.0.a+# deleted: dist/package.conf.inplace/package.cache+# deleted: dist/package.conf.inplace/template-haskell-util-0.1.0.0-inplace.conf+# deleted: dist/setup-config+# deleted: dist/setup/setup.hs+# deleted: dist/setup/setup.version+#+# Untracked files:+# #README.md#+#
@@ -1,9 +1,10 @@-update readme+ # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master-# Your branch is up-to-date with 'origin/master'.+# Your branch is ahead of 'origin/master' by 2 commits.+# (use "git push" to publish your local commits) #-# Changes to be committed:-# modified: README.md+# Untracked files:+# #README.md# #
@@ -2,8 +2,13 @@ # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master-# Your branch is up-to-date with 'origin/master'.+# Your branch is ahead of 'origin/master' by 1 commit.+# (use "git push" to publish your local commits) # # Changes to be committed:-# modified: README.md+# modified: src/Language/Haskell/TH/Utils.hs+# modified: template-haskell-util.cabal+#+# Untracked files:+# #README.md# #
binary file changed (1576 → 440 bytes)
@@ -1,3 +1,7 @@ 0000000000000000000000000000000000000000 6a35d077429c47159fd674466174acd97eb207b8 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424579505 +0800 clone: from https://github.com/HaskellZhangSong/TemplateHaskellUtils.git 6a35d077429c47159fd674466174acd97eb207b8 1d5ed8a5bd5a630d659dac826f1d251b60317469 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424584157 +0800 commit: updated some basic functions 1d5ed8a5bd5a630d659dac826f1d251b60317469 d1247d5c2308a73ca68c144ce67b060d3023b385 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424584417 +0800 commit: update readme+d1247d5c2308a73ca68c144ce67b060d3023b385 be3fb7a2051f825f8d2a8b3d299a604abf2b5244 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424586988 +0800 commit: changed readme+be3fb7a2051f825f8d2a8b3d299a604abf2b5244 084a706a37d6164dfb1fab5dcd4e098bcdfe0ffa HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424587127 +0800 commit: update me+084a706a37d6164dfb1fab5dcd4e098bcdfe0ffa 9d75ddda94952b2353bcb98b30ffa96708137edb HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424591499 +0800 commit: delete somefiles+9d75ddda94952b2353bcb98b30ffa96708137edb 3bc5e4c57a4d26371071febf2c9201f648327754 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424591528 +0800 commit: update on some functions
@@ -1,3 +1,7 @@ 0000000000000000000000000000000000000000 6a35d077429c47159fd674466174acd97eb207b8 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424579505 +0800 clone: from https://github.com/HaskellZhangSong/TemplateHaskellUtils.git 6a35d077429c47159fd674466174acd97eb207b8 1d5ed8a5bd5a630d659dac826f1d251b60317469 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424584157 +0800 commit: updated some basic functions 1d5ed8a5bd5a630d659dac826f1d251b60317469 d1247d5c2308a73ca68c144ce67b060d3023b385 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424584417 +0800 commit: update readme+d1247d5c2308a73ca68c144ce67b060d3023b385 be3fb7a2051f825f8d2a8b3d299a604abf2b5244 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424586988 +0800 commit: changed readme+be3fb7a2051f825f8d2a8b3d299a604abf2b5244 084a706a37d6164dfb1fab5dcd4e098bcdfe0ffa HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424587127 +0800 commit: update me+084a706a37d6164dfb1fab5dcd4e098bcdfe0ffa 9d75ddda94952b2353bcb98b30ffa96708137edb HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424591499 +0800 commit: delete somefiles+9d75ddda94952b2353bcb98b30ffa96708137edb 3bc5e4c57a4d26371071febf2c9201f648327754 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424591528 +0800 commit: update on some functions
@@ -1,2 +1,5 @@ 6a35d077429c47159fd674466174acd97eb207b8 1d5ed8a5bd5a630d659dac826f1d251b60317469 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424584206 +0800 update by push 1d5ed8a5bd5a630d659dac826f1d251b60317469 d1247d5c2308a73ca68c144ce67b060d3023b385 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424584455 +0800 update by push+d1247d5c2308a73ca68c144ce67b060d3023b385 be3fb7a2051f825f8d2a8b3d299a604abf2b5244 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424587031 +0800 update by push+be3fb7a2051f825f8d2a8b3d299a604abf2b5244 084a706a37d6164dfb1fab5dcd4e098bcdfe0ffa HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424587175 +0800 update by push+084a706a37d6164dfb1fab5dcd4e098bcdfe0ffa 3bc5e4c57a4d26371071febf2c9201f648327754 HaskellZhangSong <Haskell.Zhang.Song@hotmail.com> 1424591608 +0800 update by push
@@ -0,0 +1,2 @@+xÎË+Â0 a×yì L®îݹ+6M©éû[ÅGpûñs8·ZÊ£Ip~×"ú^¢àMðÚ³æ}và8f´ ÙÌ.Ld8å4ÇoÉÐ÷èÅÄX+pmC]ä_OÇëÓýR§»<ü¤ûR÷±ÓP[ÁÇØÝj9JmÁº4¹WQ)±év¹Ñ_ÆÄ:gl$7AxSI
binary file changed (absent → 44 bytes)
binary file changed (absent → 199 bytes)
@@ -0,0 +1,3 @@+xmSMoÔ0åÚHþsF³[D+mEÔr`7'Äù~=ãl²¾Åoæù½Ú¸n?¼SðhuÔÂ@Ä~0"b©Dø Æ)jÃQÖ¡EOzæ6ðÕy`Ñ´ÉG ¤kR6¨½*Æá®ªf^î|WMU+èCÙ%-±b+¬èñ^ÿêbÅoj¥.ËW|ÍW|Å0Z7.àë²+2Z¾ÃÃÁ4g ÄÐx=dù§î©µM¶É×¢zÝ©5Ql?+-.åïñâDwé0Ï&Ðp:UªyãújòS Ûííªý¼øA+nÐK6x~ܲտ?=~Þ~ÛmY!RTάMãôÎ_Å^hZ¦m,³ñ,é£rJ)®¶ß¸aôygm2Ó9?ßÂùJ4VÔIYÆq8ÉØiÊ!ø½(K¾ÁÉJ^æ÷í§/Ï[ÞËÌMÉ,_Åà~³ækÚBí Y/(ËÞÉdhòåt)|±¸àÓx®®æ\Lùv9Ý'x`ZHÎÇd7c´òÅZP>6wü-Àõ1(Ëo÷¸á·¹[ žÔ~i¾ÉÄV$K3szrvq³Z¯þÝ)k
binary file changed (absent → 50 bytes)
@@ -0,0 +1,1 @@+xuÎAK1`ÏùzQÜ=´ÒKЫ°8éNÈL´þxm5Ìyã;<l·7+ttÁ*í|Po:1YhÈC¼< N9C_iT^j¸ôàù>èdIbÊk[|ã)Æ0Ã"¢à¡¬ÄD"ÅF{×`Ý`s¨|IXc³Tm/§Ý}ù_hQ+°ÎÊ hÊ^955|RRô¶+qÑ-ü¯ýÌS·à])õeúÃÿ;\=æLùÒ\W±ÝnÓ
binary file changed (absent → 226 bytes)
binary file changed (absent → 180 bytes)
binary file changed (absent → 53 bytes)
binary file changed (absent → 49 bytes)
binary file changed (absent → 50 bytes)
binary file changed (absent → 44 bytes)
binary file changed (absent → 930 bytes)
binary file changed (absent → 198 bytes)
binary file changed (absent → 1270 bytes)
binary file changed (absent → 540 bytes)
binary file changed (absent → 52 bytes)
binary file changed (absent → 50 bytes)
binary file changed (absent → 174 bytes)
binary file changed (absent → 226 bytes)
@@ -0,0 +1,1 @@+xλNA aêyéVö\)B)ééè¼¶ÉFìì Íðþl@wôG¿ôÖnÃOc7;ƪPôE4ct&ÃSÔÁ}ñnÛð!UÍ"×(\H0%±Rg( B#eÇßcé»åû§ëûÂÛõoWþé¦]>ßÖIz{ñBÊTNDþÀz$û3'S¿k3÷¿&SÒ
@@ -1,1 +1,1 @@-d1247d5c2308a73ca68c144ce67b060d3023b385+3bc5e4c57a4d26371071febf2c9201f648327754
@@ -1,1 +1,1 @@-d1247d5c2308a73ca68c144ce67b060d3023b385+3bc5e4c57a4d26371071febf2c9201f648327754
@@ -2,11 +2,12 @@ useful functions for you to write template Haskell code some examples--- | Apply a list of expression [(+), 1, 2] to (+) 1 2- appExp :: [ExpQ] -> ExpQ --- | Apply a type constructor, convert [a, b, c] to a b c- appConT :: [TypeQ] -> TypeQ+ -- | Apply a list of expression [(+), 1, 2] to (+) 1 2+ appExp :: [ExpQ] -> ExpQ --- | convert [a, b, c] to a -> b -> c- curryType :: [TypeQ] -> TypeQ+ -- | Apply a type constructor, convert [a, b, c] to a b c+ appConT :: [TypeQ] -> TypeQ++ -- | convert [a, b, c] to a -> b -> c+ curryType :: [TypeQ] -> TypeQ
@@ -1,9 +1,9 @@ module Language.Haskell.TH.Utils( - appExp, - appConT, - curryType, - genBT, - genPE, + appExp, appExp', + appConT, appConT', + curryType, curryType', + genBT, genBT', + genPE, genPE', appKinds, curryKind, getTypeNames, @@ -16,19 +16,38 @@ import Language.Haskell.TH.Lib import Data.List (foldl1,foldr1) --- | Apply a list of expression [(+), 1, 2] to (+) 1 2 +-- | Apply a list of expression, [(+), 1, 2] to (+) 1 2 appExp :: [ExpQ] -> ExpQ appExp = appsE --- | Apply a type constructor, convert [a, b, c] to a b c +appExp' :: [Exp] -> Exp +appExp' = foldl1 AppE + +-- | Apply a type constructor, convert [a, b, c] to a b c like 'appExp' appConT :: [TypeQ] -> TypeQ appConT = foldl1 appT +appConT' :: [Type] -> Type +appConT' = foldl1 AppT + +{-| +> > pprint $ appConT' (map ConT [''(,), ''Int , ''Bool]) +> "GHC.Tuple.(,) GHC.Types.Int GHC.Types.Bool" +|-} + -- | convert [a, b, c] to a -> b -> c curryType :: [TypeQ] -> TypeQ curryType = foldr1 (\t1 -> appT (appT arrowT t1)) --- | Bind and Type +curryType' :: [Type] -> Type +curryType' = foldr1 (\t1 -> AppT (AppT ArrowT t1)) + +{-| +> > pprint $ curryType' (map ConT [''Int , ''Int , ''Bool]) +> "GHC.Types.Int -> GHC.Types.Int -> GHC.Types.Bool" +|-} + +-- | Generate a list of type Bind and Type genBT :: String -> Int -> Q ([TyVarBndr], [TypeQ]) genBT name n = do let ns = [name++ (show i) | i <- [1..n]] @@ -36,6 +55,15 @@ typ <- sequence $ map (return.varT.mkName) ns return (tvb,typ) +genBT' :: String -> Int -> ([TyVarBndr], [Type]) +genBT' name n = let ns = [name++ (show i) | i <- [1..n]] + in (map (plainTV.mkName) ns, map (VarT . mkName) ns) + +{-| +> > genBT' "a" 3 +> ([PlainTV a1,PlainTV a2,PlainTV a3],[VarT a1,VarT a2,VarT a3]) +|-} + -- | Pattern and expression genPE :: String -> Int -> Q ([PatQ],[ExpQ]) genPE name n = do @@ -44,13 +72,20 @@ exp <- sequence $ map (return.varE.mkName) ns return (pat,exp) +genPE' :: String -> Int -> ([Pat], [Exp]) +genPE' name n = let ns = [name++ (show i) | i <- [1..n]] + in (map (VarP . mkName) ns,map (VarE . mkName) ns) +{-| +> > genPE' "a" 3 +> ([VarP a1,VarP a2,VarP a3],[VarE a1,VarE a2,VarE a3]) +|-} -- | Apply a list of kinds appKinds :: [Kind] -> Kind appKinds = foldr1 AppT --- | [k1,k2,k3] to k1 -> k2 -> k3 +-- | convert [k1,k2,k3] to k1 -> k2 -> k3,like 'curryType' curryKind :: [Kind] -> Kind -curryKind = foldr1 (\t1 -> appK (appK arrowK t1)) +curryKind = curryType' -- | get type Names recursively getTypeNames :: Type -> [Name] @@ -64,7 +99,6 @@ getTVBName (PlainTV name ) = name getTVBName (KindedTV name _) = name - third (a,b,c) = c -- | get all names recursively from a constructor @@ -72,6 +106,6 @@ getCompositeType (NormalC n sts) = concatMap getTypeNames (map snd sts) getCompositeType (RecC n vars) = concatMap getTypeNames (map third vars) getCompositeType (InfixC st1 n st2) = concatMap getTypeNames [snd st1 , snd st2] - --v this could be a problem since it will lose info for context and type variables +-- This could be a problem since it will lose info for context and type variables getCompositeType (ForallC tvbs cxt con) = getCompositeType con
@@ -2,7 +2,7 @@ -- further documentation, see http://haskell.org/cabal/users-guide/ name: template-haskell-util -version: 0.1.0.0 +version: 0.1.0.1 synopsis: Some utilities for template Haskell. description: Some functions that might be useful when you use template haskell. homepage: https://github.com/HaskellZhangSong/TemplateHaskellUtils @@ -11,6 +11,7 @@ author: songzh maintainer: Haskell.Zhang.Song@hotmail.com -- copyright: +stability: experimental category: Language build-type: Simple extra-source-files: README.md