packages feed

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)

+ Language.Haskell.TH.Utils: appConT' :: [Type] -> Type
+ Language.Haskell.TH.Utils: appExp' :: [Exp] -> Exp
+ Language.Haskell.TH.Utils: curryType' :: [Type] -> Type
+ Language.Haskell.TH.Utils: genBT' :: String -> Int -> ([TyVarBndr], [Type])
+ Language.Haskell.TH.Utils: genPE' :: String -> Int -> ([Pat], [Exp])

Files

+ .git/#COMMIT_EDITMSG# view
@@ -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#+#
.git/COMMIT_EDITMSG view
@@ -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# #
.git/COMMIT_EDITMSG~ view
@@ -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# #
.git/index view

binary file changed (1576 → 440 bytes)

.git/logs/HEAD view
@@ -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
.git/logs/refs/heads/master view
@@ -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
.git/logs/refs/remotes/origin/master view
@@ -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
+ .git/objects/08/4a706a37d6164dfb1fab5dcd4e098bcdfe0ffa view
@@ -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
+ .git/objects/0a/5c8b86bc82d2e802c87753d0d281666fb1d2cf view

binary file changed (absent → 44 bytes)

+ .git/objects/11/85ce856677a3fab9b4b8152e7188867948cead view

binary file changed (absent → 199 bytes)

+ .git/objects/1b/fe09ade13ffc3e9646506a8bd07d9f06282ca8 view
@@ -0,0 +1,3 @@+xmSMoÔ0åÚHþsF³[D+m‚E­Ôr`—7'žÄŽù~=ãl²¾Åoæù½™—Ú¸n?¼S–ðhuÔÂ@Ä~0"b©Dø…Æ”)jÃQÖ¡EO˜„z„Õ¦6ðÕy`Ñ´ÉG…¤kR6Ѝ½†€*Æá®ªf^î|WMU+èCÙ%-±b+¬èñ^ÿêbÅoj¥.ËW|ÍW|Ŋ0Z7.àë²+2ŒZ’¾ÃÃÁ4g…ÄÐx=dù§î©µM¶É×¢zÝ©5Ql“?+-Œ.åïñ⚊žDwé0Ï&Ðp:Uªyãúj–òS	Ûíœíªý¼™øA+ŒnІK6x~ܑ²Õæ?=~Þ~ÛmY!RTΟ¬MãôÎ_Ŋ^hZ¦mŸ,³™ñ,é£r‘J)®Ÿ¶ß¸aôygm”‹†2Ó9?žßÂùJ4VÔIYÆq8ÉØiÊ!ø½(ƒK¾ÁÉJ^æ÷í§/Ï[ÞËÌMÉ,_Åà~³ækÚBí…Y€/ƒ(ËÞÉdhòåt)|±¸àÓx®®æš\Lùv9Ý'Šx‘`ZHÎÇd7cƒ´ò˜ÅZP>6›wü-Àõ1(Ëo÷¸á·¹[…žÔ~i¾É˜ÄV$K3szrvq³Z¯þ’Ý)k
+ .git/objects/1f/09cdb8471418bfb9d426a81124fc05387864de view

binary file changed (absent → 50 bytes)

+ .git/objects/22/06167d3bd9beff796b124fc62b10cf920ddedc view
@@ -0,0 +1,1 @@+xuÎAK1`ÏùzQÜ=´ÒK‚ˆÐ«°ž–’8‹éNÈL´þx“m5—̃yã;<l·7+ttŒÁ*í­|Po:1YhÈCž¼Ž<	N˜9C_iT‚^j¸ôàùŒ>èd‹IbÊk[|ã)Æ0Ã"Œ¢à¡¬ÄD"ÅF{×`Ý`s¨|IXc³TmŒ/§ˆÝ}ù_hQ‡+°Î‘Ê
“hÊ^955|RRô¶+qÑ-ü¯ýÌS·à])ŸõeúÃÿƒ”;\=æLùœÒ\›W±ÝnÓ
+ .git/objects/26/b3e7dc8604f16cd517c71a150db8e193d71710 view

binary file changed (absent → 226 bytes)

+ .git/objects/3b/c5e4c57a4d26371071febf2c9201f648327754 view

binary file changed (absent → 180 bytes)

+ .git/objects/40/e84137de681e2b3710c60e78cca1b541967f6b view

binary file changed (absent → 53 bytes)

+ .git/objects/45/ff6c45a9cb2bee78bb34a530229037cfac04dd view

binary file changed (absent → 49 bytes)

+ .git/objects/48/c8e4a7b86032067949768c343e0673410a676c view

binary file changed (absent → 50 bytes)

+ .git/objects/4a/96e90bdb920aa512ecdbdaa5f8d901f67e4a9a view

binary file changed (absent → 44 bytes)

+ .git/objects/60/f79d207a4fdc123ed588c5e07108374dc4c596 view

binary file changed (absent → 930 bytes)

+ .git/objects/78/3415d3261400ad2ad430037813a214e5742735 view

binary file changed (absent → 198 bytes)

+ .git/objects/80/0d936c649cb85b2c545007389fdd4a161b8241 view

binary file changed (absent → 1270 bytes)

+ .git/objects/83/0ac91299ed1575b3936ea9e541fedc2c38399e view

binary file changed (absent → 540 bytes)

+ .git/objects/83/775c596675f20802bddca97764740eed061457 view

binary file changed (absent → 52 bytes)

+ .git/objects/98/b8bcf2f60d6e4d17e63fd4a4802182ad732501 view

binary file changed (absent → 50 bytes)

+ .git/objects/9d/75ddda94952b2353bcb98b30ffa96708137edb view

binary file changed (absent → 174 bytes)

+ .git/objects/b9/913ee76376fa16f1fbd6d525f8da421f33df57 view

binary file changed (absent → 226 bytes)

+ .git/objects/be/3fb7a2051f825f8d2a8b3d299a604abf2b5244 view
@@ -0,0 +1,1 @@+x­Î»NA…aêyŠé‘Vö\)B)ééè¼¶ÉFìì Íðþl@wôG¿ôÖnǂOc7;Æ­ªPôE4c•ŠŒt&ÃSԊÁ}ñnÛðŠ!UÍ"×(\H0%±Rg( Bœ#eÇßcé»åû§­ëûÂÛõ­oWþ“é—¦‡]–>ßÖIz{ñ˜BÊTNDþÀz$û—3'S¿k3÷¿&SÒ
.git/refs/heads/master view
@@ -1,1 +1,1 @@-d1247d5c2308a73ca68c144ce67b060d3023b385+3bc5e4c57a4d26371071febf2c9201f648327754
.git/refs/remotes/origin/master view
@@ -1,1 +1,1 @@-d1247d5c2308a73ca68c144ce67b060d3023b385+3bc5e4c57a4d26371071febf2c9201f648327754
README.md view
@@ -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
src/Language/Haskell/TH/Utils.hs view
@@ -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
 
template-haskell-util.cabal view
@@ -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