talira

th-abstraction

One interface to Template Haskell's datatype information across GHC versions

open sourceISCfree

th-abstraction is a Haskell library for authors of Template Haskell code. It gives a single, consistent view of the reified information about datatypes, newtypes and data family instances, hiding the differences between normal and GADT syntax and between Template Haskell versions, so a deriving library or code generator can support many GHC releases with one code path. Its modules are Language.Haskell.TH.Datatype and Language.Haskell.TH.Datatype.TyVarBndr. Install it from Hackage as th-abstraction.

Problems it solves

  • my Template Haskell deriving code breaks on every new GHC release
  • write Template Haskell that handles GADTs and ordinary data types the same way
  • inspect a data type's constructors and fields from Template Haskell across GHC versions

Features

  • normalized reified datatype, newtype and data family instance information
  • hides normal versus GADT syntax differences
  • supports many Template Haskell versions
  • tested on GHC 8.0 to 9.14

Alternatives

The same job

These do what th-abstraction does.

  1. th-lift Derive Template Haskell's Lift class for datatypes
  2. generic-deriving Generic programming library for generalised deriving in Haskell

Compare th-abstraction with the top 3