mkDataTyConRhs cons
= DataTyCon {
data_cons = cons,
- is_enum = -- 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
- -- which is used by tagToEnum# to map Int# to constructors
- -- in an enumeration. The empty table apparently upset
- -- the linker.
- not (null cons) &&
+ is_enum = not (null cons) &&
all isNullarySrcDataCon cons
+ -- See Note [Enumeration types] in TyCon
}
mkNewTyConRhs :: Name -> TyCon -> DataCon -> TcRnIf m n AlgTyConRhs
-- (see the tag assignment in DataCon.mkDataCon)
is_enum :: Bool -- ^ Cached value: is this an enumeration type?
- -- (See 'isEnumerationTyCon')
+ -- See Note [Enumeration types]
}
-- | Information about those 'TyCon's derived from a @newtype@ declaration
| CoUnsafe
\end{code}
+Note [Enumeration types]
+~~~~~~~~~~~~~~~~~~~~~~~~
+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
+which is used by tagToEnum# to map Int# to constructors
+in an enumeration. The empty table apparently upset
+the linker.
+
Note [Newtype coercions]
~~~~~~~~~~~~~~~~~~~~~~~~
The NewTyCon field nt_co is a a TyCon (a coercion constructor in fact)
-- | Is this an algebraic 'TyCon' which is just an enumeration of values?
isEnumerationTyCon :: TyCon -> Bool
+-- See Note [Enumeration types] in TyCon
isEnumerationTyCon (AlgTyCon {algTcRhs = DataTyCon { is_enum = res }}) = res
isEnumerationTyCon (TupleTyCon {tyConArity = arity}) = arity == 0
isEnumerationTyCon _ = False