Add a new flag XDefaultSignatures to enable just the signatures on the default method...
[ghc-hetmet.git] / compiler / types / TyCon.lhs
index 2350973..5804d49 100644 (file)
@@ -49,7 +49,7 @@ module TyCon(
        isTyConAssoc,
        isRecursiveTyCon,
        isHiBootTyCon,
-        isImplicitTyCon, tyConHasGenerics,
+        isImplicitTyCon, 
 
         -- ** Extracting information out of TyCons
        tyConName,
@@ -67,7 +67,7 @@ module TyCon(
        tyConExtName,           -- External name for foreign types
        algTyConRhs,
         newTyConRhs, newTyConEtadRhs, unwrapNewTyCon_maybe, 
-        tupleTyConBoxity,
+        tupleTyConBoxity, tupleTyConArity,
 
         -- ** Manipulating TyCons
        tcExpandTyCon_maybe, coreExpandTyCon_maybe,
@@ -129,15 +129,28 @@ Note [Type synonym families]
 
 * Translation of type instance decl:
        type instance F [a] = Maybe a
-  translates to
-    A SynTyCon 'R:FList a', whose 
+  translates to a "representation TyCon", 'R:FList', where
+     R:FList is a SynTyCon, whose 
        SynTyConRhs is (SynonymTyCon (Maybe a))
        TyConParent is (FamInstTyCon F [a] co)
          where co :: F [a] ~ R:FList a
-    Notice that we introduce a gratuitous vanilla type synonym
+
+  It's very much as if the user had written
+       type instance F [a] = R:FList a
        type R:FList a = Maybe a
-    solely so that type and data families can be treated more
-    uniformly, via a single FamInstTyCon descriptor        
+  Indeed, in GHC's internal representation, the RHS of every
+  'type instance' is simply an application of the representation
+  TyCon to the quantified varaibles.
+
+  The intermediate representation TyCon is a bit gratuitous, but 
+  it means that:
+
+        each 'type instance' decls is in 1-1 correspondance 
+       with its representation TyCon
+
+  So the result of typechecking a 'type instance' decl is just a
+  TyCon.  In turn this means that type and data families can be
+  treated uniformly.
 
 * In the future we might want to support
     * closed type families (esp when we have proper kinds)
@@ -304,11 +317,7 @@ data TyCon
 
        algTcRec :: RecFlag,      -- ^ Tells us whether the data type is part 
                                   -- of a mutually-recursive group or not
-
-       hasGenerics :: Bool,      -- ^ Whether generic (in the -XGenerics sense) 
-                                  -- to\/from functions are available in the exports 
-                                  -- of the data type's source module.
-
+       
        algTcParent :: TyConParent      -- ^ Gives the class or family declaration 'TyCon' 
                                         -- for derived 'TyCon's representing class 
                                         -- or family instances, respectively. 
@@ -324,8 +333,7 @@ data TyCon
        tyConArity  :: Arity,
        tyConBoxed  :: Boxity,
        tyConTyVars :: [TyVar],
-       dataCon     :: DataCon, -- ^ Corresponding tuple data constructor
-       hasGenerics :: Bool
+       dataCon     :: DataCon -- ^ Corresponding tuple data constructor
     }
 
   -- | Represents type synonyms
@@ -582,7 +590,7 @@ data CoTyConDesc
 
 Note [Enumeration types]
 ~~~~~~~~~~~~~~~~~~~~~~~~
-We define datatypes with no constructors to not be
+We define datatypes with no constructors to *not* be
 enumerations; this fixes trac #2578,  Otherwise we
 end up generating an empty table for
   <mod>_<type>_closure_tbl
@@ -590,6 +598,16 @@ which is used by tagToEnum# to map Int# to constructors
 in an enumeration. The empty table apparently upset
 the linker.
 
+Moreover, all the data constructor must be enumerations, meaning
+they have type  (forall abc. T a b c).  GADTs are not enumerations.
+For example consider
+    data T a where
+      T1 :: T Int
+      T2 :: T Bool
+      T3 :: T a
+What would [T1 ..] be?  [T1,T3] :: T Int? Easiest thing is to exclude them.
+See Trac #4528.
+
 Note [Newtype coercions]
 ~~~~~~~~~~~~~~~~~~~~~~~~
 The NewTyCon field nt_co is a a TyCon (a coercion constructor in fact)
@@ -753,10 +771,9 @@ mkAlgTyCon :: Name
            -> AlgTyConRhs       -- ^ Information about dat aconstructors
            -> TyConParent
            -> RecFlag           -- ^ Is the 'TyCon' recursive?
-           -> Bool              -- ^ Does it have generic functions? See 'hasGenerics'
            -> Bool              -- ^ Was the 'TyCon' declared with GADT syntax?
            -> TyCon
-mkAlgTyCon name kind tyvars stupid rhs parent is_rec gen_info gadt_syn
+mkAlgTyCon name kind tyvars stupid rhs parent is_rec gadt_syn
   = AlgTyCon { 
        tyConName        = name,
        tyConUnique      = nameUnique name,
@@ -767,14 +784,13 @@ mkAlgTyCon name kind tyvars stupid rhs parent is_rec gen_info gadt_syn
        algTcRhs         = rhs,
        algTcParent      = ASSERT( okParent name parent ) parent,
        algTcRec         = is_rec,
-       algTcGadtSyntax  = gadt_syn,
-       hasGenerics      = gen_info
+       algTcGadtSyntax  = gadt_syn
     }
 
 -- | Simpler specialization of 'mkAlgTyCon' for classes
 mkClassTyCon :: Name -> Kind -> [TyVar] -> AlgTyConRhs -> Class -> RecFlag -> TyCon
 mkClassTyCon name kind tyvars rhs clas is_rec =
-  mkAlgTyCon name kind tyvars [] rhs (ClassTyCon clas) is_rec False False
+  mkAlgTyCon name kind tyvars [] rhs (ClassTyCon clas) is_rec False
 
 mkTupleTyCon :: Name 
              -> Kind    -- ^ Kind of the resulting 'TyCon'
@@ -782,9 +798,8 @@ mkTupleTyCon :: Name
              -> [TyVar] -- ^ 'TyVar's scoped over: see 'tyConTyVars'
              -> DataCon 
              -> Boxity  -- ^ Whether the tuple is boxed or unboxed
-             -> Bool    -- ^ Does it have generic functions? See 'hasGenerics'
              -> TyCon
-mkTupleTyCon name kind arity tyvars con boxed gen_info
+mkTupleTyCon name kind arity tyvars con boxed 
   = TupleTyCon {
        tyConUnique = nameUnique name,
        tyConName = name,
@@ -792,8 +807,7 @@ mkTupleTyCon name kind arity tyvars con boxed gen_info
        tyConArity = arity,
        tyConBoxed = boxed,
        tyConTyVars = tyvars,
-       dataCon = con,
-       hasGenerics = gen_info
+       dataCon = con
     }
 
 -- ^ Foreign-imported (.NET) type constructors are represented
@@ -1064,6 +1078,11 @@ isBoxedTupleTyCon _                                  = False
 tupleTyConBoxity :: TyCon -> Boxity
 tupleTyConBoxity tc = tyConBoxed tc
 
+-- | Extract the arity of the given 'TyCon', if it is a 'TupleTyCon'.
+-- Panics otherwise
+tupleTyConArity :: TyCon -> Arity
+tupleTyConArity tc = tyConArity tc
+
 -- | Is this a recursive 'TyCon'?
 isRecursiveTyCon :: TyCon -> Bool
 isRecursiveTyCon (AlgTyCon {algTcRec = Recursive}) = True
@@ -1172,11 +1191,6 @@ expand tvs rhs tys
 \end{code}
 
 \begin{code}
--- | Does this 'TyCon' have any generic to\/from functions available? See also 'hasGenerics'
-tyConHasGenerics :: TyCon -> Bool
-tyConHasGenerics (AlgTyCon {hasGenerics = hg})   = hg
-tyConHasGenerics (TupleTyCon {hasGenerics = hg}) = hg
-tyConHasGenerics _                               = False        -- Synonyms
 
 tyConKind :: TyCon -> Kind
 tyConKind (FunTyCon   { tc_kind = k }) = k