Skip to content

Commit

Permalink
Dhall.TH: Allow overriding the Haskell type of a particular record field
Browse files Browse the repository at this point in the history
  • Loading branch information
mmhat committed Nov 19, 2024
1 parent ddb940e commit 5c02e66
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dhall/src/Dhall/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -544,6 +548,7 @@ defaultGenerateOptions :: GenerateOptions
defaultGenerateOptions = GenerateOptions
{ constructorModifier = id
, fieldModifier = id
, fieldType = const Nothing
, generateFromDhallInstance = True
, generateToDhallInstance = True
, makeStrict = False
Expand Down

0 comments on commit 5c02e66

Please sign in to comment.