th-abstraction 0.4.0.0 → 0.4.1.0
raw patch · 4 files changed
+38/−24 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog.md +5/−0
- src/Language/Haskell/TH/Datatype.hs +25/−15
- test/Main.hs +7/−8
- th-abstraction.cabal +1/−1
ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for th-abstraction +## 0.4.1.0 -- 2020-12-09+* Fix a bug in which `normalizeDec` would give incorrect kind annotations to+ type variables in quoted `Dec`s. `normalizeDec` now leaves the kinds of+ type variable binders alone.+ ## 0.4.0.0 -- 2020-09-29 * Adapt to the `TyVarBndr` data type gaining a new `flag` type parameter (in `template-haskell-2.17.0.0`) to represent its specificity:
src/Language/Haskell/TH/Datatype.hs view
@@ -718,7 +718,7 @@ let tvbs' = tvbs ++ extra_tvbs instTys' = instTys ++ bndrParams extra_tvbs dec <- normalizeDec' isReified context name tvbs' instTys' cons variant- repair13618' $ giveDIVarsStarKinds dec+ repair13618' $ giveDIVarsStarKinds isReified dec -- | Create new kind variable binder names corresponding to the return kind of -- a data type. This is useful when you have a data type like:@@ -801,7 +801,7 @@ Con {- ^ Constructor -} -> Q [ConstructorInfo] normalizeConFor reifiedDec typename params instTys variant =- fmap (map giveCIVarsStarKinds) . dispatch+ fmap (map (giveCIVarsStarKinds reifiedDec)) . dispatch where -- A GADT constructor is declared infix when: --@@ -1978,23 +1978,33 @@ -- On old versions of GHC, reify would not give you kind signatures for -- GADT type variables of kind *. To work around this, we insert the kinds--- manually on any types without a signature.+-- manually on any reified type variable binders without a signature. However,+-- don't do this for quoted type variable binders (#84). -giveDIVarsStarKinds :: DatatypeInfo -> DatatypeInfo-giveDIVarsStarKinds info =- info { datatypeVars = map giveTyVarBndrStarKind (datatypeVars info)- , datatypeInstTypes = map giveTypeStarKind (datatypeInstTypes info) }+giveDIVarsStarKinds :: IsReifiedDec -> DatatypeInfo -> DatatypeInfo+giveDIVarsStarKinds isReified info =+ info { datatypeVars = map (giveTyVarBndrStarKind isReified) (datatypeVars info)+ , datatypeInstTypes = map (giveTypeStarKind isReified) (datatypeInstTypes info) } -giveCIVarsStarKinds :: ConstructorInfo -> ConstructorInfo-giveCIVarsStarKinds info =- info { constructorVars = map giveTyVarBndrStarKind (constructorVars info) }+giveCIVarsStarKinds :: IsReifiedDec -> ConstructorInfo -> ConstructorInfo+giveCIVarsStarKinds isReified info =+ info { constructorVars = map (giveTyVarBndrStarKind isReified) (constructorVars info) } -giveTyVarBndrStarKind :: TyVarBndrUnit -> TyVarBndrUnit-giveTyVarBndrStarKind tvb = elimTV (\n -> kindedTV n starK) (\_ _ -> tvb) tvb+giveTyVarBndrStarKind :: IsReifiedDec -> TyVarBndrUnit -> TyVarBndrUnit+giveTyVarBndrStarKind isReified tvb+ | isReified+ = elimTV (\n -> kindedTV n starK) (\_ _ -> tvb) tvb+ | otherwise+ = tvb -giveTypeStarKind :: Type -> Type-giveTypeStarKind t@(VarT n) = SigT t starK-giveTypeStarKind t = t+giveTypeStarKind :: IsReifiedDec -> Type -> Type+giveTypeStarKind isReified t+ | isReified+ = case t of+ VarT n -> SigT t starK+ _ -> t+ | otherwise+ = t -- | Prior to GHC 8.2.1, reify was broken for data instances and newtype -- instances. This code attempts to detect the problem and repair it if
test/Main.hs view
@@ -426,7 +426,7 @@ , datatypeCons = [ ConstructorInfo { constructorName = mkName "MkFoo"- , constructorVars = [kindedTV a starK]+ , constructorVars = [plainTV a] , constructorContext = [] , constructorFields = [VarT a] , constructorStrictness = [notStrictAnnot]@@ -491,8 +491,8 @@ DatatypeInfo { datatypeName = mkName "Quoted" , datatypeContext = []- , datatypeVars = [kindedTV a starK]- , datatypeInstTypes = [SigT aVar starK]+ , datatypeVars = [plainTV a]+ , datatypeInstTypes = [aVar] , datatypeVariant = DataInstance , datatypeCons = [ ConstructorInfo@@ -620,15 +620,14 @@ $(do [dec] <- [d| data instance FamLocalDec2 Int (a, b) a = FamLocalDec2Int { fm0 :: (b, a), fm1 :: Int } |] info <- normalizeDec dec let names = map mkName ["a", "b"]- [aTvb,bTvb] = map (\v -> kindedTV v starK) names+ [aTvb,bTvb] = map plainTV names vars@[aVar,bVar] = map (VarT . mkName) ["a", "b"]- [aSig,bSig] = map (\v -> SigT v starK) vars validateDI info DatatypeInfo { datatypeName = ''FamLocalDec2 , datatypeContext = [] , datatypeVars = [aTvb,bTvb]- , datatypeInstTypes = [ConT ''Int, TupleT 2 `AppT` aVar `AppT` bVar, aSig]+ , datatypeInstTypes = [ConT ''Int, TupleT 2 `AppT` aVar `AppT` bVar, aVar] , datatypeVariant = DataInstance , datatypeCons = [ ConstructorInfo@@ -841,9 +840,9 @@ DatatypeInfo { datatypeName = mkName "Foo" , datatypeContext = []- , datatypeVars = [ kindedTV a starK, kindedTV b starK+ , datatypeVars = [ plainTV a, plainTV b , kindedTV f fKind, kindedTV x starK ]- , datatypeInstTypes = [ SigT (VarT a) starK, SigT (VarT b) starK+ , datatypeInstTypes = [ VarT a, VarT b , SigT (VarT f) fKind, SigT (VarT x) starK ] , datatypeVariant = Datatype , datatypeCons =
th-abstraction.cabal view
@@ -1,5 +1,5 @@ name: th-abstraction-version: 0.4.0.0+version: 0.4.1.0 synopsis: Nicer interface for reified information about data types description: This package normalizes variations in the interface for inspecting datatype information via Template Haskell