getSynTyConDefn,
maybeTyConSingleCon,
- isEnumerationTyCon,
+ isEnumerationTyCon, isTupleTyCon,
derivedFor
) where
SYN_IE(Class), GenClass,
SYN_IE(Id), GenId,
splitSigmaTy, splitFunTy,
- mkTupleCon, isNullaryDataCon, idType
+ tupleCon, isNullaryDataCon, idType
--LATER: specMaybeTysSuffix
)
import Kind ( Kind, mkBoxedTypeKind, mkArrowKind, resultKind, argKind )
import Maybes
-import Name ( Name, RdrName(..), appendRdr, nameUnique,
- mkTupleTyConName, mkFunTyConName
- )
-import Unique ( Unique, funTyConKey, mkTupleTyConUnique )
+import Name ( Name, nameUnique, mkWiredInTyConName )
+import Unique ( Unique, funTyConKey )
import Pretty ( SYN_IE(Pretty), PrettyRep )
import PrimRep ( PrimRep(..) )
+import PrelMods ( gHC__, pREL_TUP, pREL_BASE )
+import Lex ( mkTupNameStr )
import SrcLoc ( SrcLoc, mkBuiltinSrcLoc )
-import Util ( nOfThem, isIn, Ord3(..), panic, panic#, assertPanic, pprPanic{-ToDo:rm-} )
-import {-hide me-}
- PprType (pprTyCon)
-import {-hide me-}
- PprStyle--ToDo:rm
+import Util ( nOfThem, isIn, Ord3(..), panic, panic#, assertPanic )
+--import {-hide me-}
+-- PprType (pprTyCon)
+--import {-hide me-}
+-- PprStyle--ToDo:rm
\end{code}
\begin{code}
[TyVar]
[(Class,Type)] -- Its context
[Id] -- Its data constructors, with fully polymorphic types
+ -- This list can be empty, when we import a data type abstractly,
+ -- either (a) the interface is hand-written and doesn't give
+ -- the constructors, or
+ -- (b) in a quest for fast compilation we don't import
+ -- the constructors
[Class] -- Classes which have derived instances
NewOrData
\end{code}
\begin{code}
-mkFunTyCon = FunTyCon
-mkSpecTyCon = SpecTyCon
+mkFunTyCon = FunTyCon
+mkFunTyConName = mkWiredInTyConName funTyConKey gHC__ SLIT("->") FunTyCon
-mkTupleTyCon arity
- = TupleTyCon u n arity
- where
- n = mkTupleTyConName arity
- u = uniqueOf n
+mkSpecTyCon = SpecTyCon
+mkTupleTyCon = TupleTyCon
mkDataTyCon name = DataTyCon (nameUnique name) name
mkPrimTyCon name = PrimTyCon (nameUnique name) name
tyConFamilySize :: TyCon -> Int
tyConDataCons (DataTyCon _ _ _ _ _ data_cons _ _) = data_cons
-tyConDataCons (TupleTyCon _ _ a) = [mkTupleCon a]
+tyConDataCons (TupleTyCon _ _ a) = [tupleCon a]
tyConDataCons other = []
-- You may think this last equation should fail,
-- but it's quite convenient to return no constructors for
tyConFamilySize (DataTyCon _ _ _ _ _ data_cons _ _) = length data_cons
tyConFamilySize (TupleTyCon _ _ _) = 1
#ifdef DEBUG
-tyConFamilySize other = pprPanic "tyConFamilySize:" (pprTyCon PprDebug other)
+--tyConFamilySize other = pprPanic "tyConFamilySize:" (pprTyCon PprDebug other)
#endif
tyConPrimRep :: TyCon -> PrimRep
\begin{code}
maybeTyConSingleCon :: TyCon -> Maybe Id
-maybeTyConSingleCon (TupleTyCon _ _ arity) = Just (mkTupleCon arity)
+maybeTyConSingleCon (TupleTyCon _ _ arity) = Just (tupleCon arity)
maybeTyConSingleCon (DataTyCon _ _ _ _ _ [c] _ _) = Just c
maybeTyConSingleCon (DataTyCon _ _ _ _ _ _ _ _) = Nothing
maybeTyConSingleCon (PrimTyCon _ _ _ _) = Nothing
= arity == 0
isEnumerationTyCon (DataTyCon _ _ _ _ _ data_cons _ _)
= not (null data_cons) && all isNullaryDataCon data_cons
+
+
+isTupleTyCon (TupleTyCon _ _ arity) = arity >= 2 -- treat "0-tuple" specially
+isTupleTyCon (SpecTyCon tc tys) = isTupleTyCon tc
+isTupleTyCon other = False
+
+
\end{code}
@derivedFor@ reports if we have an {\em obviously}-derived instance
getName other_tc = moduleNamePair (expectJust "tycon1" (getName other_tc))
getName other = Nothing
-}
+
\end{code}