mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-12-03 03:52:10 +03:00
Use common TH functions in names-th.
This commit is contained in:
parent
14f3af698a
commit
104ebe4756
@ -23,6 +23,7 @@ import Data.Map (Map, fromList, (!))
|
||||
import qualified Data.Map as Map
|
||||
import Data.Time (LocalTime, Day)
|
||||
import Language.Haskell.TH (Q, Type)
|
||||
import qualified Language.Haskell.TH.Name.Extra as TH
|
||||
|
||||
import Database.HDBC (IConnection)
|
||||
|
||||
@ -185,10 +186,7 @@ putLog :: String -> IO ()
|
||||
putLog = putStrLn . logPrefix
|
||||
|
||||
compileErrorIO :: String -> IO a
|
||||
compileErrorIO = Base.compileErrorIO . logPrefix
|
||||
|
||||
compileError :: String -> Q a
|
||||
compileError = Base.compileError . logPrefix
|
||||
compileErrorIO = TH.compileErrorIO . logPrefix
|
||||
|
||||
getPrimaryKey' :: IConnection conn
|
||||
=> conn
|
||||
|
@ -14,6 +14,7 @@ module Database.HDBC.Schema.PostgreSQL (
|
||||
) where
|
||||
|
||||
import Language.Haskell.TH (Q, Type)
|
||||
import qualified Language.Haskell.TH.Name.Extra as TH
|
||||
|
||||
import Data.Int (Int16, Int32, Int64)
|
||||
import Data.Char (toLower)
|
||||
@ -167,7 +168,7 @@ putLog :: String -> IO ()
|
||||
putLog = putStrLn . logPrefix
|
||||
|
||||
compileErrorIO :: String -> IO a
|
||||
compileErrorIO = Base.compileErrorIO . logPrefix
|
||||
compileErrorIO = TH.compileErrorIO . logPrefix
|
||||
|
||||
getPrimaryKey' :: IConnection conn
|
||||
=> conn
|
||||
|
@ -19,8 +19,6 @@ module Database.HDBC.TH (
|
||||
|
||||
derivingEq, derivingShow, derivingRead, derivingData, derivingTypable,
|
||||
|
||||
compileErrorIO, compileError,
|
||||
|
||||
defineRecordType,
|
||||
defineRecordConstructFunction,
|
||||
definePersistableInstance,
|
||||
@ -54,10 +52,12 @@ import Language.Haskell.TH.Name.CamelCase
|
||||
conCamelcaseName, varCamelcaseName,
|
||||
varNameWithPrefix,
|
||||
toTypeCon)
|
||||
import Language.Haskell.TH.Name.Extra
|
||||
(integralE, simpleValD, compileError)
|
||||
import Language.Haskell.TH
|
||||
(Q, Name, mkName, runIO,
|
||||
TypeQ, ExpQ, DecQ, Dec,
|
||||
appsE, conE, varE, listE, litE, stringE, integerL,
|
||||
(Q, mkName, runIO,
|
||||
TypeQ, DecQ, Dec,
|
||||
appsE, conE, varE, listE, stringE,
|
||||
listP, varP, wildP,
|
||||
conT,
|
||||
dataD, sigD, funD, valD,
|
||||
@ -99,18 +99,9 @@ derivingData = conCamelcaseName "Data"
|
||||
derivingTypable = conCamelcaseName "Typable"
|
||||
derivingEq, derivingShow, derivingRead, derivingData, derivingTypable :: ConName
|
||||
|
||||
compileErrorIO :: String -> IO a
|
||||
compileErrorIO = ioError . userError
|
||||
|
||||
compileError :: String -> Q a
|
||||
compileError = runIO . compileErrorIO
|
||||
|
||||
mayDeclare :: (a -> Q [Dec]) -> Maybe a -> Q [Dec]
|
||||
mayDeclare = maybe (return [])
|
||||
|
||||
integralE :: Integral a => a -> ExpQ
|
||||
integralE = litE . integerL . toInteger
|
||||
|
||||
defineRecordType :: ConName -- ^ Name of the data type of table record type.
|
||||
-> [(VarName, TypeQ)] -- ^ List of fields in the table. Must be legal, properly cased record fields.
|
||||
-> [ConName] -- ^ Deriving type class names.
|
||||
@ -146,12 +137,6 @@ defineRecordConstructFunction funName' typeName' width = do
|
||||
[] ]
|
||||
return [sig, var]
|
||||
|
||||
simpleValD :: Name -> TypeQ -> ExpQ -> Q [Dec]
|
||||
simpleValD var typ expr = do
|
||||
sig <- sigD var typ
|
||||
val <- valD (varP var) (normalB expr) []
|
||||
return [sig, val]
|
||||
|
||||
defineTableInfo :: VarName -> String
|
||||
-> VarName -> [String]
|
||||
-> VarName -> Int
|
||||
|
Loading…
Reference in New Issue
Block a user