diff options
author | Iavor S. Diatchki <iavor.diatchki@gmail.com> | 2012-03-15 00:08:06 -0700 |
---|---|---|
committer | Iavor S. Diatchki <iavor.diatchki@gmail.com> | 2012-03-15 00:08:06 -0700 |
commit | b058d9716b4980408f9cf23adfc4f3ef8ba451be (patch) | |
tree | d126707809a03dbecf072c93f6ef62a91630a1b6 /libraries | |
parent | 2638e808707c20b91df10da8d5b22c39a351c6fc (diff) | |
download | haskell-b058d9716b4980408f9cf23adfc4f3ef8ba451be.tar.gz |
Updates to type-literal support.
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/template-haskell/Language/Haskell/TH/Lib.hs | 15 | ||||
-rw-r--r-- | libraries/template-haskell/Language/Haskell/TH/Ppr.hs | 6 | ||||
-rw-r--r-- | libraries/template-haskell/Language/Haskell/TH/Syntax.hs | 6 |
3 files changed, 14 insertions, 13 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Lib.hs b/libraries/template-haskell/Language/Haskell/TH/Lib.hs index 5ead7b55c4..2a9f886650 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Lib.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Lib.hs @@ -461,8 +461,8 @@ arrowT = return ArrowT listT :: TypeQ listT = return ListT -literalT :: TyLit -> TypeQ -literalT l = return (LiteralT l) +litT :: TyLit -> TypeQ +litT l = return (LitT l) tupleT :: Int -> TypeQ tupleT i = return (TupleT i) @@ -490,10 +490,14 @@ varStrictType v st = do (s, t) <- st -- * Type Literals -numberTL :: Integer -> TyLitQ -numberTL n = if n >= 0 then return (NumberTL n) +numTyLit :: Integer -> TyLitQ +numTyLit n = if n >= 0 then return (NumTyLit n) else fail ("Negative type-level number: " ++ show n) +strTyLit :: String -> TyLitQ +strTyLit s = return (StrTyLit s) + + ------------------------------------------------------------------------------- -- * Kind @@ -507,9 +511,6 @@ kindedTV = KindedTV starK :: Kind starK = StarK -natK :: Kind -natK = NatK - arrowK :: Kind -> Kind -> Kind arrowK = ArrowK diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs index 0e3220675f..dc2ccae2de 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs @@ -388,7 +388,7 @@ pprParendType (TupleT n) = parens (hcat (replicate (n-1) comma)) pprParendType (UnboxedTupleT n) = hashParens $ hcat $ replicate (n-1) comma pprParendType ArrowT = parens (text "->") pprParendType ListT = text "[]" -pprParendType (LiteralT l) = pprTyLit l +pprParendType (LitT l) = pprTyLit l pprParendType other = parens (ppr other) instance Ppr Type where @@ -418,7 +418,8 @@ split t = go t [] go ty args = (ty, args) pprTyLit :: TyLit -> Doc -pprTyLit (NumberTL n) = integer n +pprTyLit (NumTyLit n) = integer n +pprTyLit (StrTyLit s) = text (show s) instance Ppr TyLit where ppr = pprTyLit @@ -430,7 +431,6 @@ instance Ppr TyVarBndr where instance Ppr Kind where ppr StarK = char '*' - ppr NatK = text "Nat" ppr (ArrowK k1 k2) = pprArrowArgKind k1 <+> text "->" <+> ppr k2 pprArrowArgKind :: Kind -> Doc diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs index 1e71ff509d..72e644b153 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs @@ -987,18 +987,18 @@ data Type = ForallT [TyVarBndr] Cxt Type -- ^ @forall <vars>. <ctxt> -> <type>@ | ListT -- ^ @[]@ | AppT Type Type -- ^ @T a b@ | SigT Type Kind -- ^ @t :: k@ - | LiteralT TyLit -- ^ @0,1,2, etc.@ + | LitT TyLit -- ^ @0,1,2, etc.@ deriving( Show, Eq, Data, Typeable ) data TyVarBndr = PlainTV Name -- ^ @a@ | KindedTV Name Kind -- ^ @(a :: k)@ deriving( Show, Eq, Data, Typeable ) -data TyLit = NumberTL Integer +data TyLit = NumTyLit Integer + | StrTyLit String deriving ( Show, Eq, Data, Typeable ) data Kind = StarK -- ^ @'*'@ - | NatK -- ^ @Nat@ | ArrowK Kind Kind -- ^ @k1 -> k2@ deriving( Show, Eq, Data, Typeable ) |