%
\section[TysWiredIn]{Wired-in knowledge about {\em non-primitive} types}
-This module is about types that can be defined in Haskell, but which
-must be wired into the compiler nonetheless.
-
-This module tracks the ``state interface'' document, ``GHC prelude:
-types and operations.''
-
\begin{code}
+-- | This module is about types that can be defined in Haskell, but which
+-- must be wired into the compiler nonetheless. C.f module TysPrim
module TysWiredIn (
+ -- * All wired in things
wiredInTyCons,
+ -- * Bool
boolTy, boolTyCon, boolTyCon_RDR, boolTyConName,
trueDataCon, trueDataConId, true_RDR,
falseDataCon, falseDataConId, false_RDR,
+ -- * Char
charTyCon, charDataCon, charTyCon_RDR,
charTy, stringTy, charTyConName,
-
+ -- * Double
doubleTyCon, doubleDataCon, doubleTy, doubleTyConName,
+ -- * Float
floatTyCon, floatDataCon, floatTy, floatTyConName,
+ -- * Int
intTyCon, intDataCon, intTyCon_RDR, intDataCon_RDR, intTyConName,
intTy,
+ -- * Word
wordTyCon, wordDataCon, wordTyConName, wordTy,
+ -- * List
listTyCon, nilDataCon, consDataCon,
listTyCon_RDR, consDataCon_RDR, listTyConName,
mkListTy,
- -- tuples
+ -- * Tuples
mkTupleTy,
tupleTyCon, tupleCon,
unitTyCon, unitDataCon, unitDataConId, pairTyCon,
unboxedSingletonTyCon, unboxedSingletonDataCon,
unboxedPairTyCon, unboxedPairDataCon,
-
- boxedTupleArr, unboxedTupleArr,
+ -- * Unit
unitTy,
- -- parallel arrays
+ -- * Parallel arrays
mkPArrTy,
parrTyCon, parrFakeCon, isPArrTyCon, isPArrFakeCon,
parrTyCon_RDR, parrTyConName
) where
+#include "HsVersions.h"
+
import {-# SOURCE #-} MkId( mkDataConIds )
-- friends:
import Constants ( mAX_TUPLE_SIZE )
import Module ( Module )
import RdrName
-import Name ( Name, BuiltInSyntax(..), nameUnique, nameOccName,
- nameModule, mkWiredInName )
-import OccName ( mkOccNameFS, tcName, dataName, mkTupleOcc,
- mkDataConWorkerOcc )
+import Name
import DataCon ( DataCon, mkDataCon, dataConWorkId, dataConSourceArity )
import Var
import TyCon ( TyCon, AlgTyConRhs(DataTyCon), tyConDataCons,
import TypeRep ( mkArrowKinds, liftedTypeKind, ubxTupleKind )
import Unique ( incrUnique, mkTupleTyConUnique,
mkTupleDataConUnique, mkPArrDataConUnique )
-import Array
+import Data.Array
import FastString
import Outputable
\begin{code}
mkWiredInTyConName :: BuiltInSyntax -> Module -> FastString -> Unique -> TyCon -> Name
mkWiredInTyConName built_in modu fs unique tycon
- = mkWiredInName modu (mkOccNameFS tcName fs) unique
+ = mkWiredInName modu (mkTcOccFS fs) unique
(ATyCon tycon) -- Relevant TyCon
built_in
mkWiredInDataConName :: BuiltInSyntax -> Module -> FastString -> Unique -> DataCon -> Name
mkWiredInDataConName built_in modu fs unique datacon
- = mkWiredInName modu (mkOccNameFS dataName fs) unique
+ = mkWiredInName modu (mkDataOccFS fs) unique
(ADataCon datacon) -- Relevant DataCon
built_in
tyvars
[] -- No stupid theta
(DataTyCon cons is_enum)
- [] -- No record selectors
NoParentTyCon
is_rec
True -- All the wired-in tycons have generics
[] -- No existential type variables
[] -- No equality spec
[] -- No theta
- arg_tys tycon
+ arg_tys (mkTyConApp tycon (mkTyVarTys tyvars))
+ tycon
[] -- No stupid theta
(mkDataConIds bogus_wrap_name wrk_name data_con)
- modu = nameModule dc_name
+ modu = ASSERT( isExternalName dc_name )
+ nameModule dc_name
wrk_occ = mkDataConWorkerOcc (nameOccName dc_name)
wrk_key = incrUnique (nameUnique dc_name)
wrk_name = mkWiredInName modu wrk_occ wrk_key
unboxedPairDataCon = tupleCon Unboxed 2
\end{code}
+
%************************************************************************
%* *
\subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
nilDataCon :: DataCon
nilDataCon = pcDataCon nilDataConName alpha_tyvar [] listTyCon
+
consDataCon :: DataCon
consDataCon = pcDataConWithFixity True {- Declared infix -}
consDataConName
\end{itemize}
\begin{code}
-mkTupleTy :: Boxity -> Int -> [Type] -> Type
-mkTupleTy boxity arity tys = mkTyConApp (tupleTyCon boxity arity) tys
+mkTupleTy :: Boxity -> [Type] -> Type
+-- Special case for *boxed* 1-tuples, which are represented by the type itself
+mkTupleTy boxity [ty] | Boxed <- boxity = ty
+mkTupleTy boxity tys = mkTyConApp (tupleTyCon boxity (length tys)) tys
unitTy :: Type
-unitTy = mkTupleTy Boxed 0 []
+unitTy = mkTupleTy Boxed []
\end{code}
%************************************************************************
Special syntax for parallel arrays needs some wired in definitions.
\begin{code}
--- construct a type representing the application of the parallel array
--- constructor
---
+-- | Construct a type representing the application of the parallel array constructor
mkPArrTy :: Type -> Type
mkPArrTy ty = mkTyConApp parrTyCon [ty]
--- represents the type constructor of parallel arrays
+-- | Represents the type constructor of parallel arrays
--
--- * this must match the definition in `PrelPArr'
+-- * This must match the definition in @PrelPArr@
--
-- NB: Although the constructor is given here, it will not be accessible in
-- user code as it is not in the environment of any compiled module except
--- `PrelPArr'.
+-- @PrelPArr@.
--
parrTyCon :: TyCon
parrTyCon = pcNonRecDataTyCon parrTyConName alpha_tyvar [parrDataCon]
alpha_ty]
parrTyCon
--- check whether a type constructor is the constructor for parallel arrays
---
+-- | Check whether a type constructor is the constructor for parallel arrays
isPArrTyCon :: TyCon -> Bool
isPArrTyCon tc = tyConName tc == parrTyConName
--- fake array constructors
+-- | Fake array constructors
--
--- * these constructors are never really used to represent array values;
+-- * These constructors are never really used to represent array values;
-- however, they are very convenient during desugaring (and, in particular,
-- in the pattern matching compiler) to treat array pattern just like
-- yet another constructor pattern
tyvar = head alphaTyVars
tyvarTys = replicate arity $ mkTyVarTy tyvar
nameStr = mkFastString ("MkPArr" ++ show arity)
- name = mkWiredInName gHC_PARR (mkOccNameFS dataName nameStr) unique
+ name = mkWiredInName gHC_PARR (mkDataOccFS nameStr) unique
(ADataCon data_con) UserSyntax
unique = mkPArrDataConUnique arity
--- checks whether a data constructor is a fake constructor for parallel arrays
---
+-- | Checks whether a data constructor is a fake constructor for parallel arrays
isPArrFakeCon :: DataCon -> Bool
isPArrFakeCon dcon = dcon == parrFakeCon (dataConSourceArity dcon)
\end{code}