This package provides the
Language.Haskell.TH.Desugar module, which desugars
Template Haskell’s rich encoding of Haskell syntax into a simpler encoding.
This desugaring discards surface syntax information (such as the use of infix
operators) but retains the original meaning of the TH code. The intended use
of this package is as a preprocessor for more advanced code manipulation
tools. Note that the input to any of the
ds... functions should be produced
from a TH quote, using the syntax
[| ... |]. If the input to these functions
is a hand-coded TH syntax tree, the results may be unpredictable. In
particular, it is likely that promoted datatypes will not work as expected.
One explicit goal of this package is to reduce the burden of supporting multiple GHC / TH versions. Thus, the desugared language is the same across all GHC versions, and any inconsistencies are handled internally.
The package was designed for use with the
singletons package, so some design
decisions are based on that use case, when more than one design choice was
I will try to keep this package up-to-date with respect to changes in GHC.
th-desugar release notes
Support GHC 8.4.
substTynow properly substitutes into kind signatures.
fvDType, which computes the free variables of a
DNormalCto indicate if it is a constructor that was declared infix.
mkTypeNameWithLocals, counterparts to
mkTypeNamewhich have access to local Template Haskell declarations.
reifyNameSpaceto determine a
matchTy(among other goodies) from new module
Language.Haskell.TH.Subst. This function matches a type template against a target.
Support for TH’s support for
TypeApplications, thanks to @RyanGlScott.
Support for unboxed sums, thanks to @RyanGlScott.
getRecordSelectorsnow requires a list of
DCons as an argument. This makes it easier to return correct record selector bindings in the event that a record selector appears in multiple constructors. (See goldfirere/singletons#180 for an example of where the old behavior of
Better type family expansion (expanding an open type family with variables works now).
Work with GHC 8, with thanks to @christiaanb for getting this change going. This means that several core datatypes have changed: partcularly, we now have
DTypeFamilyHeadand fixities are now reified separately from other things.
DKindis merged with
Genericinstances for everything.
- Fix issue #34. This means that desugaring (twice) is idempotent over expressions, after the second time. That is, if you desugar an expression, sweeten it, desugar again, sweeten again, and then desugar a third time, you get the same result as when you desugared the second time. (The extra round-trip is necessary there to make the output smaller in certain common cases.)
- Fix issue #32, concerning reification of classes with default methods.
DsMonadinstances, thanks to David Fox.
- Sweeten kinds more, too.
Thanks to David Fox (@ddssff), sweetening now tries to use more of TH’s
Also thanks to David Fox, depend usefully on the th-orphans package.
There is now a facility to register a list of
Decthat internal reification should use when necessary. This avoids the user needing to break up their definition across different top-level splices. See
withLocalDeclarations. This has a side effect of changing the
Quasitypeclass constraint on many functions to be the new
DsMonadconstraint. Happily, there are
IO, the two normal inhabitants of
“Match flattening” is implemented! The functions
scLetDecremove any nested pattern matches.
More is now exported from
Language.Haskell.TH.Desugarfor ease of use.
expandcan now expand closed type families! It still requires that the type to expand contain no type variables.
Support for standalone-deriving and default signatures in GHC 7.10. This means that there are now two new constructors for
staticexpressions, which are new in GHC 7.10.
expandfunctions now consider open type families, as long as the type to be expanded has no free variables.
Language.Haskell.TH.Desugar.Lift, which provides
Liftinstances for all of the th-desugar types, as well as several Template Haskell types.
applyDTypeas convenience functions.
Decs can now be desugared, to the new
Decs that do not exist in GHC 7.6.3- works on a “best effort” basis: closed type families are sweetened to open ones, and role annotations are dropped.
Infos can now be desugared. Desugaring takes into account GHC bug #8884, which meant that reifying poly-kinded type families in GHC 7.6.3- was subtly wrong.
There is a new function
flattenDValDwhich takes a binding like
let (a,b) = fooand breaks it apart into separate assignments for
There is a new
Desugarclass with methods
sweeten. See the documentation in
Variable names that are distinct in desugared code are now guaranteed to have distinct answers to
Added a new function
getRecordSelectorsthat extracts types and definitions of record selectors from a datatype definition.
- Update cabal file to include testing files in sdist.
- Update to work with
type Pred = Typein GHC 7.9. This changed the
DPredtype for all GHC versions, though.
- Generalized interface to allow any member of the
Qausiclass, instead of just
- Made compatible with HEAD after change in role annotation syntax.
- Added module
Language.Haskell.TH.Desugar.Expand, which allows for expansion of type synonyms in desugared types.
Datainstances to desugared types.
- Fixed bug where an as-pattern in a
letstatement was scoped incorrectly.
- Changed signature of
dsPatto be more specific to as-patterns; this allowed for fixing the
- Created new functions
dsPatsOverExpto allow for easy desugaring of patterns.
- Changed signature of
dsLetDecto return a list of
dsLetDecsfor convenience. Now, instead of using
mapM dsLetDec, you should use
- Initial release