summaryrefslogtreecommitdiff
path: root/libraries/template-haskell/Language
diff options
context:
space:
mode:
authorGert-Jan Bottu <gertjan.bottu@kuleuven.be>2020-03-23 09:36:28 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-05-21 12:11:31 -0400
commita9311cd53d33439e8fe79967ba5fb85bcd114fec (patch)
tree2254ef735a24f9de8d192203a3c6f4871a8b6ae9 /libraries/template-haskell/Language
parent55f0e783d234af103cf4e1d51cd31c99961c5abe (diff)
downloadhaskell-a9311cd53d33439e8fe79967ba5fb85bcd114fec.tar.gz
Explicit Specificity
Implementation for Ticket #16393. Explicit specificity allows users to manually create inferred type variables, by marking them with braces. This way, the user determines which variables can be instantiated through visible type application. The additional syntax is included in the parser, allowing users to write braces in type variable binders (type signatures, data constructors etc). This information is passed along through the renamer and verified in the type checker. The AST for type variable binders, data constructors, pattern synonyms, partial signatures and Template Haskell has been updated to include the specificity of type variables. Minor notes: - Bumps haddock submodule - Disables pattern match checking in GHC.Iface.Type with GHC 8.8
Diffstat (limited to 'libraries/template-haskell/Language')
-rw-r--r--libraries/template-haskell/Language/Haskell/TH.hs1
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Lib.hs35
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs54
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Ppr.hs26
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Syntax.hs38
5 files changed, 94 insertions, 60 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH.hs b/libraries/template-haskell/Language/Haskell/TH.hs
index 693a80fc3d..36529e54dc 100644
--- a/libraries/template-haskell/Language/Haskell/TH.hs
+++ b/libraries/template-haskell/Language/Haskell/TH.hs
@@ -85,6 +85,7 @@ module Language.Haskell.TH(
Pat(..), FieldExp, FieldPat,
-- ** Types
Type(..), TyVarBndr(..), TyLit(..), Kind, Cxt, Pred, Syntax.Role(..),
+ Syntax.Specificity(..),
FamilyResultSig(..), Syntax.InjectivityAnn(..), PatSynType, BangType, VarBangType,
-- * Library functions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Lib.hs b/libraries/template-haskell/Language/Haskell/TH/Lib.hs
index 0ec932d00b..4df23cd3c5 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Lib.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Lib.hs
@@ -18,12 +18,13 @@ module Language.Haskell.TH.Lib (
-- * Library functions
-- ** Abbreviations
- InfoQ, ExpQ, TExpQ, DecQ, DecsQ, ConQ, TypeQ, KindQ, TyVarBndrQ,
+ InfoQ, ExpQ, TExpQ, DecQ, DecsQ, ConQ, TypeQ, KindQ,
TyLitQ, CxtQ, PredQ, DerivClauseQ, MatchQ, ClauseQ, BodyQ, GuardQ,
StmtQ, RangeQ, SourceStrictnessQ, SourceUnpackednessQ, BangQ,
BangTypeQ, VarBangTypeQ, StrictTypeQ, VarStrictTypeQ, FieldExpQ, PatQ,
FieldPatQ, RuleBndrQ, TySynEqnQ, PatSynDirQ, PatSynArgsQ,
FamilyResultSigQ, DerivStrategyQ,
+ TyVarBndrUnit, TyVarBndrSpec,
-- ** Constructors lifted to 'Q'
-- *** Literals
@@ -75,6 +76,8 @@ module Language.Haskell.TH.Lib (
-- *** Type variable binders
plainTV, kindedTV,
+ plainInvisTV, kindedInvisTV,
+ specifiedSpec, inferredSpec,
-- *** Roles
nominalR, representationalR, phantomR, inferR,
@@ -174,10 +177,10 @@ import Prelude
-------------------------------------------------------------------------------
-- * Dec
-tySynD :: Quote m => Name -> [TyVarBndr] -> m Type -> m Dec
+tySynD :: Quote m => Name -> [TyVarBndr ()] -> m Type -> m Dec
tySynD tc tvs rhs = do { rhs1 <- rhs; return (TySynD tc tvs rhs1) }
-dataD :: Quote m => m Cxt -> Name -> [TyVarBndr] -> Maybe Kind -> [m Con] -> [m DerivClause]
+dataD :: Quote m => m Cxt -> Name -> [TyVarBndr ()] -> Maybe Kind -> [m Con] -> [m DerivClause]
-> m Dec
dataD ctxt tc tvs ksig cons derivs =
do
@@ -186,7 +189,7 @@ dataD ctxt tc tvs ksig cons derivs =
derivs1 <- sequenceA derivs
return (DataD ctxt1 tc tvs ksig cons1 derivs1)
-newtypeD :: Quote m => m Cxt -> Name -> [TyVarBndr] -> Maybe Kind -> m Con -> [m DerivClause]
+newtypeD :: Quote m => m Cxt -> Name -> [TyVarBndr ()] -> Maybe Kind -> m Con -> [m DerivClause]
-> m Dec
newtypeD ctxt tc tvs ksig con derivs =
do
@@ -195,7 +198,7 @@ newtypeD ctxt tc tvs ksig con derivs =
derivs1 <- sequenceA derivs
return (NewtypeD ctxt1 tc tvs ksig con1 derivs1)
-classD :: Quote m => m Cxt -> Name -> [TyVarBndr] -> [FunDep] -> [m Dec] -> m Dec
+classD :: Quote m => m Cxt -> Name -> [TyVarBndr ()] -> [FunDep] -> [m Dec] -> m Dec
classD ctxt cls tvs fds decs =
do
decs1 <- sequenceA decs
@@ -230,35 +233,35 @@ newtypeInstD ctxt tc tys ksig con derivs =
derivs1 <- sequenceA derivs
return (NewtypeInstD ctxt1 Nothing ty1 ksig con1 derivs1)
-dataFamilyD :: Quote m => Name -> [TyVarBndr] -> Maybe Kind -> m Dec
+dataFamilyD :: Quote m => Name -> [TyVarBndr ()] -> Maybe Kind -> m Dec
dataFamilyD tc tvs kind
= pure $ DataFamilyD tc tvs kind
-openTypeFamilyD :: Quote m => Name -> [TyVarBndr] -> FamilyResultSig
+openTypeFamilyD :: Quote m => Name -> [TyVarBndr ()] -> FamilyResultSig
-> Maybe InjectivityAnn -> m Dec
openTypeFamilyD tc tvs res inj
= pure $ OpenTypeFamilyD (TypeFamilyHead tc tvs res inj)
-closedTypeFamilyD :: Quote m => Name -> [TyVarBndr] -> FamilyResultSig
+closedTypeFamilyD :: Quote m => Name -> [TyVarBndr ()] -> FamilyResultSig
-> Maybe InjectivityAnn -> [m TySynEqn] -> m Dec
closedTypeFamilyD tc tvs result injectivity eqns =
do eqns1 <- sequenceA eqns
return (ClosedTypeFamilyD (TypeFamilyHead tc tvs result injectivity) eqns1)
-tySynEqn :: Quote m => (Maybe [TyVarBndr]) -> m Type -> m Type -> m TySynEqn
+tySynEqn :: Quote m => (Maybe [TyVarBndr ()]) -> m Type -> m Type -> m TySynEqn
tySynEqn tvs lhs rhs =
do
lhs1 <- lhs
rhs1 <- rhs
return (TySynEqn tvs lhs1 rhs1)
-forallC :: Quote m => [TyVarBndr] -> m Cxt -> m Con -> m Con
+forallC :: Quote m => [TyVarBndr Specificity] -> m Cxt -> m Con -> m Con
forallC ns ctxt con = liftA2 (ForallC ns) ctxt con
-------------------------------------------------------------------------------
-- * Type
-forallT :: Quote m => [TyVarBndr] -> m Cxt -> m Type -> m Type
+forallT :: Quote m => [TyVarBndr Specificity] -> m Cxt -> m Type -> m Type
forallT tvars ctxt ty = do
ctxt1 <- ctxt
ty1 <- ty
@@ -273,11 +276,11 @@ sigT t k
-------------------------------------------------------------------------------
-- * Kind
-plainTV :: Name -> TyVarBndr
-plainTV = PlainTV
+plainTV :: Name -> TyVarBndr ()
+plainTV n = PlainTV n ()
-kindedTV :: Name -> Kind -> TyVarBndr
-kindedTV = KindedTV
+kindedTV :: Name -> Kind -> TyVarBndr ()
+kindedTV n k = KindedTV n () k
starK :: Kind
starK = StarT
@@ -294,7 +297,7 @@ noSig = NoSig
kindSig :: Kind -> FamilyResultSig
kindSig = KindSig
-tyVarSig :: TyVarBndr -> FamilyResultSig
+tyVarSig :: TyVarBndr () -> FamilyResultSig
tyVarSig = TyVarSig
-------------------------------------------------------------------------------
diff --git a/libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs b/libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs
index e401ff3e60..e5899dacb8 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs
@@ -37,7 +37,6 @@ type Decs = [Dec] -- Defined as it is more convenient to wire-in
type ConQ = Q Con
type TypeQ = Q Type
type KindQ = Q Kind
-type TyVarBndrQ = Q TyVarBndr
type TyLitQ = Q TyLit
type CxtQ = Q Cxt
type PredQ = Q Pred
@@ -67,6 +66,9 @@ type DerivStrategyQ = Q DerivStrategy
type Role = TH.Role
type InjectivityAnn = TH.InjectivityAnn
+type TyVarBndrUnit = TyVarBndr ()
+type TyVarBndrSpec = TyVarBndr Specificity
+
----------------------------------------------------------
-- * Lowercase pattern syntax functions
----------------------------------------------------------
@@ -385,14 +387,14 @@ funD nm cs =
; pure (FunD nm cs1)
}
-tySynD :: Quote m => Name -> [m TyVarBndr] -> m Type -> m Dec
+tySynD :: Quote m => Name -> [m (TyVarBndr ())] -> m Type -> m Dec
tySynD tc tvs rhs =
do { tvs1 <- sequenceA tvs
; rhs1 <- rhs
; pure (TySynD tc tvs1 rhs1)
}
-dataD :: Quote m => m Cxt -> Name -> [m TyVarBndr] -> Maybe (m Kind) -> [m Con]
+dataD :: Quote m => m Cxt -> Name -> [m (TyVarBndr ())] -> Maybe (m Kind) -> [m Con]
-> [m DerivClause] -> m Dec
dataD ctxt tc tvs ksig cons derivs =
do
@@ -403,7 +405,7 @@ dataD ctxt tc tvs ksig cons derivs =
derivs1 <- sequenceA derivs
pure (DataD ctxt1 tc tvs1 ksig1 cons1 derivs1)
-newtypeD :: Quote m => m Cxt -> Name -> [m TyVarBndr] -> Maybe (m Kind) -> m Con
+newtypeD :: Quote m => m Cxt -> Name -> [m (TyVarBndr ())] -> Maybe (m Kind) -> m Con
-> [m DerivClause] -> m Dec
newtypeD ctxt tc tvs ksig con derivs =
do
@@ -414,7 +416,7 @@ newtypeD ctxt tc tvs ksig con derivs =
derivs1 <- sequenceA derivs
pure (NewtypeD ctxt1 tc tvs1 ksig1 con1 derivs1)
-classD :: Quote m => m Cxt -> Name -> [m TyVarBndr] -> [FunDep] -> [m Dec] -> m Dec
+classD :: Quote m => m Cxt -> Name -> [m (TyVarBndr ())] -> [FunDep] -> [m Dec] -> m Dec
classD ctxt cls tvs fds decs =
do
tvs1 <- sequenceA tvs
@@ -477,7 +479,7 @@ pragSpecInstD ty
ty1 <- ty
pure $ PragmaD $ SpecialiseInstP ty1
-pragRuleD :: Quote m => String -> Maybe [m TyVarBndr] -> [m RuleBndr] -> m Exp -> m Exp
+pragRuleD :: Quote m => String -> Maybe [m (TyVarBndr ())] -> [m RuleBndr] -> m Exp -> m Exp
-> Phases -> m Dec
pragRuleD n ty_bndrs tm_bndrs lhs rhs phases
= do
@@ -499,7 +501,7 @@ pragLineD line file = pure $ PragmaD $ LineP line file
pragCompleteD :: Quote m => [Name] -> Maybe Name -> m Dec
pragCompleteD cls mty = pure $ PragmaD $ CompleteP cls mty
-dataInstD :: Quote m => m Cxt -> (Maybe [m TyVarBndr]) -> m Type -> Maybe (m Kind) -> [m Con]
+dataInstD :: Quote m => m Cxt -> (Maybe [m (TyVarBndr ())]) -> m Type -> Maybe (m Kind) -> [m Con]
-> [m DerivClause] -> m Dec
dataInstD ctxt mb_bndrs ty ksig cons derivs =
do
@@ -511,7 +513,7 @@ dataInstD ctxt mb_bndrs ty ksig cons derivs =
derivs1 <- sequenceA derivs
pure (DataInstD ctxt1 mb_bndrs1 ty1 ksig1 cons1 derivs1)
-newtypeInstD :: Quote m => m Cxt -> (Maybe [m TyVarBndr]) -> m Type -> Maybe (m Kind) -> m Con
+newtypeInstD :: Quote m => m Cxt -> (Maybe [m (TyVarBndr ())]) -> m Type -> Maybe (m Kind) -> m Con
-> [m DerivClause] -> m Dec
newtypeInstD ctxt mb_bndrs ty ksig con derivs =
do
@@ -529,20 +531,20 @@ tySynInstD eqn =
eqn1 <- eqn
pure (TySynInstD eqn1)
-dataFamilyD :: Quote m => Name -> [m TyVarBndr] -> Maybe (m Kind) -> m Dec
+dataFamilyD :: Quote m => Name -> [m (TyVarBndr ())] -> Maybe (m Kind) -> m Dec
dataFamilyD tc tvs kind =
do tvs' <- sequenceA tvs
kind' <- sequenceA kind
pure $ DataFamilyD tc tvs' kind'
-openTypeFamilyD :: Quote m => Name -> [m TyVarBndr] -> m FamilyResultSig
+openTypeFamilyD :: Quote m => Name -> [m (TyVarBndr ())] -> m FamilyResultSig
-> Maybe InjectivityAnn -> m Dec
openTypeFamilyD tc tvs res inj =
do tvs' <- sequenceA tvs
res' <- res
pure $ OpenTypeFamilyD (TypeFamilyHead tc tvs' res' inj)
-closedTypeFamilyD :: Quote m => Name -> [m TyVarBndr] -> m FamilyResultSig
+closedTypeFamilyD :: Quote m => Name -> [m (TyVarBndr ())] -> m FamilyResultSig
-> Maybe InjectivityAnn -> [m TySynEqn] -> m Dec
closedTypeFamilyD tc tvs result injectivity eqns =
do tvs1 <- sequenceA tvs
@@ -592,7 +594,7 @@ implicitParamBindD n e =
e' <- e
pure $ ImplicitParamBindD n e'
-tySynEqn :: Quote m => (Maybe [m TyVarBndr]) -> m Type -> m Type -> m TySynEqn
+tySynEqn :: Quote m => (Maybe [m (TyVarBndr ())]) -> m Type -> m Type -> m TySynEqn
tySynEqn mb_bndrs lhs rhs =
do
mb_bndrs1 <- traverse sequenceA mb_bndrs
@@ -631,7 +633,7 @@ infixC st1 con st2 = do st1' <- st1
st2' <- st2
pure $ InfixC st1' con st2'
-forallC :: Quote m => [m TyVarBndr] -> m Cxt -> m Con -> m Con
+forallC :: Quote m => [m (TyVarBndr Specificity)] -> m Cxt -> m Con -> m Con
forallC ns ctxt con = do
ns' <- sequenceA ns
ctxt' <- ctxt
@@ -647,14 +649,14 @@ recGadtC cons varstrtys ty = liftA2 (RecGadtC cons) (sequenceA varstrtys) ty
-------------------------------------------------------------------------------
-- * Type
-forallT :: Quote m => [m TyVarBndr] -> m Cxt -> m Type -> m Type
+forallT :: Quote m => [m (TyVarBndr Specificity)] -> m Cxt -> m Type -> m Type
forallT tvars ctxt ty = do
tvars1 <- sequenceA tvars
ctxt1 <- ctxt
ty1 <- ty
pure $ ForallT tvars1 ctxt1 ty1
-forallVisT :: Quote m => [m TyVarBndr] -> m Type -> m Type
+forallVisT :: Quote m => [m (TyVarBndr ())] -> m Type -> m Type
forallVisT tvars ty = ForallVisT <$> sequenceA tvars <*> ty
varT :: Quote m => Name -> m Type
@@ -815,11 +817,23 @@ strTyLit s = pure (StrTyLit s)
-------------------------------------------------------------------------------
-- * Kind
-plainTV :: Quote m => Name -> m TyVarBndr
-plainTV = pure . PlainTV
+plainTV :: Quote m => Name -> m (TyVarBndr ())
+plainTV n = pure $ PlainTV n ()
+
+plainInvisTV :: Quote m => Name -> Specificity -> m (TyVarBndr Specificity)
+plainInvisTV n s = pure $ PlainTV n s
+
+kindedTV :: Quote m => Name -> m Kind -> m (TyVarBndr ())
+kindedTV n = fmap (KindedTV n ())
+
+kindedInvisTV :: Quote m => Name -> Specificity -> m Kind -> m (TyVarBndr Specificity)
+kindedInvisTV n s = fmap (KindedTV n s)
+
+specifiedSpec :: Specificity
+specifiedSpec = SpecifiedSpec
-kindedTV :: Quote m => Name -> m Kind -> m TyVarBndr
-kindedTV n = fmap (KindedTV n)
+inferredSpec :: Specificity
+inferredSpec = InferredSpec
varK :: Name -> Kind
varK = VarT
@@ -854,7 +868,7 @@ noSig = pure NoSig
kindSig :: Quote m => m Kind -> m FamilyResultSig
kindSig = fmap KindSig
-tyVarSig :: Quote m => m TyVarBndr -> m FamilyResultSig
+tyVarSig :: Quote m => m (TyVarBndr ()) -> m FamilyResultSig
tyVarSig = fmap TyVarSig
-------------------------------------------------------------------------------
diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
index 8cf39c9af8..6dd90e364b 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
@@ -511,7 +511,7 @@ ppr_tf_head (TypeFamilyHead tc tvs res inj)
maybeInj | (Just inj') <- inj = ppr inj'
| otherwise = empty
-ppr_bndrs :: Maybe [TyVarBndr] -> Doc
+ppr_bndrs :: PprFlag flag => Maybe [TyVarBndr flag] -> Doc
ppr_bndrs (Just bndrs) = text "forall" <+> sep (map ppr bndrs) <> text "."
ppr_bndrs Nothing = empty
@@ -660,13 +660,13 @@ instance Ppr PatSynArgs where
commaSepApplied :: [Name] -> Doc
commaSepApplied = commaSepWith (pprName' Applied)
-pprForall :: [TyVarBndr] -> Cxt -> Doc
+pprForall :: [TyVarBndr Specificity] -> Cxt -> Doc
pprForall = pprForall' ForallInvis
-pprForallVis :: [TyVarBndr] -> Cxt -> Doc
+pprForallVis :: [TyVarBndr ()] -> Cxt -> Doc
pprForallVis = pprForall' ForallVis
-pprForall' :: ForallVisFlag -> [TyVarBndr] -> Cxt -> Doc
+pprForall' :: PprFlag flag => ForallVisFlag -> [TyVarBndr flag] -> Cxt -> Doc
pprForall' fvf tvs cxt
-- even in the case without any tvs, there could be a non-empty
-- context cxt (e.g., in the case of pattern synonyms, where there
@@ -859,9 +859,21 @@ instance Ppr TyLit where
ppr = pprTyLit
------------------------------
-instance Ppr TyVarBndr where
- ppr (PlainTV nm) = ppr nm
- ppr (KindedTV nm k) = parens (ppr nm <+> dcolon <+> ppr k)
+class PprFlag flag where
+ pprTyVarBndr :: (TyVarBndr flag) -> Doc
+
+instance PprFlag () where
+ pprTyVarBndr (PlainTV nm ()) = ppr nm
+ pprTyVarBndr (KindedTV nm () k) = parens (ppr nm <+> dcolon <+> ppr k)
+
+instance PprFlag Specificity where
+ pprTyVarBndr (PlainTV nm SpecifiedSpec) = ppr nm
+ pprTyVarBndr (PlainTV nm InferredSpec) = braces (ppr nm)
+ pprTyVarBndr (KindedTV nm SpecifiedSpec k) = parens (ppr nm <+> dcolon <+> ppr k)
+ pprTyVarBndr (KindedTV nm InferredSpec k) = braces (ppr nm <+> dcolon <+> ppr k)
+
+instance PprFlag flag => Ppr (TyVarBndr flag) where
+ ppr bndr = pprTyVarBndr bndr
instance Ppr Role where
ppr NominalR = text "nominal"
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
index 227d24290c..60fb9d37ca 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
@@ -3,7 +3,7 @@
RankNTypes, RoleAnnotations, ScopedTypeVariables,
MagicHash, KindSignatures, PolyKinds, TypeApplications, DataKinds,
GADTs, UnboxedTuples, UnboxedSums, TypeInType,
- Trustworthy #-}
+ Trustworthy, DeriveFunctor #-}
{-# OPTIONS_GHC -fno-warn-inline-rule-shadowing #-}
@@ -2065,19 +2065,19 @@ data Range = FromR Exp | FromThenR Exp Exp
data Dec
= FunD Name [Clause] -- ^ @{ f p1 p2 = b where decs }@
| ValD Pat Body [Dec] -- ^ @{ p = b where decs }@
- | DataD Cxt Name [TyVarBndr]
+ | DataD Cxt Name [TyVarBndr ()]
(Maybe Kind) -- Kind signature (allowed only for GADTs)
[Con] [DerivClause]
-- ^ @{ data Cxt x => T x = A x | B (T x)
-- deriving (Z,W)
-- deriving stock Eq }@
- | NewtypeD Cxt Name [TyVarBndr]
+ | NewtypeD Cxt Name [TyVarBndr ()]
(Maybe Kind) -- Kind signature
Con [DerivClause] -- ^ @{ newtype Cxt x => T x = A (B x)
-- deriving (Z,W Q)
-- deriving stock Eq }@
- | TySynD Name [TyVarBndr] Type -- ^ @{ type T x = (x,x) }@
- | ClassD Cxt Name [TyVarBndr]
+ | TySynD Name [TyVarBndr ()] Type -- ^ @{ type T x = (x,x) }@
+ | ClassD Cxt Name [TyVarBndr ()]
[FunDep] [Dec] -- ^ @{ class Eq a => Ord a where ds }@
| InstanceD (Maybe Overlap) Cxt Type [Dec]
-- ^ @{ instance {\-\# OVERLAPS \#-\}
@@ -2093,18 +2093,18 @@ data Dec
| PragmaD Pragma -- ^ @{ {\-\# INLINE [1] foo \#-\} }@
-- | data families (may also appear in [Dec] of 'ClassD' and 'InstanceD')
- | DataFamilyD Name [TyVarBndr]
+ | DataFamilyD Name [TyVarBndr ()]
(Maybe Kind)
-- ^ @{ data family T a b c :: * }@
- | DataInstD Cxt (Maybe [TyVarBndr]) Type
+ | DataInstD Cxt (Maybe [TyVarBndr ()]) Type
(Maybe Kind) -- Kind signature
[Con] [DerivClause] -- ^ @{ data instance Cxt x => T [x]
-- = A x | B (T x)
-- deriving (Z,W)
-- deriving stock Eq }@
- | NewtypeInstD Cxt (Maybe [TyVarBndr]) Type -- Quantified type vars
+ | NewtypeInstD Cxt (Maybe [TyVarBndr ()]) Type -- Quantified type vars
(Maybe Kind) -- Kind signature
Con [DerivClause] -- ^ @{ newtype instance Cxt x => T [x]
-- = A (B x)
@@ -2217,7 +2217,7 @@ type PatSynType = Type
-- @TypeFamilyHead@ is defined to be the elements of the declaration
-- between @type family@ and @where@.
data TypeFamilyHead =
- TypeFamilyHead Name [TyVarBndr] FamilyResultSig (Maybe InjectivityAnn)
+ TypeFamilyHead Name [TyVarBndr ()] FamilyResultSig (Maybe InjectivityAnn)
deriving( Show, Eq, Ord, Data, Generic )
-- | One equation of a type family instance or closed type family. The
@@ -2237,7 +2237,7 @@ data TypeFamilyHead =
-- ('AppT' ('AppKindT' ('ConT' ''Foo) ('VarT' k)) ('VarT' a))
-- ('VarT' a)
-- @
-data TySynEqn = TySynEqn (Maybe [TyVarBndr]) Type Type
+data TySynEqn = TySynEqn (Maybe [TyVarBndr ()]) Type Type
deriving( Show, Eq, Ord, Data, Generic )
data FunDep = FunDep [Name] [Name]
@@ -2257,7 +2257,7 @@ data Safety = Unsafe | Safe | Interruptible
data Pragma = InlineP Name Inline RuleMatch Phases
| SpecialiseP Name Type (Maybe Inline) Phases
| SpecialiseInstP Type
- | RuleP String (Maybe [TyVarBndr]) [RuleBndr] Exp Exp Phases
+ | RuleP String (Maybe [TyVarBndr ()]) [RuleBndr] Exp Exp Phases
| AnnP AnnTarget Exp
| LineP Int String
| CompleteP [Name] (Maybe Name)
@@ -2346,7 +2346,7 @@ data DecidedStrictness = DecidedLazy
data Con = NormalC Name [BangType] -- ^ @C Int a@
| RecC Name [VarBangType] -- ^ @C { v :: Int, w :: a }@
| InfixC BangType Name BangType -- ^ @Int :+ a@
- | ForallC [TyVarBndr] Cxt Con -- ^ @forall a. Eq a => C [a]@
+ | ForallC [TyVarBndr Specificity] Cxt Con -- ^ @forall a. Eq a => C [a]@
| GadtC [Name] [BangType]
Type -- See Note [GADT return type]
-- ^ @C :: a -> b -> T b Int@
@@ -2415,8 +2415,8 @@ data PatSynArgs
| RecordPatSyn [Name] -- ^ @pattern P { {x,y,z} } = p@
deriving( Show, Eq, Ord, Data, Generic )
-data Type = ForallT [TyVarBndr] Cxt Type -- ^ @forall \<vars\>. \<ctxt\> => \<type\>@
- | ForallVisT [TyVarBndr] Type -- ^ @forall \<vars\> -> \<type\>@
+data Type = ForallT [TyVarBndr Specificity] Cxt Type -- ^ @forall \<vars\>. \<ctxt\> => \<type\>@
+ | ForallVisT [TyVarBndr ()] Type -- ^ @forall \<vars\> -> \<type\>@
| AppT Type Type -- ^ @T a b@
| AppKindT Type Kind -- ^ @T \@k t@
| SigT Type Kind -- ^ @t :: k@
@@ -2446,14 +2446,18 @@ data Type = ForallT [TyVarBndr] Cxt Type -- ^ @forall \<vars\>. \<ctxt\> => \<t
| ImplicitParamT String Type -- ^ @?x :: t@
deriving( Show, Eq, Ord, Data, Generic )
-data TyVarBndr = PlainTV Name -- ^ @a@
- | KindedTV Name Kind -- ^ @(a :: k)@
+data Specificity = SpecifiedSpec -- ^ @a@
+ | InferredSpec -- ^ @{a}@
deriving( Show, Eq, Ord, Data, Generic )
+data TyVarBndr flag = PlainTV Name flag -- ^ @a@
+ | KindedTV Name flag Kind -- ^ @(a :: k)@
+ deriving( Show, Eq, Ord, Data, Generic, Functor )
+
-- | Type family result signature
data FamilyResultSig = NoSig -- ^ no signature
| KindSig Kind -- ^ @k@
- | TyVarSig TyVarBndr -- ^ @= r, = (r :: k)@
+ | TyVarSig (TyVarBndr ()) -- ^ @= r, = (r :: k)@
deriving( Show, Eq, Ord, Data, Generic )
-- | Injectivity annotation