Added Template Haskell helper functions
darcs-hash:20070823120526-a4fee-4d3fcf18768f5be81a81309d003f991c269ca136
This commit is contained in:
parent
dc47984bf6
commit
1e3524e478
33
Data/Encoding/Helper/Template.hs
Normal file
33
Data/Encoding/Helper/Template.hs
Normal file
@ -0,0 +1,33 @@
|
||||
{- This module is used to create arrays from lists in template haskell -}
|
||||
|
||||
module Data.Encoding.Helper.Template where
|
||||
|
||||
import Data.Char
|
||||
import Data.Word
|
||||
import Data.Array.IArray (Array,array)
|
||||
import Language.Haskell.TH
|
||||
|
||||
createCharArray :: [(Integer,Char)] -> Integer -> Integer -> Q Exp
|
||||
#ifndef __HADDOCK__
|
||||
createCharArray lst = createArray (map (\(x,y) -> (x,LitE $ CharL y)) lst)
|
||||
#endif
|
||||
|
||||
createArray :: [(Integer,Exp)] -> Integer -> Integer -> Q Exp
|
||||
#ifndef __HADDOCK__
|
||||
createArray lst from to = return $ AppE
|
||||
(AppE
|
||||
(VarE 'array)
|
||||
(TupE [LitE $ IntegerL from,LitE $ IntegerL to]))
|
||||
(ListE [ TupE [LitE $ IntegerL x,y]
|
||||
| (x,y) <- lst ])
|
||||
#endif
|
||||
|
||||
xmlArray :: [(Char,[Word8])] -> Integer -> Integer -> Q Exp
|
||||
#ifndef __HADDOCK__
|
||||
xmlArray lst l u = do
|
||||
let trans = map (\(ch,bin) ->
|
||||
(toInteger $ ord ch
|
||||
,TupE [LitE $ IntegerL (toInteger $ length bin),TupE $ map (\b -> LitE $ IntegerL (fromIntegral b)) bin ++ replicate (4-length bin) (LitE $ IntegerL 0)]
|
||||
)) (filter (\(c,_) -> ord c <= fromInteger u && ord c >= fromInteger l) lst)
|
||||
createArray trans l u
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user