diff options
Diffstat (limited to 'hsm-core/Hsm')
-rw-r--r-- | hsm-core/Hsm/Core/Serial.hs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/hsm-core/Hsm/Core/Serial.hs b/hsm-core/Hsm/Core/Serial.hs index a0efca3..a672fca 100644 --- a/hsm-core/Hsm/Core/Serial.hs +++ b/hsm-core/Hsm/Core/Serial.hs @@ -36,13 +36,17 @@ import Language.Haskell.TH -- Generates a data type `GPIOPin` with constructors `GPIO2`, `GPIO3` `GPIO4`, -- and a function `pinLine :: GPIOPin -> Int`. makeSerial :: String -> String -> String -> Name -> [Int] -> Q [Dec] -makeSerial name suffix mapFun mapType idxs = - return [DataD [] dtName [] Nothing (idxCons <$> idxs) [derivClause], SigD mapFunName . AppT (AppT ArrowT $ ConT dtName) $ ConT mapType, FunD mapFunName $ mapFunClause <$> idxs] +makeSerial name suffix mapFunction mapType indices = + return + [ DataD [] dataName [] Nothing (indexCons <$> indices) [deriveClause] + , SigD mapFunctionName . AppT (AppT ArrowT $ ConT dataName) $ ConT mapType + , FunD mapFunctionName $ mapFunctionClause <$> indices + ] where - dtName = mkName $ name <> suffix - idxName idx = mkName $ name <> show idx - idxCons idx = NormalC (idxName idx) [] - derivClause = DerivClause Nothing [ConT ''Bounded, ConT ''Enum, ConT ''Show] - mapFunName = mkName mapFun - mapFunBody = NormalB . LitE . IntegerL . integerFromInt - mapFunClause idx = Clause [ConP (idxName idx) [] []] (mapFunBody idx) [] + dataName = mkName $ name <> suffix + indexName index = mkName $ name <> show index + indexCons index = NormalC (indexName index) [] + deriveClause = DerivClause Nothing [ConT ''Bounded, ConT ''Enum, ConT ''Show] + mapFunctionName = mkName mapFunction + mapFunctionBody = NormalB . LitE . IntegerL . integerFromInt + mapFunctionClause index = Clause [ConP (indexName index) [] []] (mapFunctionBody index) [] |