From 101b60386ec8380cc3a62154bc7c1c53205f5d59 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Tue, 26 Aug 2025 21:39:37 +0000 Subject: Improves formatting even more --- hsm-core/Hsm/Core/Serial.hs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'hsm-core/Hsm/Core/Serial.hs') 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) [] -- cgit v1.2.1