Skip to content

Commit fdba865

Browse files
committed
Added more documentation for Scoped
1 parent 45c7d88 commit fdba865

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

dhall/src/Dhall/TH.hs

+24
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,30 @@ data HaskellType code
480480
-- ^ Dhall code that evaluates to a type
481481
}
482482
-- | Generate some Haskell types within a restricted scope.
483+
--
484+
-- Suppose generate your types using the following code:
485+
--
486+
-- > data MyBool = MyFalse | MyTrue
487+
-- >
488+
-- > Dhall.TH.makeHaskellTypes
489+
-- > [ SingleConstructor "ListOfBool" "ListOfBool" "List Bool"
490+
-- > , Scoped
491+
-- > [ Predefined (TH.ConT ''MyBool) "Bool"
492+
-- > , SingleConstructor "ListOfMyBool" "ListOfMyBool" "List Bool"
493+
-- > ]
494+
-- > , SingleConstructor "ListOfBoolAgain" "ListOfBoolAgain" "List Bool"
495+
-- > ]
496+
--
497+
-- This generates the following Haskell types:
498+
--
499+
-- > data ListOfBool = ListOfBool Bool
500+
-- > data ListOfMyBool = ListOfMyBool MyBool
501+
-- > data ListOfBoolAgain = ListOfBoolAgain Bool
502+
--
503+
-- Therefore @Scoped@ allows you to override the type mapping locally. This
504+
-- is especially handy in conjunction with @Predefined@, as it allows you to
505+
-- use different representations of a Dhall type, e.g. a Dhall @List@ can be
506+
-- a Haskell @Vector@, @Seq@ or a good old linked list.
483507
| Scoped [HaskellType code]
484508
deriving (Functor, Foldable, Traversable)
485509

0 commit comments

Comments
 (0)