@@ -133,6 +133,7 @@ toNestedHaskellType
133
133
-> Q Type
134
134
toNestedHaskellType typeParams haskellTypes = loop
135
135
where
136
+ predicate _ Scoped {} = False
136
137
predicate dhallType haskellType = Core. judgmentallyEqual (code haskellType) dhallType
137
138
138
139
document dhallType =
@@ -262,6 +263,10 @@ toDeclaration globalGenerateOptions haskellTypes typ =
262
263
MultipleConstructors {.. } -> uncurry (fromMulti globalGenerateOptions typeName) $ getTypeParams code
263
264
MultipleConstructorsWith {.. } -> uncurry (fromMulti options typeName) $ getTypeParams code
264
265
Predefined {} -> return []
266
+ Scoped scopedHaskellTypes ->
267
+ let haskellTypes' = haskellTypes <> scopedHaskellTypes
268
+ in
269
+ concat <$> traverse (toDeclaration globalGenerateOptions haskellTypes') scopedHaskellTypes
265
270
where
266
271
#if MIN_VERSION_template_haskell(2,21,0)
267
272
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
374
379
375
380
case maybeAlternativeType of
376
381
Just dhallType
377
- | let predicate haskellType =
382
+ | let predicate Scoped {} = False
383
+ predicate haskellType =
378
384
Core. judgmentallyEqual (code haskellType) dhallType
379
385
&& typeName haskellType /= outerTypeName
380
386
, Just haskellType <- List. find predicate haskellTypes -> do
@@ -478,6 +484,8 @@ data HaskellType code
478
484
, code :: code
479
485
-- ^ Dhall code that evaluates to a type
480
486
}
487
+ -- | Generate some Haskell types within a restricted scope.
488
+ | Scoped [HaskellType code ]
481
489
deriving (Functor , Foldable , Traversable )
482
490
483
491
-- | This data type holds various options that let you control several aspects
@@ -520,6 +528,8 @@ defaultGenerateOptions = GenerateOptions
520
528
-- I.e. those `Dhall.InterpretOptions` reflect the mapping done by
521
529
-- `constructorModifier` and `fieldModifier` on the value level.
522
530
generateToInterpretOptions :: GenerateOptions -> HaskellType (Expr s a ) -> Q Exp
531
+ generateToInterpretOptions _ SingleConstructorWith {.. } = generateToInterpretOptions options SingleConstructor {.. }
532
+ generateToInterpretOptions _ MultipleConstructorsWith {.. } = generateToInterpretOptions options MultipleConstructors {.. }
523
533
generateToInterpretOptions GenerateOptions {.. } haskellType = [| Dhall. InterpretOptions
524
534
{ Dhall. fieldModifier = \ $ (pure nameP) ->
525
535
$ (toCases fieldModifier $ fields haskellType)
0 commit comments