@@ -132,6 +132,7 @@ toNestedHaskellType
132
132
-> Q Type
133
133
toNestedHaskellType typeParams haskellTypes = loop
134
134
where
135
+ predicate _ Scoped {} = False
135
136
predicate dhallType haskellType = Core. judgmentallyEqual (code haskellType) dhallType
136
137
137
138
document dhallType =
@@ -261,6 +262,10 @@ toDeclaration globalGenerateOptions haskellTypes typ =
261
262
MultipleConstructors {.. } -> uncurry (fromMulti globalGenerateOptions typeName) $ getTypeParams code
262
263
MultipleConstructorsWith {.. } -> uncurry (fromMulti options typeName) $ getTypeParams code
263
264
Predefined {} -> return []
265
+ Scoped scopedHaskellTypes ->
266
+ let haskellTypes' = haskellTypes <> scopedHaskellTypes
267
+ in
268
+ concat <$> traverse (toDeclaration globalGenerateOptions haskellTypes') scopedHaskellTypes
264
269
where
265
270
toTypeVar (V n i) = Syntax. PlainTV $ Syntax. mkName (Text. unpack n ++ show i)
266
271
@@ -367,7 +372,8 @@ toConstructor typeParams GenerateOptions{..} haskellTypes outerTypeName (constru
367
372
368
373
case maybeAlternativeType of
369
374
Just dhallType
370
- | let predicate haskellType =
375
+ | let predicate Scoped {} = False
376
+ predicate haskellType =
371
377
Core. judgmentallyEqual (code haskellType) dhallType
372
378
&& typeName haskellType /= outerTypeName
373
379
, Just haskellType <- List. find predicate haskellTypes -> do
@@ -471,6 +477,8 @@ data HaskellType code
471
477
, code :: code
472
478
-- ^ Dhall code that evaluates to a type
473
479
}
480
+ -- | Generate some Haskell types within a restricted scope.
481
+ | Scoped [HaskellType code ]
474
482
deriving (Functor , Foldable , Traversable )
475
483
476
484
-- | This data type holds various options that let you control several aspects
@@ -513,6 +521,8 @@ defaultGenerateOptions = GenerateOptions
513
521
-- I.e. those `Dhall.InterpretOptions` reflect the mapping done by
514
522
-- `constructorModifier` and `fieldModifier` on the value level.
515
523
generateToInterpretOptions :: GenerateOptions -> HaskellType (Expr s a ) -> Q Exp
524
+ generateToInterpretOptions _ SingleConstructorWith {.. } = generateToInterpretOptions options SingleConstructor {.. }
525
+ generateToInterpretOptions _ MultipleConstructorsWith {.. } = generateToInterpretOptions options MultipleConstructors {.. }
516
526
generateToInterpretOptions GenerateOptions {.. } haskellType = [| Dhall. InterpretOptions
517
527
{ Dhall. fieldModifier = \ $ (pure nameP) ->
518
528
$ (toCases fieldModifier $ fields haskellType)
0 commit comments