@@ -132,6 +132,7 @@ toNestedHaskellType
132132 -> Q Type
133133toNestedHaskellType typeParams haskellTypes = loop
134134 where
135+ predicate _ Scoped {} = False
135136 predicate dhallType haskellType = Core. judgmentallyEqual (code haskellType) dhallType
136137
137138 document dhallType =
@@ -261,6 +262,10 @@ toDeclaration globalGenerateOptions haskellTypes typ =
261262 MultipleConstructors {.. } -> uncurry (fromMulti globalGenerateOptions typeName) $ getTypeParams code
262263 MultipleConstructorsWith {.. } -> uncurry (fromMulti options typeName) $ getTypeParams code
263264 Predefined {} -> return []
265+ Scoped scopedHaskellTypes ->
266+ let haskellTypes' = haskellTypes <> scopedHaskellTypes
267+ in
268+ concat <$> traverse (toDeclaration globalGenerateOptions haskellTypes') scopedHaskellTypes
264269 where
265270 toTypeVar (V n i) = Syntax. PlainTV $ Syntax. mkName (Text. unpack n ++ show i)
266271
@@ -367,7 +372,8 @@ toConstructor typeParams GenerateOptions{..} haskellTypes outerTypeName (constru
367372
368373 case maybeAlternativeType of
369374 Just dhallType
370- | let predicate haskellType =
375+ | let predicate Scoped {} = False
376+ predicate haskellType =
371377 Core. judgmentallyEqual (code haskellType) dhallType
372378 && typeName haskellType /= outerTypeName
373379 , Just haskellType <- List. find predicate haskellTypes -> do
@@ -471,6 +477,8 @@ data HaskellType code
471477 , code :: code
472478 -- ^ Dhall code that evaluates to a type
473479 }
480+ -- | Generate some Haskell types within a restricted scope.
481+ | Scoped [HaskellType code ]
474482 deriving (Functor , Foldable , Traversable )
475483
476484-- | This data type holds various options that let you control several aspects
@@ -513,6 +521,8 @@ defaultGenerateOptions = GenerateOptions
513521-- I.e. those `Dhall.InterpretOptions` reflect the mapping done by
514522-- `constructorModifier` and `fieldModifier` on the value level.
515523generateToInterpretOptions :: GenerateOptions -> HaskellType (Expr s a ) -> Q Exp
524+ generateToInterpretOptions _ SingleConstructorWith {.. } = generateToInterpretOptions options SingleConstructor {.. }
525+ generateToInterpretOptions _ MultipleConstructorsWith {.. } = generateToInterpretOptions options MultipleConstructors {.. }
516526generateToInterpretOptions GenerateOptions {.. } haskellType = [| Dhall. InterpretOptions
517527 { Dhall. fieldModifier = \ $ (pure nameP) ->
518528 $ (toCases fieldModifier $ fields haskellType)
0 commit comments