[commit: template-haskell] master: Implement roles into Template Haskell. (fa7d4f2)
Richard Eisenberg
eir at ghc.haskell.org
Fri Aug 2 17:00:08 CEST 2013
Repository : http://darcs.haskell.org/ghc.git/
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/fa7d4f228984c8ff0fdf492af81a61bbf6160786
>---------------------------------------------------------------
commit fa7d4f228984c8ff0fdf492af81a61bbf6160786
Author: Richard Eisenberg <eir at cis.upenn.edu>
Date: Fri Aug 2 15:52:48 2013 +0100
Implement roles into Template Haskell.
The biggest change is to the TyVarBndr type, which now can deal
with role annotations.
>---------------------------------------------------------------
Language/Haskell/TH.hs | 2 +-
Language/Haskell/TH/Lib.hs | 14 ++++++++++++++
Language/Haskell/TH/Ppr.hs | 8 ++++++++
Language/Haskell/TH/Syntax.hs | 8 ++++++++
4 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/Language/Haskell/TH.hs b/Language/Haskell/TH.hs
index 066086e..5064b6a 100644
--- a/Language/Haskell/TH.hs
+++ b/Language/Haskell/TH.hs
@@ -59,7 +59,7 @@ module Language.Haskell.TH(
-- ** Patterns
Pat(..), FieldExp, FieldPat,
-- ** Types
- Type(..), TyVarBndr(..), TyLit(..), Kind, Cxt, Pred(..),
+ Type(..), TyVarBndr(..), TyLit(..), Kind, Cxt, Pred(..), Role(..),
-- * Library functions
-- ** Abbreviations
diff --git a/Language/Haskell/TH/Lib.hs b/Language/Haskell/TH/Lib.hs
index e29463b..346d872 100644
--- a/Language/Haskell/TH/Lib.hs
+++ b/Language/Haskell/TH/Lib.hs
@@ -566,6 +566,12 @@ plainTV = PlainTV
kindedTV :: Name -> Kind -> TyVarBndr
kindedTV = KindedTV
+roledTV :: Name -> Role -> TyVarBndr
+roledTV = RoledTV
+
+kindedRoledTV :: Name -> Kind -> Role -> TyVarBndr
+kindedRoledTV = KindedRoledTV
+
varK :: Name -> Kind
varK = VarT
@@ -591,6 +597,14 @@ constraintK :: Kind
constraintK = ConstraintT
-------------------------------------------------------------------------------
+-- * Role
+
+nominal, representational, phantom :: Role
+nominal = Nominal
+representational = Representational
+phantom = Phantom
+
+-------------------------------------------------------------------------------
-- * Callconv
cCall, stdCall :: Callconv
diff --git a/Language/Haskell/TH/Ppr.hs b/Language/Haskell/TH/Ppr.hs
index 8bd3b84..4096d9e 100644
--- a/Language/Haskell/TH/Ppr.hs
+++ b/Language/Haskell/TH/Ppr.hs
@@ -485,6 +485,14 @@ instance Ppr TyLit where
instance Ppr TyVarBndr where
ppr (PlainTV nm) = ppr nm
ppr (KindedTV nm k) = parens (ppr nm <+> text "::" <+> ppr k)
+ ppr (RoledTV nm r) = ppr nm <> text "@" <> ppr r
+ ppr (KindedRoledTV nm k r)
+ = parens (ppr nm <+> text "::" <+> ppr k) <> text "@" <> ppr r
+
+instance Ppr Role where
+ ppr Nominal = text "N"
+ ppr Representational = text "R"
+ ppr Phantom = text "P"
------------------------------
pprCxt :: Cxt -> Doc
diff --git a/Language/Haskell/TH/Syntax.hs b/Language/Haskell/TH/Syntax.hs
index 9d6ae93..2995b58 100644
--- a/Language/Haskell/TH/Syntax.hs
+++ b/Language/Haskell/TH/Syntax.hs
@@ -1258,12 +1258,20 @@ data Type = ForallT [TyVarBndr] Cxt Type -- ^ @forall \<vars\>. \<ctxt\> -> \<t
data TyVarBndr = PlainTV Name -- ^ @a@
| KindedTV Name Kind -- ^ @(a :: k)@
+ | RoledTV Name Role -- ^ @a\@R@
+ | KindedRoledTV Name Kind Role -- ^ @(a :: k)\@R@
deriving( Show, Eq, Data, Typeable )
data TyLit = NumTyLit Integer -- ^ @2@
| StrTyLit String -- ^ @"Hello"@
deriving ( Show, Eq, Data, Typeable )
+-- | Role annotations
+data Role = Nominal -- ^ @N@
+ | Representational -- ^ @R@
+ | Phantom -- ^ @P@
+ deriving( Show, Eq, Data, Typeable )
+
-- | To avoid duplication between kinds and types, they
-- are defined to be the same. Naturally, you would never
-- have a type be 'StarT' and you would never have a kind
More information about the ghc-commits
mailing list