Skip to content

Commit 8a5c928

Browse files
committed
Allow building with GHC 9.0
This applies a couple of tweaks needed to adapt `hobbits` to changes to `template-haskell`'s `TyVarBndr` API in GHC 9.0 (see https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/9.0?version_id=5fcd0a50e0872efb3c38a32db140506da8310d87#template-haskell-217): * Since `PlainTV` and `KindedTV` now have an additional field, the `tvName` function from `th-abstraction` is now used to extract the `Name`s from these two constructors. `tvName` is designed to work across different versions of `template-haskell`. * A use of `TyVarBndr` was changed to `TyVarBndrUnit`. Again, the `th-abstraction` library is used to ensure that `TyVarBndrUnit` is always is in scope, even on old versions of `template-haskell`. * A use of `PlainTV` was changed to `plainTVSpecified` (offered by `th-abstraction`) to give it a `Specificity` on newer versions of `template-haskell`.
1 parent e591889 commit 8a5c928

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

hobbits.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Library
2828
, deepseq
2929
, haskell-src-exts >= 1.17.1 && < 2
3030
, haskell-src-meta
31+
, th-abstraction >= 0.4 && < 0.5
3132
, th-expand-syns >= 0.3 && < 0.5
3233
, transformers
3334
, containers

src/Data/Binding/Hobbits/NuMatching.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import qualified Data.Vector as Vector
4444
--import Data.Typeable
4545
import Language.Haskell.TH hiding (Name, Type(..), cxt, clause)
4646
import qualified Language.Haskell.TH as TH
47+
import Language.Haskell.TH.Datatype.TyVarBndr
4748
import Control.Monad.State
4849
import Numeric.Natural
4950
import Data.Functor.Constant
@@ -63,7 +64,7 @@ import Data.Binding.Hobbits.Internal.Closed
6364
mapNames :: NuMatching a => NameRefresher -> a -> a
6465
mapNames = mapNamesPf nuMatchingProof
6566

66-
matchDataDecl :: Dec -> Maybe (Cxt, TH.Name, [TyVarBndr], [Con])
67+
matchDataDecl :: Dec -> Maybe (Cxt, TH.Name, [TyVarBndrUnit], [Con])
6768
matchDataDecl (DataD cxt name tyvars _ constrs _) =
6869
Just (cxt, name, tyvars, constrs)
6970
matchDataDecl (NewtypeD cxt name tyvars _ constr _) =
@@ -314,7 +315,7 @@ mkNuMatching tQ =
314315
$ AppE (ConE 'MbTypeReprData)
315316
$ AppE (ConE 'MkMbTypeReprData)
316317
$ LetE [SigD fName
317-
$ TH.ForallT (map PlainTV tyvars) cxt mapNamesT,
318+
$ TH.ForallT (map plainTVSpecified tyvars) cxt mapNamesT,
318319
FunD fName clauses]
319320
(VarE fName)) []]]
320321

@@ -329,10 +330,6 @@ mkNuMatching tQ =
329330
(VarE fname))
330331
-}
331332
where
332-
-- extract the name from a TyVarBndr
333-
tyBndrToName (PlainTV n) = n
334-
tyBndrToName (KindedTV n _) = n
335-
336333
-- fail for getMbTypeReprInfo
337334
getMbTypeReprInfoFail t extraMsg =
338335
fail ("mkMbTypeRepr: " ++ show t
@@ -351,7 +348,7 @@ mkNuMatching tQ =
351348
where
352349
success tyvarsReq constrs =
353350
let tyvarsRet = if tyvars == [] && ctx == []
354-
then map tyBndrToName tyvarsReq
351+
then map tvName tyvarsReq
355352
else tyvars in
356353
return (ctx,
357354
foldl TH.AppT (TH.ConT tName) (map TH.VarT tyvars),

0 commit comments

Comments
 (0)