Skip to content

Commit dfa4bf5

Browse files
committed
Added more documentation for Scoped
1 parent cb8cf9a commit dfa4bf5

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
@@ -487,6 +487,30 @@ data HaskellType code
487487
-- ^ Dhall code that evaluates to a type
488488
}
489489
-- | Generate some Haskell types within a restricted scope.
490+
--
491+
-- Suppose generate your types using the following code:
492+
--
493+
-- > data MyBool = MyFalse | MyTrue
494+
-- >
495+
-- > Dhall.TH.makeHaskellTypes
496+
-- > [ SingleConstructor "ListOfBool" "ListOfBool" "List Bool"
497+
-- > , Scoped
498+
-- > [ Predefined (TH.ConT ''MyBool) "Bool"
499+
-- > , SingleConstructor "ListOfMyBool" "ListOfMyBool" "List Bool"
500+
-- > ]
501+
-- > , SingleConstructor "ListOfBoolAgain" "ListOfBoolAgain" "List Bool"
502+
-- > ]
503+
--
504+
-- This generates the following Haskell types:
505+
--
506+
-- > data ListOfBool = ListOfBool Bool
507+
-- > data ListOfMyBool = ListOfMyBool MyBool
508+
-- > data ListOfBoolAgain = ListOfBoolAgain Bool
509+
--
510+
-- Therefore @Scoped@ allows you to override the type mapping locally. This
511+
-- is especially handy in conjunction with @Predefined@, as it allows you to
512+
-- use different representations of a Dhall type, e.g. a Dhall @List@ can be
513+
-- a Haskell @Vector@, @Seq@ or a good old linked list.
490514
| Scoped [HaskellType code]
491515
deriving (Functor, Foldable, Traversable)
492516

0 commit comments

Comments
 (0)