Skip to content

Commit 2b4bb7e

Browse files
committed
Added Scoped to Dhall.TH
1 parent d2ee3c6 commit 2b4bb7e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

dhall/src/Dhall/TH.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ toNestedHaskellType
133133
-> Q Type
134134
toNestedHaskellType 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.
522530
generateToInterpretOptions :: GenerateOptions -> HaskellType (Expr s a) -> Q Exp
531+
generateToInterpretOptions _ SingleConstructorWith{..} = generateToInterpretOptions options SingleConstructor{..}
532+
generateToInterpretOptions _ MultipleConstructorsWith{..} = generateToInterpretOptions options MultipleConstructors{..}
523533
generateToInterpretOptions GenerateOptions{..} haskellType = [| Dhall.InterpretOptions
524534
{ Dhall.fieldModifier = \ $(pure nameP) ->
525535
$(toCases fieldModifier $ fields haskellType)

0 commit comments

Comments
 (0)