diff options
Diffstat (limited to 'libraries/template-haskell/Language/Haskell/TH/Syntax.hs')
-rw-r--r-- | libraries/template-haskell/Language/Haskell/TH/Syntax.hs | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs index 00ac0b308b..afe961b50e 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs @@ -1549,13 +1549,15 @@ data Dec | ValD Pat Body [Dec] -- ^ @{ p = b where decs }@ | DataD Cxt Name [TyVarBndr] (Maybe Kind) -- Kind signature (allowed only for GADTs) - [Con] Cxt + [Con] [DerivClause] -- ^ @{ data Cxt x => T x = A x | B (T x) - -- deriving (Z,W)}@ + -- deriving (Z,W) + -- deriving stock Eq }@ | NewtypeD Cxt Name [TyVarBndr] (Maybe Kind) -- Kind signature - Con Cxt -- ^ @{ newtype Cxt x => T x = A (B x) - -- deriving (Z,W Q)}@ + 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] [FunDep] [Dec] -- ^ @{ class Eq a => Ord a where ds }@ @@ -1578,14 +1580,18 @@ data Dec | DataInstD Cxt Name [Type] (Maybe Kind) -- Kind signature - [Con] Cxt -- ^ @{ data instance Cxt x => T [x] - -- = A x | B (T x) deriving (Z,W)}@ + [Con] [DerivClause] -- ^ @{ data instance Cxt x => T [x] + -- = A x | B (T x) + -- deriving (Z,W) + -- deriving stock Eq }@ | NewtypeInstD Cxt Name [Type] - (Maybe Kind) -- Kind signature - Con Cxt -- ^ @{ newtype instance Cxt x => T [x] - -- = A (B x) deriving (Z,W)}@ - | TySynInstD Name TySynEqn -- ^ @{ type instance ... }@ + (Maybe Kind) -- Kind signature + Con [DerivClause] -- ^ @{ newtype instance Cxt x => T [x] + -- = A (B x) + -- deriving (Z,W) + -- deriving stock Eq }@ + | TySynInstD Name TySynEqn -- ^ @{ type instance ... }@ -- | open type families (may also appear in [Dec] of 'ClassD' and 'InstanceD') | OpenTypeFamilyD TypeFamilyHead @@ -1595,7 +1601,8 @@ data Dec -- ^ @{ type family F a b = (r :: *) | r -> a where ... }@ | RoleAnnotD Name [Role] -- ^ @{ type role T nominal representational }@ - | StandaloneDerivD Cxt Type -- ^ @{ deriving instance Ord a => Ord (Foo a) }@ + | StandaloneDerivD (Maybe DerivStrategy) Cxt Type + -- ^ @{ deriving stock instance Ord a => Ord (Foo a) }@ | DefaultSigD Name Type -- ^ @{ default size :: Data a => a -> Int }@ -- | Pattern Synonyms @@ -1620,6 +1627,17 @@ data Overlap = Overlappable -- ^ May be overlapped by more specific instances -- available. deriving( Show, Eq, Ord, Data, Generic ) +-- | A single @deriving@ clause at the end of a datatype. +data DerivClause = DerivClause (Maybe DerivStrategy) Cxt + -- ^ @{ deriving stock (Eq, Ord) }@ + deriving( Show, Eq, Ord, Data, Generic ) + +-- | What the user explicitly requests when deriving an instance. +data DerivStrategy = Stock -- ^ A \"standard\" derived instance + | Anyclass -- ^ @-XDeriveAnyClass@ + | Newtype -- ^ @-XGeneralizedNewtypeDeriving@ + deriving( Show, Eq, Ord, Data, Generic ) + -- | A Pattern synonym's type. Note that a pattern synonym's *fully* -- specified type has a peculiar shape coming with two forall -- quantifiers and two constraint contexts. For example, consider the |