From 5c02e66bf59bef1e29047ad85aa6ae73836018de Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Tue, 19 Nov 2024 15:33:11 +0100 Subject: [PATCH] Dhall.TH: Allow overriding the Haskell type of a particular record field --- dhall/src/Dhall/TH.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dhall/src/Dhall/TH.hs b/dhall/src/Dhall/TH.hs index 403ac9635..ebc0ba231 100644 --- a/dhall/src/Dhall/TH.hs +++ b/dhall/src/Dhall/TH.hs @@ -393,7 +393,9 @@ toConstructor typeParams GenerateOptions{..} haskellTypes outerTypeName (constru Just (Record kts) -> do let process (key, dhallFieldType) = do - haskellFieldType <- toNestedHaskellType typeParams haskellTypes dhallFieldType + haskellFieldType <- case fieldType key of + Nothing -> toNestedHaskellType typeParams haskellTypes dhallFieldType + Just haskellFieldType -> return haskellFieldType return (Syntax.mkName (Text.unpack $ fieldModifier key), bang, haskellFieldType) @@ -525,6 +527,8 @@ data GenerateOptions = GenerateOptions -- Note: The `constructorName` of `SingleConstructor` will be passed to this function, too. , fieldModifier :: Text -> Text -- ^ How to map a Dhall record field names to a Haskell record field names. + , fieldType :: Text -> Maybe Type + -- ^ Override the Haskell type used for a particular field of a Dhall record. , generateFromDhallInstance :: Bool -- ^ Generate a `FromDhall` instance for the Haskell type , generateToDhallInstance :: Bool @@ -544,6 +548,7 @@ defaultGenerateOptions :: GenerateOptions defaultGenerateOptions = GenerateOptions { constructorModifier = id , fieldModifier = id + , fieldType = const Nothing , generateFromDhallInstance = True , generateToDhallInstance = True , makeStrict = False