diff options
Diffstat (limited to 'libraries/template-haskell/Language/Haskell')
6 files changed, 140 insertions, 190 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH.hs b/libraries/template-haskell/Language/Haskell/TH.hs index 76aae272bd..e038a3ba6b 100644 --- a/libraries/template-haskell/Language/Haskell/TH.hs +++ b/libraries/template-haskell/Language/Haskell/TH.hs @@ -41,15 +41,15 @@ module Language.Haskell.TH( TExp, unType, -- * Names - Name, NameSpace, -- Abstract + Name, NameSpace, -- Abstract -- ** Constructing names mkName, -- :: String -> Name newName, -- :: String -> Q Name -- ** Deconstructing names - nameBase, -- :: Name -> String - nameModule, -- :: Name -> Maybe String + nameBase, -- :: Name -> String + nameModule, -- :: Name -> Maybe String -- ** Built-in names - tupleTypeName, tupleDataName, -- Int -> Name + tupleTypeName, tupleDataName, -- Int -> Name unboxedTupleTypeName, unboxedTupleDataName, -- :: Int -> Name -- * The algebraic data types @@ -124,7 +124,7 @@ module Language.Haskell.TH( -- **** Data valD, funD, tySynD, dataD, newtypeD, -- **** Class - classD, instanceD, sigD, + classD, instanceD, sigD, standaloneDerivD, defaultSigD, -- **** Role annotations roleAnnotD, -- **** Type Family / Data Family diff --git a/libraries/template-haskell/Language/Haskell/TH/Lib.hs b/libraries/template-haskell/Language/Haskell/TH/Lib.hs index 4d4f079719..efe597275b 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Lib.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Lib.hs @@ -171,7 +171,7 @@ patG ss = do { ss' <- sequence ss; return (PatG ss') } patGE :: [StmtQ] -> ExpQ -> Q (Guard, Exp) patGE ss e = do { ss' <- sequence ss; - e' <- e; + e' <- e; return (PatG ss', e') } ------------------------------------------------------------------------------- @@ -459,6 +459,19 @@ closedTypeFamilyKindD tc tvs kind eqns = roleAnnotD :: Name -> [Role] -> DecQ roleAnnotD name roles = return $ RoleAnnotD name roles +standaloneDerivD :: CxtQ -> TypeQ -> DecQ +standaloneDerivD ctxtq tyq = + do + ctxt <- ctxtq + ty <- tyq + return $ StandaloneDerivD ctxt ty + +defaultSigD :: Name -> TypeQ -> DecQ +defaultSigD n tyq = + do + ty <- tyq + return $ DefaultSigD n ty + tySynEqn :: [TypeQ] -> TypeQ -> TySynEqnQ tySynEqn lhs rhs = do diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs index 81bf3c1d66..5f3a0c6c9b 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs @@ -52,9 +52,9 @@ instance Ppr Info where ppr (FamilyI d is) = ppr d $$ vcat (map ppr is) ppr (PrimTyConI name arity is_unlifted) = text "Primitive" - <+> (if is_unlifted then text "unlifted" else empty) - <+> text "type constructor" <+> quotes (ppr name) - <+> parens (text "arity" <+> int arity) + <+> (if is_unlifted then text "unlifted" else empty) + <+> text "type constructor" <+> quotes (ppr name) + <+> parens (text "arity" <+> int arity) ppr (ClassOpI v ty cls fix) = text "Class op from" <+> ppr cls <> colon <+> vcat [ppr_sig v ty, pprFixity v fix] @@ -327,11 +327,17 @@ ppr_dec _ (ClosedTypeFamilyD tc tvs mkind eqns) ppr_dec _ (RoleAnnotD name roles) = hsep [ text "type role", ppr name ] <+> hsep (map ppr roles) +ppr_dec _ (StandaloneDerivD cxt ty) + = hsep [ text "deriving instance", pprCxt cxt, ppr ty ] + +ppr_dec _ (DefaultSigD n ty) + = hsep [ text "default", pprPrefixOcc n, text "::", ppr ty ] + ppr_data :: Doc -> Cxt -> Name -> Doc -> [Con] -> [Name] -> Doc ppr_data maybeInst ctxt t argsDoc cs decs = sep [text "data" <+> maybeInst - <+> pprCxt ctxt - <+> ppr t <+> argsDoc, + <+> pprCxt ctxt + <+> ppr t <+> argsDoc, nest nestDepth (sep (pref $ map ppr cs)), if null decs then empty @@ -346,14 +352,14 @@ ppr_data maybeInst ctxt t argsDoc cs decs ppr_newtype :: Doc -> Cxt -> Name -> Doc -> Con -> [Name] -> Doc ppr_newtype maybeInst ctxt t argsDoc c decs = sep [text "newtype" <+> maybeInst - <+> pprCxt ctxt - <+> ppr t <+> argsDoc, + <+> pprCxt ctxt + <+> ppr t <+> argsDoc, nest 2 (char '=' <+> ppr c), if null decs - then empty - else nest nestDepth - $ text "deriving" - <+> parens (hsep $ punctuate comma $ map ppr decs)] + then empty + else nest nestDepth + $ text "deriving" + <+> parens (hsep $ punctuate comma $ map ppr decs)] ppr_tySyn :: Doc -> Name -> Doc -> Type -> Doc ppr_tySyn maybeInst t argsDoc rhs @@ -507,7 +513,7 @@ pprTyApp (PromotedTupleT n, args) | length args == n = quoteParens (sep (punctuate comma (map ppr args))) pprTyApp (fun, args) = pprParendType fun <+> sep (map pprParendType args) -pprFunArgType :: Type -> Doc -- Should really use a precedence argument +pprFunArgType :: Type -> Doc -- Should really use a precedence argument -- Everything except forall and (->) binds more tightly than (->) pprFunArgType ty@(ForallT {}) = parens (ppr ty) pprFunArgType ty@((ArrowT `AppT` _) `AppT` _) = parens (ppr ty) diff --git a/libraries/template-haskell/Language/Haskell/TH/PprLib.hs b/libraries/template-haskell/Language/Haskell/TH/PprLib.hs index 22b336ae81..a6b923cc35 100644 --- a/libraries/template-haskell/Language/Haskell/TH/PprLib.hs +++ b/libraries/template-haskell/Language/Haskell/TH/PprLib.hs @@ -1,35 +1,35 @@ -{-# LANGUAGE FlexibleInstances, MagicHash #-} +{-# LANGUAGE FlexibleInstances #-} -- | Monadic front-end to Text.PrettyPrint module Language.Haskell.TH.PprLib ( - -- * The document type + -- * The document type Doc, -- Abstract, instance of Show PprM, - -- * Primitive Documents + -- * Primitive Documents empty, semi, comma, colon, space, equals, arrow, lparen, rparen, lbrack, rbrack, lbrace, rbrace, - -- * Converting values into documents + -- * Converting values into documents text, char, ptext, int, integer, float, double, rational, - -- * Wrapping documents in delimiters + -- * Wrapping documents in delimiters parens, brackets, braces, quotes, doubleQuotes, - -- * Combining documents + -- * Combining documents (<>), (<+>), hcat, hsep, ($$), ($+$), vcat, sep, cat, fsep, fcat, - nest, + nest, hang, punctuate, - -- * Predicates on documents - isEmpty, + -- * Predicates on documents + isEmpty, to_HPJ_Doc, pprName, pprName' ) where @@ -41,7 +41,6 @@ import qualified Text.PrettyPrint as HPJ import Control.Monad (liftM, liftM2, ap) import Language.Haskell.TH.Lib.Map ( Map ) import qualified Language.Haskell.TH.Lib.Map as Map ( lookup, insert, empty ) -import GHC.Base (Int(..)) infixl 6 <> infixl 6 <+> @@ -57,23 +56,23 @@ instance Show Doc where isEmpty :: Doc -> PprM Bool; -- ^ Returns 'True' if the document is empty -empty :: Doc; -- ^ An empty document -semi :: Doc; -- ^ A ';' character -comma :: Doc; -- ^ A ',' character -colon :: Doc; -- ^ A ':' character -space :: Doc; -- ^ A space character -equals :: Doc; -- ^ A '=' character -arrow :: Doc; -- ^ A "->" string -lparen :: Doc; -- ^ A '(' character -rparen :: Doc; -- ^ A ')' character -lbrack :: Doc; -- ^ A '[' character -rbrack :: Doc; -- ^ A ']' character -lbrace :: Doc; -- ^ A '{' character -rbrace :: Doc; -- ^ A '}' character - -text :: String -> Doc -ptext :: String -> Doc -char :: Char -> Doc +empty :: Doc; -- ^ An empty document +semi :: Doc; -- ^ A ';' character +comma :: Doc; -- ^ A ',' character +colon :: Doc; -- ^ A ':' character +space :: Doc; -- ^ A space character +equals :: Doc; -- ^ A '=' character +arrow :: Doc; -- ^ A "->" string +lparen :: Doc; -- ^ A '(' character +rparen :: Doc; -- ^ A ')' character +lbrack :: Doc; -- ^ A '[' character +rbrack :: Doc; -- ^ A ']' character +lbrace :: Doc; -- ^ A '{' character +rbrace :: Doc; -- ^ A '}' character + +text :: String -> Doc +ptext :: String -> Doc +char :: Char -> Doc int :: Int -> Doc integer :: Integer -> Doc float :: Float -> Doc @@ -81,11 +80,11 @@ double :: Double -> Doc rational :: Rational -> Doc -parens :: Doc -> Doc; -- ^ Wrap document in @(...)@ -brackets :: Doc -> Doc; -- ^ Wrap document in @[...]@ -braces :: Doc -> Doc; -- ^ Wrap document in @{...}@ -quotes :: Doc -> Doc; -- ^ Wrap document in @\'...\'@ -doubleQuotes :: Doc -> Doc; -- ^ Wrap document in @\"...\"@ +parens :: Doc -> Doc; -- ^ Wrap document in @(...)@ +brackets :: Doc -> Doc; -- ^ Wrap document in @[...]@ +braces :: Doc -> Doc; -- ^ Wrap document in @{...}@ +quotes :: Doc -> Doc; -- ^ Wrap document in @\'...\'@ +doubleQuotes :: Doc -> Doc; -- ^ Wrap document in @\"...\"@ -- Combining @Doc@ values @@ -96,7 +95,7 @@ hsep :: [Doc] -> Doc; -- ^List version of '<+>' ($$) :: Doc -> Doc -> Doc; -- ^Above; if there is no -- overlap it \"dovetails\" the two -($+$) :: Doc -> Doc -> Doc; -- ^Above, without dovetailing. +($+$) :: Doc -> Doc -> Doc; -- ^Above, without dovetailing. vcat :: [Doc] -> Doc; -- ^List version of '$$' cat :: [Doc] -> Doc; -- ^ Either hcat or vcat @@ -109,7 +108,7 @@ nest :: Int -> Doc -> Doc; -- ^ Nested -- GHC-specific ones. -hang :: Doc -> Int -> Doc -> Doc; -- ^ @hang d1 n d2 = sep [d1, nest n d2]@ +hang :: Doc -> Int -> Doc -> Doc; -- ^ @hang d1 n d2 = sep [d1, nest n d2]@ punctuate :: Doc -> [Doc] -> [Doc]; -- ^ @punctuate p [d1, ... dn] = [d1 \<> p, d2 \<> p, ... dn-1 \<> p, dn]@ @@ -124,10 +123,10 @@ pprName = pprName' Alone pprName' :: NameIs -> Name -> Doc pprName' ni n@(Name o (NameU _)) - = PprM $ \s@(fm, i@(I# i')) + = PprM $ \s@(fm, i) -> let (n', s') = case Map.lookup n fm of Just d -> (d, s) - Nothing -> let n'' = Name o (NameU i') + Nothing -> let n'' = Name o (NameU i) in (n'', (Map.insert n n'' fm, i + 1)) in (HPJ.text $ showName' ni n', s') pprName' ni n = text $ showName' ni n @@ -141,7 +140,7 @@ instance Show Name where data Name = Name OccName NameFlavour data NameFlavour - | NameU Int# -- A unique local name + | NameU Int# -- A unique local name -} to_HPJ_Doc :: Doc -> HPJ.Doc diff --git a/libraries/template-haskell/Language/Haskell/TH/Quote.hs b/libraries/template-haskell/Language/Haskell/TH/Quote.hs index b9c0d25d2b..618906d901 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Quote.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Quote.hs @@ -1,6 +1,6 @@ {-# LANGUAGE RankNTypes, ScopedTypeVariables #-} module Language.Haskell.TH.Quote( - QuasiQuoter(..), + QuasiQuoter(..), dataToQa, dataToExpQ, dataToPatQ, quoteFile ) where diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs index b5163cb44b..48199a4d8e 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs @@ -1,4 +1,5 @@ -{-# LANGUAGE CPP, DeriveDataTypeable, MagicHash, PolymorphicComponents, RoleAnnotations, UnboxedTuples #-} +{-# LANGUAGE CPP, DeriveDataTypeable, PolymorphicComponents, + RoleAnnotations, DeriveGeneric #-} ----------------------------------------------------------------------------- -- | @@ -16,9 +17,7 @@ module Language.Haskell.TH.Syntax where -import GHC.Exts -import Data.Data (Data(..), Typeable, mkConstr, mkDataType, constrIndex) -import qualified Data.Data as Data +import Data.Data (Data(..), Typeable ) #if __GLASGOW_HASKELL__ < 709 import Control.Applicative( Applicative(..) ) #endif @@ -28,6 +27,7 @@ import Control.Monad (liftM) import System.IO ( hPutStrLn, stderr ) import Data.Char ( isAlpha, isAlphaNum, isUpper ) import Data.Word ( Word8 ) +import GHC.Generics ( Generic ) ----------------------------------------------------- -- @@ -377,9 +377,16 @@ runIO :: IO a -> Q a runIO m = Q (qRunIO m) -- | Record external files that runIO is using (dependent upon). --- The compiler can then recognize that it should re-compile the file using this TH when the external file changes. --- Note that ghc -M will still not know about these dependencies - it does not execute TH. +-- The compiler can then recognize that it should re-compile the Haskell file +-- when an external file changes. +-- -- Expects an absolute file path. +-- +-- Notes: +-- +-- * ghc -M does not know about these dependencies - it does not execute TH. +-- +-- * The dependency is based on file content, not a modification time addDependentFile :: FilePath -> Q () addDependentFile fp = Q (qAddDependentFile fp) @@ -525,17 +532,17 @@ rightName = mkNameG DataName "base" "Data.Either" "Right" ----------------------------------------------------- newtype ModName = ModName String -- Module name - deriving (Show,Eq,Ord,Typeable,Data) + deriving (Show,Eq,Ord,Typeable,Data,Generic) newtype PkgName = PkgName String -- package name - deriving (Show,Eq,Ord,Typeable,Data) + deriving (Show,Eq,Ord,Typeable,Data,Generic) -- | Obtained from 'reifyModule' and 'thisModule'. data Module = Module PkgName ModName -- package qualified module name - deriving (Show,Eq,Ord,Typeable,Data) + deriving (Show,Eq,Ord,Typeable,Data,Generic) newtype OccName = OccName String - deriving (Show,Eq,Ord,Typeable,Data) + deriving (Show,Eq,Ord,Typeable,Data,Generic) mkModName :: String -> ModName mkModName s = ModName s @@ -646,67 +653,29 @@ Names constructed using @newName@ and @mkName@ may be used in bindings (such as @let x = ...@ or @\x -> ...@), but names constructed using @lookupValueName@, @lookupTypeName@, @'f@, @''T@ may not. -} -data Name = Name OccName NameFlavour deriving (Typeable, Data) +data Name = Name OccName NameFlavour deriving (Typeable, Data, Eq, Generic) + +instance Ord Name where + -- check if unique is different before looking at strings + (Name o1 f1) `compare` (Name o2 f2) = (f1 `compare` f2) `thenCmp` + (o1 `compare` o2) data NameFlavour = NameS -- ^ An unqualified name; dynamically bound | NameQ ModName -- ^ A qualified name; dynamically bound - | NameU Int# -- ^ A unique local name - | NameL Int# -- ^ Local name bound outside of the TH AST + | NameU !Int -- ^ A unique local name + | NameL !Int -- ^ Local name bound outside of the TH AST | NameG NameSpace PkgName ModName -- ^ Global name bound outside of the TH AST: -- An original name (occurrences only, not binders) -- Need the namespace too to be sure which -- thing we are naming - deriving ( Typeable ) - --- | --- Although the NameFlavour type is abstract, the Data instance is not. The reason for this --- is that currently we use Data to serialize values in annotations, and in order for that to --- work for Template Haskell names introduced via the 'x syntax we need gunfold on NameFlavour --- to work. Bleh! --- --- The long term solution to this is to use the binary package for annotation serialization and --- then remove this instance. However, to do _that_ we need to wait on binary to become stable, since --- boot libraries cannot be upgraded separately from GHC itself. --- --- This instance cannot be derived automatically due to bug #2701 -instance Data NameFlavour where - gfoldl _ z NameS = z NameS - gfoldl k z (NameQ mn) = z NameQ `k` mn - gfoldl k z (NameU i) = z (\(I# i') -> NameU i') `k` (I# i) - gfoldl k z (NameL i) = z (\(I# i') -> NameL i') `k` (I# i) - gfoldl k z (NameG ns p m) = z NameG `k` ns `k` p `k` m - gunfold k z c = case constrIndex c of - 1 -> z NameS - 2 -> k $ z NameQ - 3 -> k $ z (\(I# i) -> NameU i) - 4 -> k $ z (\(I# i) -> NameL i) - 5 -> k $ k $ k $ z NameG - _ -> error "gunfold: NameFlavour" - toConstr NameS = con_NameS - toConstr (NameQ _) = con_NameQ - toConstr (NameU _) = con_NameU - toConstr (NameL _) = con_NameL - toConstr (NameG _ _ _) = con_NameG - dataTypeOf _ = ty_NameFlavour - -con_NameS, con_NameQ, con_NameU, con_NameL, con_NameG :: Data.Constr -con_NameS = mkConstr ty_NameFlavour "NameS" [] Data.Prefix -con_NameQ = mkConstr ty_NameFlavour "NameQ" [] Data.Prefix -con_NameU = mkConstr ty_NameFlavour "NameU" [] Data.Prefix -con_NameL = mkConstr ty_NameFlavour "NameL" [] Data.Prefix -con_NameG = mkConstr ty_NameFlavour "NameG" [] Data.Prefix - -ty_NameFlavour :: Data.DataType -ty_NameFlavour = mkDataType "Language.Haskell.TH.Syntax.NameFlavour" - [con_NameS, con_NameQ, con_NameU, - con_NameL, con_NameG] + deriving ( Typeable, Data, Eq, Ord, Generic ) data NameSpace = VarName -- ^ Variables | DataName -- ^ Data constructors | TcClsName -- ^ Type constructors and classes; Haskell has them -- in the same name space for now. - deriving( Eq, Ord, Data, Typeable ) + deriving( Eq, Ord, Data, Typeable, Generic ) type Uniq = Int @@ -789,11 +758,11 @@ mkName str -- | Only used internally mkNameU :: String -> Uniq -> Name -mkNameU s (I# u) = Name (mkOccName s) (NameU u) +mkNameU s u = Name (mkOccName s) (NameU u) -- | Only used internally mkNameL :: String -> Uniq -> Name -mkNameL s (I# u) = Name (mkOccName s) (NameL u) +mkNameL s u = Name (mkOccName s) (NameL u) -- | Used for 'x etc, but not available to the programmer mkNameG :: NameSpace -> String -> String -> String -> Name @@ -805,45 +774,6 @@ mkNameG_v = mkNameG VarName mkNameG_tc = mkNameG TcClsName mkNameG_d = mkNameG DataName -instance Eq Name where - v1 == v2 = cmpEq (v1 `compare` v2) - -instance Ord Name where - (Name o1 f1) `compare` (Name o2 f2) = (f1 `compare` f2) `thenCmp` - (o1 `compare` o2) - -instance Eq NameFlavour where - f1 == f2 = cmpEq (f1 `compare` f2) - -instance Ord NameFlavour where - -- NameS < NameQ < NameU < NameL < NameG - NameS `compare` NameS = EQ - NameS `compare` _ = LT - - (NameQ _) `compare` NameS = GT - (NameQ m1) `compare` (NameQ m2) = m1 `compare` m2 - (NameQ _) `compare` _ = LT - - (NameU _) `compare` NameS = GT - (NameU _) `compare` (NameQ _) = GT - (NameU u1) `compare` (NameU u2) | isTrue# (u1 <# u2) = LT - | isTrue# (u1 ==# u2) = EQ - | otherwise = GT - (NameU _) `compare` _ = LT - - (NameL _) `compare` NameS = GT - (NameL _) `compare` (NameQ _) = GT - (NameL _) `compare` (NameU _) = GT - (NameL u1) `compare` (NameL u2) | isTrue# (u1 <# u2) = LT - | isTrue# (u1 ==# u2) = EQ - | otherwise = GT - (NameL _) `compare` _ = LT - - (NameG ns1 p1 m1) `compare` (NameG ns2 p2 m2) = (ns1 `compare` ns2) `thenCmp` - (p1 `compare` p2) `thenCmp` - (m1 `compare` m2) - (NameG _ _ _) `compare` _ = GT - data NameIs = Alone | Applied | Infix showName :: Name -> String @@ -870,8 +800,8 @@ showName' ni nm Name occ NameS -> occString occ Name occ (NameQ m) -> modString m ++ "." ++ occString occ Name occ (NameG _ _ m) -> modString m ++ "." ++ occString occ - Name occ (NameU u) -> occString occ ++ "_" ++ show (I# u) - Name occ (NameL u) -> occString occ ++ "_" ++ show (I# u) + Name occ (NameU u) -> occString occ ++ "_" ++ show u + Name occ (NameL u) -> occString occ ++ "_" ++ show u pnam = classify nms @@ -1015,13 +945,13 @@ data Info | TyVarI -- Scoped type variable Name Type -- What it is bound to - deriving( Show, Data, Typeable ) + deriving( Show, Data, Typeable, Generic ) -- | Obtained from 'reifyModule' in the 'Q' Monad. data ModuleInfo = -- | Contains the import list of the module. ModuleInfo [Module] - deriving( Show, Data, Typeable ) + deriving( Show, Data, Typeable, Generic ) {- | In 'ClassOpI' and 'DataConI', name of the parent class or type @@ -1045,9 +975,9 @@ type Unlifted = Bool type InstanceDec = Dec data Fixity = Fixity Int FixityDirection - deriving( Eq, Show, Data, Typeable ) + deriving( Eq, Show, Data, Typeable, Generic ) data FixityDirection = InfixL | InfixR | InfixN - deriving( Eq, Show, Data, Typeable ) + deriving( Eq, Show, Data, Typeable, Generic ) -- | Highest allowed operator precedence for 'Fixity' constructor (answer: 9) maxPrecedence :: Int @@ -1139,7 +1069,7 @@ data Lit = CharL Char | FloatPrimL Rational | DoublePrimL Rational | StringPrimL [Word8] -- ^ A primitive C-style string, type Addr# - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) -- We could add Int, Float, Double etc, as we do in HsLit, -- but that could complicate the @@ -1167,15 +1097,15 @@ data Pat | ListP [ Pat ] -- ^ @{ [1,2,3] }@ | SigP Pat Type -- ^ @{ p :: t }@ | ViewP Exp Pat -- ^ @{ e -> p }@ - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) type FieldPat = (Name,Pat) data Match = Match Pat Body [Dec] -- ^ @case e of { pat -> body where decs }@ - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Clause = Clause [Pat] Body [Dec] -- ^ @f { p1 p2 = body where decs }@ - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Exp = VarE Name -- ^ @{ x }@ @@ -1222,7 +1152,7 @@ data Exp | SigE Exp Type -- ^ @{ e :: t }@ | RecConE Name [FieldExp] -- ^ @{ T { x = y, z = w } }@ | RecUpdE Exp [FieldExp] -- ^ @{ (f x) { z = w } }@ - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) type FieldExp = (Name,Exp) @@ -1233,23 +1163,23 @@ data Body -- | e3 = e4 } -- where ds@ | NormalB Exp -- ^ @f p { = e } where ds@ - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Guard = NormalG Exp -- ^ @f x { | odd x } = x@ | PatG [Stmt] -- ^ @f x { | Just y <- x, Just z <- y } = z@ - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Stmt = BindS Pat Exp | LetS [ Dec ] | NoBindS Exp | ParS [[Stmt]] - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Range = FromR Exp | FromThenR Exp Exp | FromToR Exp Exp | FromThenToR Exp Exp Exp - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Dec = FunD Name [Clause] -- ^ @{ f p1 p2 = b where decs }@ @@ -1292,29 +1222,31 @@ data Dec [TySynEqn] -- ^ @{ type family F a b :: * where ... }@ | RoleAnnotD Name [Role] -- ^ @{ type role T nominal representational }@ - deriving( Show, Eq, Data, Typeable ) + | StandaloneDerivD Cxt Type -- ^ @{ deriving instance Ord a => Ord (Foo a) }@ + | DefaultSigD Name Type -- ^ @{ default size :: Data a => a -> Int }@ + deriving( Show, Eq, Data, Typeable, Generic ) -- | One equation of a type family instance or closed type family. The -- arguments are the left-hand-side type patterns and the right-hand-side -- result. data TySynEqn = TySynEqn [Type] Type - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data FunDep = FunDep [Name] [Name] - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data FamFlavour = TypeFam | DataFam - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Foreign = ImportF Callconv Safety String Name Type | ExportF Callconv String Name Type - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Callconv = CCall | StdCall - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Safety = Unsafe | Safe | Interruptible - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Pragma = InlineP Name Inline RuleMatch Phases | SpecialiseP Name Type (Maybe Inline) Phases @@ -1322,30 +1254,30 @@ data Pragma = InlineP Name Inline RuleMatch Phases | RuleP String [RuleBndr] Exp Exp Phases | AnnP AnnTarget Exp | LineP Int String - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Inline = NoInline | Inline | Inlinable - deriving (Show, Eq, Data, Typeable) + deriving (Show, Eq, Data, Typeable, Generic) data RuleMatch = ConLike | FunLike - deriving (Show, Eq, Data, Typeable) + deriving (Show, Eq, Data, Typeable, Generic) data Phases = AllPhases | FromPhase Int | BeforePhase Int - deriving (Show, Eq, Data, Typeable) + deriving (Show, Eq, Data, Typeable, Generic) data RuleBndr = RuleVar Name | TypedRuleVar Name Type - deriving (Show, Eq, Data, Typeable) + deriving (Show, Eq, Data, Typeable, Generic) data AnnTarget = ModuleAnnotation | TypeAnnotation Name | ValueAnnotation Name - deriving (Show, Eq, Data, Typeable) + deriving (Show, Eq, Data, Typeable, Generic) type Cxt = [Pred] -- ^ @(Eq a, Ord b)@ @@ -1355,13 +1287,13 @@ type Cxt = [Pred] -- ^ @(Eq a, Ord b)@ type Pred = Type data Strict = IsStrict | NotStrict | Unpacked - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data Con = NormalC Name [StrictType] -- ^ @C Int a@ | RecC Name [VarStrictType] -- ^ @C { v :: Int, w :: a }@ | InfixC StrictType Name StrictType -- ^ @Int :+ a@ | ForallC [TyVarBndr] Cxt Con -- ^ @forall a. Eq a => C [a]@ - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) type StrictType = (Strict, Type) type VarStrictType = (Name, Strict, Type) @@ -1385,27 +1317,27 @@ data Type = ForallT [TyVarBndr] Cxt Type -- ^ @forall \<vars\>. \<ctxt\> -> \<t | StarT -- ^ @*@ | ConstraintT -- ^ @Constraint@ | LitT TyLit -- ^ @0,1,2, etc.@ - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data TyVarBndr = PlainTV Name -- ^ @a@ | KindedTV Name Kind -- ^ @(a :: k)@ - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) data TyLit = NumTyLit Integer -- ^ @2@ | StrTyLit String -- ^ @"Hello"@ - deriving ( Show, Eq, Data, Typeable ) + deriving ( Show, Eq, Data, Typeable, Generic ) -- | Role annotations data Role = NominalR -- ^ @nominal@ | RepresentationalR -- ^ @representational@ | PhantomR -- ^ @phantom@ | InferR -- ^ @_@ - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) -- | Annotation target for reifyAnnotations data AnnLookup = AnnLookupModule Module | AnnLookupName Name - deriving( Show, Eq, Data, Typeable ) + deriving( Show, Eq, Data, Typeable, Generic ) -- | To avoid duplication between kinds and types, they -- are defined to be the same. Naturally, you would never |