[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / compiler / prelude / TysWiredIn.lhs
index ce28587..63dd524 100644 (file)
@@ -1,5 +1,5 @@
 %
-% (c) The GRASP Project, Glasgow University, 1994-1995
+% (c) The GRASP Project, Glasgow University, 1994-1998
 %
 \section[TysWiredIn]{Wired-in knowledge about {\em non-primitive} types}
 
@@ -10,8 +10,6 @@ This module tracks the ``state interface'' document, ``GHC prelude:
 types and operations.''
 
 \begin{code}
-#include "HsVersions.h"
-
 module TysWiredIn (
        addrDataCon,
        addrTy,
@@ -21,456 +19,489 @@ module TysWiredIn (
        charDataCon,
        charTy,
        charTyCon,
-       cmpTagTy,
-       cmpTagTyCon,
        consDataCon,
        doubleDataCon,
        doubleTy,
+       isDoubleTy,
        doubleTyCon,
-       eqPrimDataCon,
        falseDataCon,
        floatDataCon,
        floatTy,
+       isFloatTy,
        floatTyCon,
-       getStatePairingConInfo,
-       gtPrimDataCon,
+
+       voidTyCon, voidTy, 
+
        intDataCon,
        intTy,
        intTyCon,
+       isIntTy,
+       inIntRange,
+
+       int8TyCon,
+       int16TyCon,
+       int32TyCon,
+
+       int64TyCon,
+       int64DataCon,
+--     int64Ty,
+
        integerTy,
        integerTyCon,
-       liftDataCon,
-       liftTyCon,
+       integerDataCon,
+       isIntegerTy,
+
        listTyCon,
-       ltPrimDataCon,
-       mallocPtrTyCon,
-       mkLiftTy,
+
        mkListTy,
-       mkPrimIoTy,
-       mkStateTransformerTy,
-       mkTupleTy,
        nilDataCon,
-       primIoTyCon,
-       ratioDataCon,
-       ratioTyCon,
-       rationalTy,
-       rationalTyCon,
-       realWorldStateTy,
-       return2GMPsTyCon,
-       returnIntAndGMPTyCon,
-       stTyCon,
-       stablePtrTyCon,
-       stateAndAddrPrimTyCon,
-       stateAndArrayPrimTyCon,
-       stateAndByteArrayPrimTyCon,
-       stateAndCharPrimTyCon,
-       stateAndDoublePrimTyCon,
-       stateAndFloatPrimTyCon,
-       stateAndIntPrimTyCon,
-       stateAndMallocPtrPrimTyCon,
-       stateAndMutableArrayPrimTyCon,
-       stateAndMutableByteArrayPrimTyCon,
-       stateAndPtrPrimTyCon,
-       stateAndStablePtrPrimTyCon,
-       stateAndSynchVarPrimTyCon,
-       stateAndWordPrimTyCon,
+
+       -- tuples
+       mkTupleTy,
+       tupleTyCon, tupleCon, unitTyCon, unitDataCon, pairTyCon, pairDataCon,
+
+       -- unboxed tuples
+       mkUnboxedTupleTy,
+       unboxedTupleTyCon, unboxedTupleCon, 
+       unboxedPairTyCon, unboxedPairDataCon,
+
        stateDataCon,
        stateTyCon,
+       realWorldStateTy,
+
+       stablePtrTyCon,
        stringTy,
-       stringTyCon,
        trueDataCon,
        unitTy,
        wordDataCon,
        wordTy,
-       wordTyCon
+       wordTyCon,
+
+       word8TyCon,
+       word16TyCon,
+       word32TyCon,
+
+       word64DataCon,
+--     word64Ty,
+       word64TyCon,
+       
+       isFFIArgumentTy,  -- :: Type -> Bool
+       isFFIResultTy,    -- :: Type -> Bool
+       isFFIExternalTy,  -- :: Type -> Bool
+       isAddrTy,         -- :: Type -> Bool
+
     ) where
 
-import Pretty          --ToDo:rm debugging only
+#include "HsVersions.h"
 
-import PrelFuns                -- help functions, types and things
+import {-# SOURCE #-} MkId( mkDataConId )
+
+-- friends:
+import PrelMods
 import TysPrim
 
-import AbsUniType      ( applyTyCon, mkTupleTyCon, mkSynonymTyCon,
-                         getUniDataTyCon_maybe, mkSigmaTy, TyCon
-                         , pprUniType --ToDo: rm debugging only
-                         IF_ATTACK_PRAGMAS(COMMA cmpTyCon)
-                       )
-import IdInfo
-import Maybes          ( Maybe(..) )
+-- others:
+import Constants       ( mAX_TUPLE_SIZE )
+import Name            ( mkWiredInTyConName, mkWiredInIdName, mkTupNameStr,
+                         mkUbxTupNameStr )
+import DataCon         ( DataCon, mkDataCon )
+import Var             ( TyVar, tyVarKind )
+import TyCon           ( TyCon, mkAlgTyCon, mkSynTyCon, mkTupleTyCon )
+import BasicTypes      ( Module, Arity, NewOrData(..), 
+                         RecFlag(..), StrictnessMark(..) )
+import Type            ( Type, mkTyConTy, mkTyConApp, mkSigmaTy, mkTyVarTys, 
+                         mkArrowKinds, boxedTypeKind, unboxedTypeKind,
+                         mkFunTy, mkFunTys, isUnLiftedType,
+                         splitTyConApp_maybe, splitAlgTyConApp_maybe,
+                         GenType(..), ThetaType, TauType )
+import PrimRep         ( PrimRep(..) )
 import Unique
-import Util
+import CmdLineOpts      ( opt_GlasgowExts )
+import Util            ( assoc, panic )
+import Array
+
+alpha_tyvar      = [alphaTyVar]
+alpha_ty         = [alphaTy]
+alpha_beta_tyvars = [alphaTyVar, betaTyVar]
+
+pcRecDataTyCon, pcNonRecDataTyCon, pcNonRecNewTyCon
+       :: Unique{-TyConKey-} -> Module -> FAST_STRING
+       -> [TyVar] -> [DataCon] -> TyCon
+
+pcRecDataTyCon    = pcTyCon DataType Recursive
+pcNonRecDataTyCon = pcTyCon DataType NonRecursive
+pcNonRecNewTyCon  = pcTyCon NewType  NonRecursive
+
+pcTyCon new_or_data is_rec key mod str tyvars cons
+  = tycon
+  where
+    tycon = mkAlgTyCon name kind 
+               tyvars 
+               []              -- No context
+               cons
+               []              -- No derivings
+               Nothing         -- Not a dictionary
+               new_or_data
+               is_rec
+
+    name = mkWiredInTyConName key mod str tycon
+    kind = mkArrowKinds (map tyVarKind tyvars) boxedTypeKind
+
+pcSynTyCon key mod str kind arity tyvars expansion
+  = tycon
+  where
+    tycon = mkSynTyCon name kind arity tyvars expansion
+    name  = mkWiredInTyConName key mod str tycon
+
+pcDataCon :: Unique{-DataConKey-} -> Module -> FAST_STRING
+         -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> DataCon
+pcDataCon key mod str tyvars context arg_tys tycon
+  = data_con
+  where
+    data_con = mkDataCon name 
+               [ NotMarkedStrict | a <- arg_tys ]
+               [ {- no labelled fields -} ]
+               tyvars context [] [] arg_tys tycon id
+    name = mkWiredInIdName key mod str id
+    id   = mkDataConId data_con
 \end{code}
 
 %************************************************************************
 %*                                                                     *
-\subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
+\subsection[TysWiredIn-tuples]{The tuple types}
 %*                                                                     *
 %************************************************************************
 
 \begin{code}
-charTy = UniData charTyCon []
+tupleTyCon :: Arity -> TyCon
+tupleTyCon i | i > mAX_TUPLE_SIZE = fst (mk_tuple i)   -- Build one specially
+            | otherwise          = tupleTyConArr!i
 
-charTyCon = pcDataTyCon charTyConKey pRELUDE_BUILTIN SLIT("Char") [] [charDataCon]
-charDataCon = pcDataCon charDataConKey pRELUDE_BUILTIN SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv
-\end{code}
+tupleCon :: Arity -> DataCon
+tupleCon i | i > mAX_TUPLE_SIZE = snd (mk_tuple i)     -- Build one specially
+          | otherwise          = tupleConArr!i
 
-\begin{code}
-intTy = UniData intTyCon []
+tupleTyCons :: [TyCon]
+tupleTyCons = elems tupleTyConArr
 
-intTyCon = pcDataTyCon intTyConKey pRELUDE_BUILTIN SLIT("Int") [] [intDataCon]
-intDataCon = pcDataCon intDataConKey pRELUDE_BUILTIN SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv 
-\end{code}
+tupleTyConArr :: Array Int TyCon
+tupleTyConArr = array (0,mAX_TUPLE_SIZE) ([0..] `zip` map fst tuples)
 
-\begin{code}
-wordTy = UniData wordTyCon []
+tupleConArr :: Array Int DataCon
+tupleConArr = array (0,mAX_TUPLE_SIZE) ([0..] `zip` map snd tuples)
 
-wordTyCon = pcDataTyCon wordTyConKey pRELUDE_BUILTIN SLIT("_Word") [] [wordDataCon]
-wordDataCon = pcDataCon wordDataConKey pRELUDE_BUILTIN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv
+tuples :: [(TyCon,DataCon)]
+tuples = [mk_tuple i | i <- [0..mAX_TUPLE_SIZE]]
+
+mk_tuple :: Int -> (TyCon,DataCon)
+mk_tuple arity = (tycon, tuple_con)
+  where
+       tycon   = mkTupleTyCon tc_name tc_kind arity tyvars tuple_con True
+       tc_name = mkWiredInTyConName tc_uniq mod_name name_str tycon
+       tc_kind = mkArrowKinds (map tyVarKind tyvars) boxedTypeKind
+
+       tuple_con = pcDataCon dc_uniq mod_name name_str tyvars [] tyvar_tys tycon
+       tyvars    = take arity alphaTyVars
+       tyvar_tys = mkTyVarTys tyvars
+       (mod_name, name_str) = mkTupNameStr arity
+       tc_uniq   = mkTupleTyConUnique   arity
+       dc_uniq   = mkTupleDataConUnique arity
+
+unitTyCon = tupleTyCon 0
+pairTyCon = tupleTyCon 2
+
+unitDataCon = tupleCon 0
+pairDataCon = tupleCon 2
 \end{code}
 
+%************************************************************************
+%*                                                                     *
+\subsection[TysWiredIn-ubx-tuples]{Unboxed Tuple Types}
+%*                                                                     *
+%************************************************************************
+
 \begin{code}
-addrTy = UniData addrTyCon []
+unboxedTupleTyCon :: Arity -> TyCon
+unboxedTupleTyCon i | i > mAX_TUPLE_SIZE = fst (mk_unboxed_tuple i)
+                   | otherwise          = unboxedTupleTyConArr!i
 
-addrTyCon = pcDataTyCon addrTyConKey pRELUDE_BUILTIN SLIT("_Addr") [] [addrDataCon]
-addrDataCon = pcDataCon addrDataConKey pRELUDE_BUILTIN SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv
-\end{code}
+unboxedTupleCon :: Arity -> DataCon
+unboxedTupleCon i | i > mAX_TUPLE_SIZE = snd (mk_unboxed_tuple i)
+                 | otherwise          = unboxedTupleConArr!i
 
-\begin{code}
-floatTy        = UniData floatTyCon []
+unboxedTupleTyConArr :: Array Int TyCon
+unboxedTupleTyConArr = array (0,mAX_TUPLE_SIZE) ([0..] `zip` map fst ubx_tuples)
 
-floatTyCon = pcDataTyCon floatTyConKey pRELUDE_BUILTIN SLIT("Float") [] [floatDataCon]
-floatDataCon = pcDataCon floatDataConKey pRELUDE_BUILTIN SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv
-\end{code}
+unboxedTupleConArr :: Array Int DataCon
+unboxedTupleConArr = array (0,mAX_TUPLE_SIZE) ([0..] `zip` map snd ubx_tuples)
 
-\begin{code}
-doubleTy = UniData doubleTyCon []
+ubx_tuples :: [(TyCon,DataCon)]
+ubx_tuples = [mk_unboxed_tuple i | i <- [0..mAX_TUPLE_SIZE]]
 
-doubleTyCon = pcDataTyCon doubleTyConKey pRELUDE_BUILTIN SLIT("Double") [] [doubleDataCon]
-doubleDataCon = pcDataCon doubleDataConKey pRELUDE_BUILTIN SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv
+mk_unboxed_tuple :: Int -> (TyCon,DataCon)
+mk_unboxed_tuple arity = (tycon, tuple_con)
+  where
+       tycon   = mkTupleTyCon tc_name tc_kind arity tyvars tuple_con False
+       tc_name = mkWiredInTyConName tc_uniq mod_name name_str tycon
+       tc_kind = mkArrowKinds (map tyVarKind tyvars) unboxedTypeKind
+
+       tuple_con = pcDataCon dc_uniq mod_name name_str tyvars [] tyvar_tys tycon
+       tyvars    = take arity openAlphaTyVars
+       tyvar_tys = mkTyVarTys tyvars
+       (mod_name, name_str) = mkUbxTupNameStr arity
+       tc_uniq   = mkUbxTupleTyConUnique   arity
+       dc_uniq   = mkUbxTupleDataConUnique arity
+
+unboxedPairTyCon   = unboxedTupleTyCon 2
+unboxedPairDataCon = unboxedTupleCon 2
 \end{code}
 
-\begin{code}
-mkStateTy ty    = applyTyCon stateTyCon [ty]
-realWorldStateTy = mkStateTy realWorldTy -- a common use
+%************************************************************************
+%*                                                                     *
+\subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
+%*                                                                     *
+%************************************************************************
 
-stateTyCon = pcDataTyCon stateTyConKey pRELUDE_BUILTIN SLIT("_State") [alpha_tv] [stateDataCon]
-stateDataCon
-  = pcDataCon stateDataConKey pRELUDE_BUILTIN SLIT("S#")
-       [alpha_tv] [] [mkStatePrimTy alpha] stateTyCon nullSpecEnv
+\begin{code}
+-- The Void type is represented as a data type with no constructors
+-- It's a built in type (i.e. there's no way to define it in Haskell;
+--     the nearest would be
+--
+--             data Void =             -- No constructors!
+--
+-- ) It's boxed; there is only one value of this
+-- type, namely "void", whose semantics is just bottom.
+voidTy    = mkTyConTy voidTyCon
+voidTyCon = pcNonRecDataTyCon voidTyConKey pREL_GHC SLIT("Void") [] [{-No data cons-}]
 \end{code}
 
 \begin{code}
-{- OLD:
-byteArrayTyCon
-  = pcDataTyCon byteArrayTyConKey pRELUDE_ARRAY SLIT("_ByteArray")
-       [alpha_tv] [byteArrayDataCon]
-
-byteArrayDataCon
-  = pcDataCon byteArrayDataConKey pRELUDE_ARRAY SLIT("_ByteArray")
-       [alpha_tv] []
-       [mkTupleTy 2 [alpha, alpha], byteArrayPrimTy]
-       byteArrayTyCon nullSpecEnv
--}
+charTy = mkTyConTy charTyCon
+
+charTyCon = pcNonRecDataTyCon charTyConKey  pREL_BASE  SLIT("Char") [] [charDataCon]
+charDataCon = pcDataCon charDataConKey pREL_BASE SLIT("C#") [] [] [charPrimTy] charTyCon
+
+stringTy = mkListTy charTy -- convenience only
 \end{code}
 
 \begin{code}
-{- OLD:
-mutableArrayTyCon
-  = pcDataTyCon mutableArrayTyConKey gLASGOW_ST SLIT("_MutableArray")
-       [alpha_tv, beta_tv, gamma_tv] [mutableArrayDataCon]
+intTy = mkTyConTy intTyCon 
+
+intTyCon = pcNonRecDataTyCon intTyConKey pREL_BASE SLIT("Int") [] [intDataCon]
+intDataCon = pcDataCon intDataConKey pREL_BASE SLIT("I#") [] [] [intPrimTy] intTyCon
+
+isIntTy :: GenType flexi -> Bool
+isIntTy ty
+  = case (splitAlgTyConApp_maybe ty) of
+       Just (tycon, [], _) -> getUnique tycon == intTyConKey
+       _                   -> False
+
+inIntRange :: Integer -> Bool  -- Tells if an integer lies in the legal range of Ints
+inIntRange i = (min_int <= i) && (i <= max_int)
+
+max_int, min_int :: Integer
+max_int = toInteger maxInt  
+min_int = toInteger minInt
+
+int8TyCon = pcNonRecDataTyCon int8TyConKey iNT SLIT("Int8") [] [int8DataCon]
   where
-    mutableArrayDataCon
-      = pcDataCon mutableArrayDataConKey gLASGOW_ST SLIT("_MutableArray")
-           [alpha_tv, beta_tv, gamma_tv] []
-           [mkTupleTy 2 [beta, beta], applyTyCon mutableArrayPrimTyCon [alpha, gamma]]
-           mutableArrayTyCon nullSpecEnv
--}
-\end{code}
+   int8DataCon = pcDataCon int8DataConKey iNT SLIT("I8#") [] [] [intPrimTy] int8TyCon
 
-\begin{code}
-{-
-mutableByteArrayTyCon
-  = pcDataTyCon mutableByteArrayTyConKey gLASGOW_ST SLIT("_MutableByteArray")
-       [alpha_tv, beta_tv] [mutableByteArrayDataCon]
-
-mutableByteArrayDataCon
-  = pcDataCon mutableByteArrayDataConKey gLASGOW_ST SLIT("_MutableByteArray")
-       [alpha_tv, beta_tv] []
-       [mkTupleTy 2 [beta, beta], mkMutableByteArrayPrimTy alpha]
-       mutableByteArrayTyCon nullSpecEnv
--}
-\end{code}
+int16TyCon = pcNonRecDataTyCon int16TyConKey iNT SLIT("Int16") [] [int16DataCon]
+  where
+   int16DataCon = pcDataCon int16DataConKey iNT SLIT("I16#") [] [] [intPrimTy] int16TyCon
 
-\begin{code}
-stablePtrTyCon
-  = pcDataTyCon stablePtrTyConKey gLASGOW_MISC SLIT("_StablePtr")
-       [alpha_tv] [stablePtrDataCon]
+int32TyCon = pcNonRecDataTyCon int32TyConKey iNT SLIT("Int32") [] [int32DataCon]
   where
-    stablePtrDataCon
-      = pcDataCon stablePtrDataConKey gLASGOW_MISC SLIT("_StablePtr")
-           [alpha_tv] [] [applyTyCon stablePtrPrimTyCon [alpha]] stablePtrTyCon nullSpecEnv
+   int32DataCon = pcDataCon int32DataConKey iNT SLIT("I32#") [] [] [intPrimTy] int32TyCon
+
+int64Ty = mkTyConTy int64TyCon 
+
+int64TyCon = pcNonRecDataTyCon int64TyConKey pREL_ADDR SLIT("Int64") [] [int64DataCon]
+int64DataCon = pcDataCon int64DataConKey pREL_ADDR SLIT("I64#") [] [] [int64PrimTy] int64TyCon
 \end{code}
 
 \begin{code}
-mallocPtrTyCon
-  = pcDataTyCon mallocPtrTyConKey gLASGOW_MISC SLIT("_MallocPtr")
-       [] [mallocPtrDataCon]
+
+wordTy = mkTyConTy wordTyCon
+
+wordTyCon = pcNonRecDataTyCon wordTyConKey   pREL_ADDR SLIT("Word") [] [wordDataCon]
+wordDataCon = pcDataCon wordDataConKey pREL_ADDR SLIT("W#") [] [] [wordPrimTy] wordTyCon
+
+word8TyCon = pcNonRecDataTyCon word8TyConKey   wORD SLIT("Word8") [] [word8DataCon]
   where
-    mallocPtrDataCon
-      = pcDataCon mallocPtrDataConKey gLASGOW_MISC SLIT("_MallocPtr")
-           [] [] [applyTyCon mallocPtrPrimTyCon []] mallocPtrTyCon nullSpecEnv
-\end{code}
+   word8DataCon = pcDataCon word8DataConKey wORD SLIT("W8#") [] [] [wordPrimTy] word8TyCon
 
-%************************************************************************
-%*                                                                     *
-\subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
-%*                                                                     *
-%************************************************************************
+word16TyCon = pcNonRecDataTyCon word16TyConKey   wORD SLIT("Word16") [] [word16DataCon]
+  where
+   word16DataCon = pcDataCon word16DataConKey wORD SLIT("W16#") [] [] [wordPrimTy] word16TyCon
 
-@Integer@ and its pals are not really primitive.  @Integer@ itself, first:
-\begin{code}
-integerTy :: UniType
-integerTy    = UniData integerTyCon []
-
-integerTyCon = pcDataTyCon integerTyConKey pRELUDE_BUILTIN SLIT("Integer") [] [integerDataCon]
-
-#ifndef DPH
-integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#")
-               [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv
-#else
--- DPH: For the time being we implement Integers in the same way as Ints.
-integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#")
-               [] [] [intPrimTy] integerTyCon nullSpecEnv
-#endif {- Data Parallel Haskell -}
+word32TyCon = pcNonRecDataTyCon word32TyConKey   wORD SLIT("Word32") [] [word32DataCon]
+  where
+   word32DataCon = pcDataCon word32DataConKey wORD SLIT("W32#") [] [] [wordPrimTy] word32TyCon
+
+word64Ty = mkTyConTy word64TyCon
+
+word64TyCon = pcNonRecDataTyCon word64TyConKey   pREL_ADDR SLIT("Word64") [] [word64DataCon]
+word64DataCon = pcDataCon word64DataConKey pREL_ADDR SLIT("W64#") [] [] [word64PrimTy] word64TyCon
 \end{code}
 
-And the other pairing types:
 \begin{code}
-return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey
-       pRELUDE_BUILTIN SLIT("_Return2GMPs") [] [return2GMPsDataCon]
+addrTy = mkTyConTy addrTyCon
 
-return2GMPsDataCon
-  = pcDataCon return2GMPsDataConKey pRELUDE_BUILTIN SLIT("_Return2GMPs") [] []
-       [intPrimTy, intPrimTy, byteArrayPrimTy,
-        intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv
+addrTyCon = pcNonRecDataTyCon addrTyConKey   pREL_ADDR SLIT("Addr") [] [addrDataCon]
+addrDataCon = pcDataCon addrDataConKey pREL_ADDR SLIT("A#") [] [] [addrPrimTy] addrTyCon
 
-returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey
-       pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
+isAddrTy :: GenType flexi -> Bool
+isAddrTy ty
+  = case (splitAlgTyConApp_maybe ty) of
+       Just (tycon, [], _) -> getUnique tycon == addrTyConKey
+       _                   -> False
 
-returnIntAndGMPDataCon
-  = pcDataCon returnIntAndGMPDataConKey pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] []
-       [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv
 \end{code}
 
-%************************************************************************
-%*                                                                     *
-\subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
-%*                                                                     *
-%************************************************************************
+\begin{code}
+floatTy        = mkTyConTy floatTyCon
+
+floatTyCon = pcNonRecDataTyCon floatTyConKey pREL_BASE SLIT("Float") [] [floatDataCon]
+floatDataCon = pcDataCon floatDataConKey pREL_BASE SLIT("F#") [] [] [floatPrimTy] floatTyCon
 
-These boring types pair a \tr{State#} with another primitive type.
-They are not really primitive, so they are given here, not in
-\tr{TysPrim.lhs}.
+isFloatTy :: GenType flexi -> Bool
+isFloatTy ty
+  = case (splitAlgTyConApp_maybe ty) of
+       Just (tycon, [], _) -> getUnique tycon == floatTyConKey
+       _                   -> False
 
-We fish one of these \tr{StateAnd<blah>#} things with
-@getStatePairingConInfo@ (given a little way down).
+\end{code}
 
 \begin{code}
-stateAndPtrPrimTyCon
-  = pcDataTyCon stateAndPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
-               [alpha_tv, beta_tv] [stateAndPtrPrimDataCon]
-stateAndPtrPrimDataCon
-  = pcDataCon stateAndPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
-               [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, beta]
-               stateAndPtrPrimTyCon nullSpecEnv
-
-stateAndCharPrimTyCon
-  = pcDataTyCon stateAndCharPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
-               [alpha_tv] [stateAndCharPrimDataCon]
-stateAndCharPrimDataCon
-  = pcDataCon stateAndCharPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
-               [alpha_tv] [] [mkStatePrimTy alpha, charPrimTy]
-               stateAndCharPrimTyCon nullSpecEnv
-
-stateAndIntPrimTyCon
-  = pcDataTyCon stateAndIntPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
-               [alpha_tv] [stateAndIntPrimDataCon]
-stateAndIntPrimDataCon
-  = pcDataCon stateAndIntPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
-               [alpha_tv] [] [mkStatePrimTy alpha, intPrimTy]
-               stateAndIntPrimTyCon nullSpecEnv
-
-stateAndWordPrimTyCon
-  = pcDataTyCon stateAndWordPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
-               [alpha_tv] [stateAndWordPrimDataCon]
-stateAndWordPrimDataCon
-  = pcDataCon stateAndWordPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
-               [alpha_tv] [] [mkStatePrimTy alpha, wordPrimTy]
-               stateAndWordPrimTyCon nullSpecEnv
-
-stateAndAddrPrimTyCon
-  = pcDataTyCon stateAndAddrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
-               [alpha_tv] [stateAndAddrPrimDataCon]
-stateAndAddrPrimDataCon
-  = pcDataCon stateAndAddrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
-               [alpha_tv] [] [mkStatePrimTy alpha, addrPrimTy]
-               stateAndAddrPrimTyCon nullSpecEnv
-
-stateAndStablePtrPrimTyCon
-  = pcDataTyCon stateAndStablePtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
-               [alpha_tv, beta_tv] [stateAndStablePtrPrimDataCon]
-stateAndStablePtrPrimDataCon
-  = pcDataCon stateAndStablePtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
-               [alpha_tv, beta_tv] []
-               [mkStatePrimTy alpha, applyTyCon stablePtrPrimTyCon [beta]]
-               stateAndStablePtrPrimTyCon nullSpecEnv
-
-stateAndMallocPtrPrimTyCon
-  = pcDataTyCon stateAndMallocPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
-               [alpha_tv] [stateAndMallocPtrPrimDataCon]
-stateAndMallocPtrPrimDataCon
-  = pcDataCon stateAndMallocPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
-               [alpha_tv] []
-               [mkStatePrimTy alpha, applyTyCon mallocPtrPrimTyCon []]
-               stateAndMallocPtrPrimTyCon nullSpecEnv
-
-stateAndFloatPrimTyCon
-  = pcDataTyCon stateAndFloatPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
-               [alpha_tv] [stateAndFloatPrimDataCon]
-stateAndFloatPrimDataCon
-  = pcDataCon stateAndFloatPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
-               [alpha_tv] [] [mkStatePrimTy alpha, floatPrimTy]
-               stateAndFloatPrimTyCon nullSpecEnv
-
-stateAndDoublePrimTyCon
-  = pcDataTyCon stateAndDoublePrimTyConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
-               [alpha_tv] [stateAndDoublePrimDataCon]
-stateAndDoublePrimDataCon
-  = pcDataCon stateAndDoublePrimDataConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
-               [alpha_tv] [] [mkStatePrimTy alpha, doublePrimTy]
-               stateAndDoublePrimTyCon nullSpecEnv
+doubleTy = mkTyConTy doubleTyCon
+
+isDoubleTy :: GenType flexi -> Bool
+isDoubleTy ty
+  = case (splitAlgTyConApp_maybe ty) of
+       Just (tycon, [], _) -> getUnique tycon == doubleTyConKey
+       _                   -> False
+
+doubleTyCon = pcNonRecDataTyCon doubleTyConKey pREL_BASE SLIT("Double") [] [doubleDataCon]
+doubleDataCon = pcDataCon doubleDataConKey pREL_BASE SLIT("D#") [] [] [doublePrimTy] doubleTyCon
 \end{code}
 
 \begin{code}
-stateAndArrayPrimTyCon
-  = pcDataTyCon stateAndArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
-               [alpha_tv, beta_tv] [stateAndArrayPrimDataCon]
-stateAndArrayPrimDataCon
-  = pcDataCon stateAndArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
-               [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkArrayPrimTy beta]
-               stateAndArrayPrimTyCon nullSpecEnv
-
-stateAndMutableArrayPrimTyCon
-  = pcDataTyCon stateAndMutableArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
-               [alpha_tv, beta_tv] [stateAndMutableArrayPrimDataCon]
-stateAndMutableArrayPrimDataCon
-  = pcDataCon stateAndMutableArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
-               [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkMutableArrayPrimTy alpha beta]
-               stateAndMutableArrayPrimTyCon nullSpecEnv
-
-stateAndByteArrayPrimTyCon
-  = pcDataTyCon stateAndByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
-               [alpha_tv] [stateAndByteArrayPrimDataCon]
-stateAndByteArrayPrimDataCon
-  = pcDataCon stateAndByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
-               [alpha_tv] [] [mkStatePrimTy alpha, byteArrayPrimTy]
-               stateAndByteArrayPrimTyCon nullSpecEnv
-
-stateAndMutableByteArrayPrimTyCon
-  = pcDataTyCon stateAndMutableByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
-               [alpha_tv] [stateAndMutableByteArrayPrimDataCon]
-stateAndMutableByteArrayPrimDataCon
-  = pcDataCon stateAndMutableByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
-               [alpha_tv] [] [mkStatePrimTy alpha, applyTyCon mutableByteArrayPrimTyCon [alpha]]
-               stateAndMutableByteArrayPrimTyCon nullSpecEnv
-
-stateAndSynchVarPrimTyCon
-  = pcDataTyCon stateAndSynchVarPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
-               [alpha_tv, beta_tv] [stateAndSynchVarPrimDataCon]
-stateAndSynchVarPrimDataCon
-  = pcDataCon stateAndSynchVarPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
-               [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkSynchVarPrimTy alpha beta]
-               stateAndSynchVarPrimTyCon nullSpecEnv
+mkStateTy ty    = mkTyConApp stateTyCon [ty]
+realWorldStateTy = mkStateTy realWorldTy -- a common use
+
+stateTyCon = pcNonRecDataTyCon stateTyConKey pREL_ST SLIT("State") alpha_tyvar [stateDataCon]
+stateDataCon
+  = pcDataCon stateDataConKey pREL_ST SLIT("S#")
+       alpha_tyvar [] [mkStatePrimTy alphaTy] stateTyCon
 \end{code}
 
-The ccall-desugaring mechanism uses this function to figure out how to
-rebox the result.  It's really a HACK, especially the part about
-how many types to drop from \tr{tys_applied}.
+\begin{code}
+stablePtrTyCon
+  = pcNonRecDataTyCon stablePtrTyConKey pREL_FOREIGN SLIT("StablePtr")
+       alpha_tyvar [stablePtrDataCon]
+  where
+    stablePtrDataCon
+      = pcDataCon stablePtrDataConKey pREL_FOREIGN SLIT("StablePtr")
+           alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon
+\end{code}
 
 \begin{code}
-getStatePairingConInfo
-       :: UniType      -- primitive type
-       -> (Id,         -- state pair constructor for prim type
-           UniType)    -- type of state pair
-
-getStatePairingConInfo prim_ty
-  = case (getUniDataTyCon_maybe prim_ty) of
-      Nothing -> panic "getStatePairingConInfo:1"
-      Just (prim_tycon, tys_applied, _) ->
-       let
-           (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
-           pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied)
-       in
-       (pair_con, pair_ty)
+foreignObjTyCon
+  = pcNonRecDataTyCon foreignObjTyConKey pREL_IO_BASE SLIT("ForeignObj")
+       [] [foreignObjDataCon]
   where
-    tbl = [
-       (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
-       (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
-       (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
-       (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
-       (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
-       (mallocPtrPrimTyCon, (stateAndMallocPtrPrimDataCon, stateAndMallocPtrPrimTyCon, 0)),
-       (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
-       (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
-       (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
-       (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
-       (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
-       (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
-       (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
-       -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
-       ]
+    foreignObjDataCon
+      = pcDataCon foreignObjDataConKey pREL_IO_BASE SLIT("ForeignObj")
+           [] [] [foreignObjPrimTy] foreignObjTyCon
 \end{code}
 
 %************************************************************************
 %*                                                                     *
-\subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
+\subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
 %*                                                                     *
 %************************************************************************
 
-This is really just an ordinary synonym, except it is ABSTRACT.
-
+@Integer@ and its pals are not really primitive.  @Integer@ itself, first:
 \begin{code}
-mkStateTransformerTy s a = applyTyCon stTyCon [s, a]
-
-stTyCon
-  = mkSynonymTyCon
-     stTyConKey
-     (mkPreludeCoreName gLASGOW_ST SLIT("_ST"))
-     2
-     [alpha_tv, beta_tv]
-     (mkStateTy alpha `UniFun` mkTupleTy 2 [beta, mkStateTy alpha])
-     True -- ToDo: make... *** ABSTRACT ***
+integerTy :: GenType t
+integerTy    = mkTyConTy integerTyCon
+
+integerTyCon = pcNonRecDataTyCon integerTyConKey pREL_BASE SLIT("Integer") [] [integerDataCon]
+
+integerDataCon = pcDataCon integerDataConKey pREL_BASE SLIT("J#")
+               [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon
+
+isIntegerTy :: GenType flexi -> Bool
+isIntegerTy ty
+  = case (splitAlgTyConApp_maybe ty) of
+       Just (tycon, [], _) -> getUnique tycon == integerTyConKey
+       _                   -> False
 \end{code}
 
+
 %************************************************************************
 %*                                                                     *
-\subsection[TysWiredIn-IO]{The @PrimIO@ and @IO@ monadic-I/O types}
+\subsection[TysWiredIn-ext-type]{External types}
 %*                                                                     *
 %************************************************************************
 
-@PrimIO@ and @IO@ really are just a plain synonyms.
+The compiler's foreign function interface supports the passing of a
+restricted set of types as arguments and results (the restricting factor
+being the )
 
 \begin{code}
-mkPrimIoTy a = applyTyCon primIoTyCon [a]
-
-primIoTyCon
-  = mkSynonymTyCon
-     primIoTyConKey
-     (mkPreludeCoreName pRELUDE_PRIMIO SLIT("PrimIO"))
-     1
-     [alpha_tv]
-     (mkStateTransformerTy realWorldTy alpha)
-     True -- need not be abstract
+isFFIArgumentTy :: Type -> Bool
+isFFIArgumentTy ty =
+  (opt_GlasgowExts && isUnLiftedType ty) || --leave out for now: maybeToBool (maybeBoxedPrimType ty))) ||
+  case (splitAlgTyConApp_maybe ty) of
+    Just (tycon, _, _) -> (getUnique tycon) `elem` primArgTyConKeys
+    _                 -> False
+
+-- types that can be passed as arguments to "foreign" functions
+primArgTyConKeys 
+  = [ intTyConKey, int8TyConKey, int16TyConKey, int32TyConKey, int64TyConKey
+    , wordTyConKey, word8TyConKey, word16TyConKey, word32TyConKey, word64TyConKey
+    , floatTyConKey, doubleTyConKey
+    , addrTyConKey, charTyConKey, foreignObjTyConKey
+    , stablePtrTyConKey, byteArrayTyConKey, mutableByteArrayTyConKey
+    ]
+
+-- types that can be passed from the outside world into Haskell.
+-- excludes (mutable) byteArrays.
+isFFIExternalTy :: Type -> Bool
+isFFIExternalTy ty = 
+  (opt_GlasgowExts && isUnLiftedType ty) || --leave out for now: maybeToBool (maybeBoxedPrimType ty))) ||
+  case (splitAlgTyConApp_maybe ty) of
+    Just (tycon, _, _) -> 
+       let 
+        u_tycon = getUnique tycon
+       in  
+       (u_tycon `elem` primArgTyConKeys) &&
+       not (u_tycon `elem` notLegalExternalTyCons)
+    _                 -> False
+
+
+isFFIResultTy :: Type -> Bool
+isFFIResultTy ty =
+   not (isUnLiftedType ty) &&
+   case (splitAlgTyConApp_maybe ty) of
+    Just (tycon, _, _) -> 
+       let
+        u_tycon = getUnique tycon
+       in
+       (u_tycon == getUnique unitTyCon) ||
+        ((u_tycon `elem` primArgTyConKeys) && 
+        not (u_tycon `elem` notLegalExternalTyCons))
+    _                 -> False
+
+-- it's illegal to return foreign objects and (mutable)
+-- bytearrays from a _ccall_ / foreign declaration
+-- (or be passed them as arguments in foreign exported functions).
+notLegalExternalTyCons =
+  [ foreignObjTyConKey, byteArrayTyConKey, mutableByteArrayTyConKey ]
+    
 \end{code}
 
 %************************************************************************
@@ -522,33 +553,13 @@ primitive counterpart.
 {\em END IDLE SPECULATION BY SIMON}
 
 \begin{code}
-boolTy = UniData boolTyCon []
-
-boolTyCon = pcDataTyCon boolTyConKey pRELUDE_CORE SLIT("Bool") [] [falseDataCon, trueDataCon]
-
-falseDataCon = pcDataCon falseDataConKey pRELUDE_CORE SLIT("False") [] [] [] boolTyCon nullSpecEnv
-trueDataCon  = pcDataCon trueDataConKey         pRELUDE_CORE SLIT("True")  [] [] [] boolTyCon nullSpecEnv
-\end{code}
-
-%************************************************************************
-%*                                                                     *
-\subsection[TysWiredIn-CMP-TAG]{The @CMP_TAG#@ type (for fast `derived' comparisons)}
-%*                                                                     *
-%************************************************************************
-
-\begin{code}
----------------------------------------------
--- data _CMP_TAG = _LT | _EQ | _GT deriving ()
----------------------------------------------
-
-cmpTagTy = UniData cmpTagTyCon []
+boolTy = mkTyConTy boolTyCon
 
-cmpTagTyCon = pcDataTyCon cmpTagTyConKey pRELUDE_BUILTIN SLIT("_CMP_TAG") []
-               [ltPrimDataCon, eqPrimDataCon, gtPrimDataCon]
+boolTyCon = pcTyCon EnumType NonRecursive boolTyConKey 
+                   pREL_BASE SLIT("Bool") [] [falseDataCon, trueDataCon]
 
-ltPrimDataCon  = pcDataCon ltTagDataConKey pRELUDE_BUILTIN SLIT("_LT") [] [] [] cmpTagTyCon nullSpecEnv
-eqPrimDataCon  = pcDataCon eqTagDataConKey pRELUDE_BUILTIN SLIT("_EQ") [] [] [] cmpTagTyCon nullSpecEnv
-gtPrimDataCon  = pcDataCon gtTagDataConKey pRELUDE_BUILTIN SLIT("_GT") [] [] [] cmpTagTyCon nullSpecEnv
+falseDataCon = pcDataCon falseDataConKey pREL_BASE SLIT("False") [] [] [] boolTyCon
+trueDataCon  = pcDataCon trueDataConKey         pREL_BASE SLIT("True")  [] [] [] boolTyCon
 \end{code}
 
 %************************************************************************
@@ -558,38 +569,29 @@ gtPrimDataCon  = pcDataCon gtTagDataConKey pRELUDE_BUILTIN SLIT("_GT") [] [] []
 %************************************************************************
 
 Special syntax, deeply wired in, but otherwise an ordinary algebraic
-data type:
+data types:
 \begin{verbatim}
-data List a = Nil | a : (List a)
+data [] a = [] | a : (List a)
+data () = ()
+data (,) a b = (,,) a b
+...
 \end{verbatim}
 
 \begin{code}
-mkListTy :: UniType -> UniType
-mkListTy ty = UniData listTyCon [ty]
+mkListTy :: GenType t -> GenType t
+mkListTy ty = mkTyConApp listTyCon [ty]
 
-alphaListTy = mkSigmaTy [alpha_tv] [] (mkListTy alpha)
+alphaListTy = mkSigmaTy alpha_tyvar [] (mkTyConApp listTyCon alpha_ty)
 
-listTyCon = pcDataTyCon listTyConKey pRELUDE_BUILTIN SLIT("List") [alpha_tv] [nilDataCon, consDataCon]
+listTyCon = pcRecDataTyCon listTyConKey pREL_BASE SLIT("[]") 
+                       alpha_tyvar [nilDataCon, consDataCon]
 
-nilDataCon  = pcDataCon nilDataConKey  pRELUDE_BUILTIN SLIT("Nil") [alpha_tv] [] [] listTyCon
-               (pcGenerateDataSpecs alphaListTy)
-consDataCon = pcDataCon consDataConKey pRELUDE_BUILTIN SLIT(":")
-               [alpha_tv] [] [alpha, mkListTy alpha] listTyCon
-               (pcGenerateDataSpecs alphaListTy)
-\end{code}
-
-This is the @_Build@ data constructor, it does {\em not} appear inside
-listTyCon.  It has this type: \tr{((a -> b -> b) -> b -> b) -> [a]}.
-\begin{code}
-{- NOT USED:
-buildDataCon
-  = pcDataCon buildDataConKey  pRELUDE_BUILTIN "Build"
-       [alpha_tv] [] [
-               mkSigmaTy [beta_tv] []
-                       ((alpha `UniFun` (beta `UniFun` beta))
-                       `UniFun` (beta
-                       `UniFun` beta))] listTyCon nullSpecEnv
--}
+nilDataCon  = pcDataCon nilDataConKey  pREL_BASE SLIT("[]") alpha_tyvar [] [] listTyCon
+consDataCon = pcDataCon consDataConKey pREL_BASE SLIT(":")
+               alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
+-- Interesting: polymorphic recursion would help here.
+-- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
+-- gets the over-specific type (Type -> Type)
 \end{code}
 
 %************************************************************************
@@ -603,14 +605,12 @@ family.
 
 \begin{itemize}
 \item
-They have a special family of type constructors, of type
-@TyCon@\srcloc{uniType/TyCon.lhs}.
+They have a special family of type constructors, of type @TyCon@
 These contain the tycon arity, but don't require a Unique.
 
 \item
 They have a special family of constructors, of type
-@Id@\srcloc{basicTypes/Id.lhs}.         Again these contain their arity but
-don't need a Unique.
+@Id@. Again these contain their arity but don't need a Unique.
 
 \item
 There should be a magic way of generating the info tables and
@@ -641,117 +641,11 @@ done by enumeration\srcloc{lib/prelude/InTup?.hs}.
 \end{itemize}
 
 \begin{code}
-mkTupleTy :: Int -> [UniType] -> UniType
-
-mkTupleTy arity tys = applyTyCon (mkTupleTyCon arity) tys
-
-unitTy = mkTupleTy 0 []
-\end{code}
-
-%************************************************************************
-%*                                                                     *
-\subsection[TysWiredIn-Ratios]{@Ratio@ and @Rational@}
-%*                                                                     *
-%************************************************************************
-
-ToDo: make this (mostly) go away.
-
-\begin{code}
-rationalTy :: UniType
-
-mkRatioTy ty = UniData ratioTyCon [ty]
-rationalTy   = mkRatioTy integerTy
-
-ratioTyCon = pcDataTyCon ratioTyConKey pRELUDE_RATIO SLIT("Ratio") [alpha_tv] [ratioDataCon]
-
-ratioDataCon = pcDataCon ratioDataConKey pRELUDE_RATIO SLIT(":%")
-               [alpha_tv] [{-(integralClass,alpha)-}] [alpha, alpha] ratioTyCon nullSpecEnv
-       -- context omitted to match lib/prelude/ defn of "data Ratio ..."
-
-rationalTyCon
-  = mkSynonymTyCon
-      rationalTyConKey
-      (mkPreludeCoreName pRELUDE_RATIO SLIT("Rational"))
-      0         -- arity
-      [] -- tyvars
-      rationalTy -- == mkRatioTy integerTy
-      True -- unabstract
-\end{code}
-
-%************************************************************************
-%*                                                                     *
-\subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
-%*                                                                     *
-%************************************************************************
-
-Again, deeply turgid: \tr{data _Lift a = _Lift a}.
-
-\begin{code}
-mkLiftTy ty = applyTyCon liftTyCon [ty]
-
-{-
-mkLiftTy ty
-  = mkSigmaTy tvs theta (UniData liftTyCon [tau])
-  where
-    (tvs, theta, tau) = splitType ty
-
-isLiftTy ty
-  = case getUniDataTyCon_maybe tau of
-      Just (tycon, tys, _) -> tycon == liftTyCon
-      Nothing -> False
-  where
-    (tvs, theta, tau) = splitType ty
--}
-
-
-alphaLiftTy = mkSigmaTy [alpha_tv] [] (UniData liftTyCon [alpha])
-
-liftTyCon
-  = pcDataTyCon liftTyConKey pRELUDE_BUILTIN SLIT("_Lift") [alpha_tv] [liftDataCon]
-
-liftDataCon
-  = pcDataCon liftDataConKey pRELUDE_BUILTIN SLIT("_Lift")
-               [alpha_tv] [] [alpha] liftTyCon 
-               ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv`
-                (SpecInfo [Just realWorldStatePrimTy] 0 bottom))
-  where
-    bottom = panic "liftDataCon:State# _RealWorld"
-\end{code}
-
-
-%************************************************************************
-%*                                                                     *
-\subsection[TysWiredIn-for-convenience]{Types wired in for convenience (e.g., @String@)}
-%*                                                                     *
-%************************************************************************
-
-\begin{code}
-stringTy = mkListTy charTy
-
-stringTyCon
- = mkSynonymTyCon
-     stringTyConKey
-     (mkPreludeCoreName pRELUDE_CORE SLIT("String"))
-     0
-     []   -- type variables
-     stringTy
-     True -- unabstract
-\end{code}
-
-\begin{code}
-{- UNUSED:
-packedStringTy = applyTyCon packedStringTyCon []
-
-packedStringTyCon
-  = pcDataTyCon packedStringTyConKey pRELUDE_PS SLIT("_PackedString") []
-       [psDataCon, cpsDataCon]
+mkTupleTy :: Int -> [GenType t] -> GenType t
+mkTupleTy arity tys = mkTyConApp (tupleTyCon arity) tys
 
-psDataCon
-  = pcDataCon psDataConKey pRELUDE_PS SLIT("_PS")
-               [] [] [intPrimTy, byteArrayPrimTy] packedStringTyCon
+mkUnboxedTupleTy :: Int -> [GenType t] -> GenType t
+mkUnboxedTupleTy arity tys = mkTyConApp (unboxedTupleTyCon arity) tys
 
-cpsDataCon
-  = pcDataCon cpsDataConKey pRELUDE_PS SLIT("_CPS")
-               [] [] [addrPrimTy] packedStringTyCon
--}
+unitTy    = mkTupleTy 0 []
 \end{code}