Skip to content

Commit

Permalink
Added more documentation for Scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
mmhat committed Oct 21, 2024
1 parent d0b1f20 commit ddb940e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions dhall/src/Dhall/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit ddb940e

Please sign in to comment.