Skip to content

Commit 5c02e66

Browse files
committed
Dhall.TH: Allow overriding the Haskell type of a particular record field
1 parent ddb940e commit 5c02e66

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

dhall/src/Dhall/TH.hs

+6-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,9 @@ toConstructor typeParams GenerateOptions{..} haskellTypes outerTypeName (constru
393393

394394
Just (Record kts) -> do
395395
let process (key, dhallFieldType) = do
396-
haskellFieldType <- toNestedHaskellType typeParams haskellTypes dhallFieldType
396+
haskellFieldType <- case fieldType key of
397+
Nothing -> toNestedHaskellType typeParams haskellTypes dhallFieldType
398+
Just haskellFieldType -> return haskellFieldType
397399

398400
return (Syntax.mkName (Text.unpack $ fieldModifier key), bang, haskellFieldType)
399401

@@ -525,6 +527,8 @@ data GenerateOptions = GenerateOptions
525527
-- Note: The `constructorName` of `SingleConstructor` will be passed to this function, too.
526528
, fieldModifier :: Text -> Text
527529
-- ^ How to map a Dhall record field names to a Haskell record field names.
530+
, fieldType :: Text -> Maybe Type
531+
-- ^ Override the Haskell type used for a particular field of a Dhall record.
528532
, generateFromDhallInstance :: Bool
529533
-- ^ Generate a `FromDhall` instance for the Haskell type
530534
, generateToDhallInstance :: Bool
@@ -544,6 +548,7 @@ defaultGenerateOptions :: GenerateOptions
544548
defaultGenerateOptions = GenerateOptions
545549
{ constructorModifier = id
546550
, fieldModifier = id
551+
, fieldType = const Nothing
547552
, generateFromDhallInstance = True
548553
, generateToDhallInstance = True
549554
, makeStrict = False

0 commit comments

Comments
 (0)