@@ -133,6 +133,7 @@ toNestedHaskellType
133133 -> Q Type
134134toNestedHaskellType typeParams haskellTypes = loop
135135 where
136+ predicate _ Scoped {} = False
136137 predicate dhallType haskellType = Core. judgmentallyEqual (code haskellType) dhallType
137138
138139 document dhallType =
@@ -262,6 +263,10 @@ toDeclaration globalGenerateOptions haskellTypes typ =
262263 MultipleConstructors {.. } -> uncurry (fromMulti globalGenerateOptions typeName) $ getTypeParams code
263264 MultipleConstructorsWith {.. } -> uncurry (fromMulti options typeName) $ getTypeParams code
264265 Predefined {} -> return []
266+ Scoped scopedHaskellTypes ->
267+ let haskellTypes' = haskellTypes <> scopedHaskellTypes
268+ in
269+ concat <$> traverse (toDeclaration globalGenerateOptions haskellTypes') scopedHaskellTypes
265270 where
266271#if MIN_VERSION_template_haskell(2,21,0)
267272 toTypeVar (V n i) = Syntax. PlainTV (Syntax. mkName (Text. unpack n ++ show i)) Syntax. BndrInvis
@@ -374,7 +379,8 @@ toConstructor typeParams GenerateOptions{..} haskellTypes outerTypeName (constru
374379
375380 case maybeAlternativeType of
376381 Just dhallType
377- | let predicate haskellType =
382+ | let predicate Scoped {} = False
383+ predicate haskellType =
378384 Core. judgmentallyEqual (code haskellType) dhallType
379385 && typeName haskellType /= outerTypeName
380386 , Just haskellType <- List. find predicate haskellTypes -> do
@@ -478,6 +484,8 @@ data HaskellType code
478484 , code :: code
479485 -- ^ Dhall code that evaluates to a type
480486 }
487+ -- | Generate some Haskell types within a restricted scope.
488+ | Scoped [HaskellType code ]
481489 deriving (Functor , Foldable , Traversable )
482490
483491-- | This data type holds various options that let you control several aspects
@@ -520,6 +528,8 @@ defaultGenerateOptions = GenerateOptions
520528-- I.e. those `Dhall.InterpretOptions` reflect the mapping done by
521529-- `constructorModifier` and `fieldModifier` on the value level.
522530generateToInterpretOptions :: GenerateOptions -> HaskellType (Expr s a ) -> Q Exp
531+ generateToInterpretOptions _ SingleConstructorWith {.. } = generateToInterpretOptions options SingleConstructor {.. }
532+ generateToInterpretOptions _ MultipleConstructorsWith {.. } = generateToInterpretOptions options MultipleConstructors {.. }
523533generateToInterpretOptions GenerateOptions {.. } haskellType = [| Dhall. InterpretOptions
524534 { Dhall. fieldModifier = \ $ (pure nameP) ->
525535 $ (toCases fieldModifier $ fields haskellType)
0 commit comments