th-desugar v1.9 Release Notes
-
Suppose GHC 8.6.
➕ Add support for
DerivingVia
. Correspondingly, there is now aDDerivStrategy
data type.➕ Add support for
QuantifiedConstraints
. Correspondingly, there is now aDForallPr
constructor inDPred
to represent quantified constraint types.✂ Remove the
DStarT
constructor ofDType
in favor ofDConT ''Type
. Two utility functions have been added toLanguage.Haskell.TH.Desugar
to ease this transition:isTypeKindName
: returnsTrue
if the argumentName
is that ofType
or★
(or*
, to support older GHCs).typeKindName
: the name ofType
(on GHC 8.0 or later) or*
(on older GHCs).
th-desugar
now desugars all data types to GADT syntax. The most significant API-facing changes resulting from this new design are:- The
DDataD
,DDataFamilyD
, andDDataFamInstD
constructors ofDDec
now haveMaybe DKind
fields that either haveJust
an explicit return kind (e.g., thek -> Type -> Type
indata Foo :: k -> Type -> Type
) orNothing
(if lacking an explicit return kind). - The
DCon
constructor previously had a field of typeMaybe DType
, since there was a possibility it could be a GADT (with an explicit return type) or non-GADT (without an explicit return type) constructor. Since all data types are desugared to GADTs now, this field has been changed to be simply aDType
. - The type signature of
dsCon
was previously:
dsCon :: DsMonad q => Con -> q [DCon]
However, desugaring constructors now needs more information than before, since GADT constructors have richer type signatures. Accordingly, the type of
dsCon
is now:dsCon :: DsMonad q => [DTyVarBndr] -- ^ The universally quantified type variables -- (used if desugaring a non-GADT constructor) -> DType -- ^ The original data declaration's type -- (used if desugaring a non-GADT constructor). -> Con -> q [DCon]
The
instance Desugar [Con] [DCon]
has also been removed, as the previous implementation ofdesugar
(concatMapM dsCon
) no longer has enough information to work.- The
Some other utility functions have also been added as part of this change:
A
conExistentialTvbs
function has been introduced to determine the existentially quantified type variables of aDCon
. Note that this function is not 100% accurate—refer to the documentation forconExistentialTvbs
for more information.A
mkExtraDKindBinders
function has been introduced to turn a data type's return kind into explicit, fresh type variable binders.A
toposortTyVarsOf
function, which finds the free variables of a list ofDType
s and returns them in a well scoped list that has been sorted in reverse topological order.th-desugar
now desugars partial pattern matches indo
-notation and list/monad comprehensions to the appropriate invocation offail
. (Previously, these were incorrectly desugared intocase
expressions with incomplete patterns.)- ➕ Add a
mkDLamEFromDPats
function for constructing aDLamE
expression using a list ofDPat
arguments and aDExp
body. - ➕ Add an
unravel
function for decomposing a function type into itsforall
'd type variables, its context, its argument types, and its result type. - Export a
substTyVarBndrs
function fromLanguage.Haskell.TH.Desugar.Subst
, which substitutes over type variable binders in a capture-avoiding fashion. getDataD
,dataConNameToDataName
, anddataConNameToCon
fromLanguage.Haskell.TH.Desugar.Reify
now look up local declarations. As a result, the contexts in their type signatures have been strengthened fromQuasi
toDsMonad
.- Export a
dTyVarBndrToDType
function which converts aDTyVarBndr
to aDType
, which preserves its kind. - Previously,
th-desugar
would silently accept illegal uses of record construction with fields that did not belong to the constructor, such asIdentity { notAField = "wat" }
. This is now an error.