This fully resolves, type checks, and normalizes the expression, so the
resulting AST is self-contained.
This can be used to resolve all of an expression’s imports at compile time,
allowing one to reference Dhall expressions from Haskell without having a
runtime dependency on the location of Dhall files.
For example, given a file "./Some/Type.dhall" containing
< This : Natural | Other : ../Other/Type.dhall >
... rather than duplicating the AST manually in a Haskell Dhall.Type, you
can do:
This would create the Dhall Expr AST from the "./Some/Type.dhall" file
at compile time with all imports resolved, making it easy to keep your Dhall
configs and Haskell interpreters in sync.
This quoter is build on top of staticDhallExpression. Therefore consult the
documentation of that function for further information.
This quoter is meant to be used in expression context only; Other contexts
like pattern contexts or declaration contexts are not supported and will
result in an error.
Generate a Haskell datatype declaration with one constructor from a Dhall
type.
This comes in handy if you need to keep Dhall types and Haskell types in
sync. You make the Dhall types the source of truth and use Template Haskell
to generate the matching Haskell type declarations from the Dhall types.
-- ./Employee.dhall
{ name : Text, department : ./Department.dhall }
... this Template Haskell splice:
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
Dhall.TH.makeHaskellTypes
[ MultipleConstructors "Department" "./tests/th/Department.dhall"
, SingleConstructor "Employee" "MakeEmployee" "./tests/th/Employee.dhall"
]
... generates this Haskell code:
data Department = Engineering | Marketing | Sales
deriving stock (GHC.Generics.Generic)
deriving anyclass (Dhall.FromDhall, Dhall.ToDhall)
data Employee
= MakeEmployee {department :: Department,
name :: Data.Text.Internal.Text}
deriving stock (GHC.Generics.Generic)
deriving anyclass (Dhall.FromDhall, Dhall.ToDhall)
Carefully note that the conversion makes a best-effort attempt to
auto-detect when a Dhall type (like ./Employee.dhall) refers to another
Dhall type (like ./Department.dhall) and replaces that reference with the
corresponding Haskell type.
This Template Haskell splice requires you to enable the following extensions:
DeriveGeneric
DerivingAnyClass
DerivingStrategies
By default, the generated types only derive Generic,
FromDhall, and ToDhall. To add any desired instances (such
as Eq/Ord/Show), you can use the StandaloneDeriving language
extension, like this:
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
Dhall.TH.makeHaskellTypes
[ MultipleConstructors "Department" "./tests/th/Department.dhall"
, SingleConstructor "Employee" "MakeEmployee" "./tests/th/Employee.dhall"
]
deriving instance Eq Department
deriving instance Ord Department
deriving instance Show Department
deriving instance Eq Employee
deriving instance Ord Employee
deriving instance Show Employee