From 4d3ffe07fc154c5d9d777eb9040104a7e433320e Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Sun, 24 Sep 2023 00:37:52 +0200 Subject: [PATCH] Added more documentation for Scoped --- dhall/src/Dhall/TH.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/dhall/src/Dhall/TH.hs b/dhall/src/Dhall/TH.hs index d2b7d39d4..403ac9635 100644 --- a/dhall/src/Dhall/TH.hs +++ b/dhall/src/Dhall/TH.hs @@ -487,6 +487,30 @@ data HaskellType code -- ^ Dhall code that evaluates to a type } -- | Generate some Haskell types within a restricted scope. + -- + -- Suppose generate your types using the following code: + -- + -- > data MyBool = MyFalse | MyTrue + -- > + -- > Dhall.TH.makeHaskellTypes + -- > [ SingleConstructor "ListOfBool" "ListOfBool" "List Bool" + -- > , Scoped + -- > [ Predefined (TH.ConT ''MyBool) "Bool" + -- > , SingleConstructor "ListOfMyBool" "ListOfMyBool" "List Bool" + -- > ] + -- > , SingleConstructor "ListOfBoolAgain" "ListOfBoolAgain" "List Bool" + -- > ] + -- + -- This generates the following Haskell types: + -- + -- > data ListOfBool = ListOfBool Bool + -- > data ListOfMyBool = ListOfMyBool MyBool + -- > data ListOfBoolAgain = ListOfBoolAgain Bool + -- + -- Therefore @Scoped@ allows you to override the type mapping locally. This + -- is especially handy in conjunction with @Predefined@, as it allows you to + -- use different representations of a Dhall type, e.g. a Dhall @List@ can be + -- a Haskell @Vector@, @Seq@ or a good old linked list. | Scoped [HaskellType code] deriving (Functor, Foldable, Traversable)