Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ghc-9.0.1 #8

Merged
merged 2 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/Language/Haskell/TH/Extras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Data.Set (Set)
import qualified Data.Set as Set
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Language.Haskell.TH.Datatype.TyVarBndr

intIs64 :: Bool
intIs64 = toInteger (maxBound :: Int) > 2^(32 :: Integer)
Expand Down Expand Up @@ -46,16 +47,10 @@ argTypesOfCon (GadtC _ args _) = map snd args
argTypesOfCon (RecGadtC _ args _) = [t | (_,_,t) <- args]
#endif

nameOfBinder :: TyVarBndr -> Name
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 700
nameOfBinder (PlainTV n) = n
nameOfBinder (KindedTV n _) = n
#else
nameOfBinder = id
type TyVarBndr = Name
#endif
nameOfBinder :: TyVarBndr_ a -> Name
nameOfBinder = tvName

varsBoundInCon :: Con -> [TyVarBndr]
varsBoundInCon :: Con -> [TyVarBndrSpec]
varsBoundInCon (ForallC bndrs _ con) = bndrs ++ varsBoundInCon con
varsBoundInCon _ = []

Expand Down Expand Up @@ -149,7 +144,7 @@ headOfType ty = error $ "headOfType: Unhandled type: " ++ show ty
occursInType :: Name -> Type -> Bool
occursInType var ty = case ty of
ForallT bndrs _ ty'
| any (var ==) (map nameOfBinder bndrs)
| any (var ==) (map tvName bndrs)
-> False
| otherwise
-> occursInType var ty'
Expand Down Expand Up @@ -182,7 +177,7 @@ substVarsWith topVars resultType argType = subst Set.empty argType
-- of Template Haskell.
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 710
ForallT bndrs cxt t ->
let bs' = Set.union bs (Set.fromList (map nameOfBinder bndrs))
let bs' = Set.union bs (Set.fromList (map tvName bndrs))
in ForallT bndrs (map (subst bs') cxt) (subst bs' t)
#else
ForallT {} -> error "substVarsWith: ForallT substitutions have not been implemented for GHCs prior to 7.10"
Expand Down Expand Up @@ -251,7 +246,7 @@ tyConArity n = do
-- its declaration, and the arity of the kind of type being defined (i.e. how many more arguments would
-- need to be supplied in addition to the bound parameters in order to obtain an ordinary type of kind *).
-- If the supplied 'Name' is anything other than a data or newtype, produces an error.
tyConArity' :: Name -> Q ([TyVarBndr], Int)
tyConArity' :: Name -> Q ([TyVarBndrUnit], Int)
tyConArity' n = do
r <- reify n
return $ case r of
Expand Down
7 changes: 4 additions & 3 deletions th-extras.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: th-extras
version: 0.0.0.4
stability: experimental

cabal-version: >= 1.6
cabal-version: >= 1.8
build-type: Simple

author: James Cook <[email protected]>
Expand Down Expand Up @@ -34,7 +34,8 @@ Library
exposed-modules: Language.Haskell.TH.Extras
build-depends: base >= 3 && < 5,
containers,
template-haskell

template-haskell < 2.18,
th-abstraction >= 0.4 && < 0.5

if flag(base4)
build-depends: base >= 4, syb