Commit 94e90962 authored by simonpj's avatar simonpj
Browse files

[project @ 2004-07-19 11:29:39 by simonpj]

Template Haskell improvements

a) Make '() and '[] work.
b) Add tupleTypeName, tupleDataName
b) Try to improve error message for (lack of) existential data constructors in TH
parent 08a11a72
......@@ -14,6 +14,7 @@ module Language.Haskell.TH(
mkName, -- :: String -> Name
newName, -- :: String -> Q Name
nameBase, -- :: Name -> String
tupleTypeName, tupleDataName, -- Int -> Name
-- The algebraic data types
Dec(..), Exp(..), Con(..), Type(..), Cxt, Match(..),
......@@ -28,18 +29,18 @@ module Language.Haskell.TH(
StmtQ, RangeQ, StrictTypeQ, VarStrictTypeQ, PatQ, FieldPatQ,
intPrimL, floatPrimL, doublePrimL, integerL, charL, stringL, rationalL,
litP, varP, tupP, conP, infixP, tildeP, asP, wildP, recP, listP, sigP,
fieldPat,
fieldPat,
bindS, letS, noBindS, parS,
fromR, fromThenR, fromToR, fromThenToR,
normalB, guardedB, normalG, normalGE, patG, patGE, match, clause,
dyn, global, varE, conE, litE, appE, infixE, infixApp, sectionL, sectionR,
lamE, lam1E, tupE, condE, letE, caseE, doE, compE, arithSeqE,
fromE, fromThenE, fromToE, fromThenToE,
listE, sigE, recConE, recUpdE, stringE, fieldExp,
listE, sigE, recConE, recUpdE, stringE, fieldExp,
valD, funD, tySynD, dataD, newtypeD, classD, instanceD, sigD, forImpD,
cxt, normalC, recC, infixC,
forallT, varT, conT, appT, arrowT, listT, tupleT,
isStrict, notStrict, strictType, varStrictType,
forallT, varT, conT, appT, arrowT, listT, tupleT,
isStrict, notStrict, strictType, varStrictType,
cCall, stdCall, unsafe, safe, threadsafe,
-- Pretty-printer
......
......@@ -37,6 +37,7 @@ module Language.Haskell.TH.Syntax(
returnQ, bindQ, sequenceQ,
NameFlavour(..), NameSpace (..),
mkNameG_v, mkNameG_d, mkNameG_tc, mkNameU,
tupleTypeName, tupleDataName,
OccName, mkOccName, occString,
ModName, mkModName, modString
) where
......@@ -239,20 +240,20 @@ falseName = mkNameG DataName "GHC.Base" "False"
-----------------------------------------------------
type ModName = PackedString -- Module name
mkModName :: String -> ModName
mkModName s = packString s
modString :: ModName -> String
modString m = unpackPS m
-----------------------------------------------------
-- OccName
-----------------------------------------------------
-- An OccName (occurrence name) records which name space it is from
type OccName = PackedString
mkOccName :: String -> OccName
mkOccName s = packString s
......@@ -260,7 +261,6 @@ occString :: OccName -> String
occString occ = unpackPS occ
-----------------------------------------------------
-- Names
-----------------------------------------------------
......@@ -304,7 +304,7 @@ mkNameU :: String -> Uniq -> Name -- Only used internally
mkNameU s (I# u) = Name (mkOccName s) (NameU u)
mkNameG :: NameSpace -> String -> String -> Name -- Used for 'x etc, but not available
mkNameG ns mod occ -- to the programmer
mkNameG ns mod occ -- to the programmer
= Name (mkOccName occ) (NameG ns (mkModName mod))
mkNameG_v = mkNameG VarName
......@@ -341,6 +341,25 @@ instance Show Name where
show (Name occ (NameG ns m)) = modString m ++ "." ++ occString occ
-- Tuple data and type constructors
tupleDataName :: Int -> Name -- Data constructor
tupleTypeName :: Int -> Name -- Type constructor
tupleDataName 0 = mk_tup_name 0 DataName
tupleDataName 1 = error "tupleDataName 1"
tupleDataName n = mk_tup_name (n-1) DataName
tupleTypeName 0 = mk_tup_name 0 TcClsName
tupleTypeName 1 = error "tupleTypeName 1"
tupleTypeName n = mk_tup_name (n-1) TcClsName
mk_tup_name n_commas space
= Name occ (NameG space tup_mod)
where
occ = mkOccName ('(' : replicate n_commas ',' ++ ")")
tup_mod = mkModName "GHC.Tuple"
-----------------------------------------------------
--
-- The Info returned by reification
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment