TysWiredIn.lhs 20 KB
Newer Older
1
%
2
% (c) The GRASP Project, Glasgow University, 1994-1998
3 4 5 6 7 8 9 10 11 12 13
%
\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}
module TysWiredIn (
14 15
	wiredInTyCons, genericTyCons,

16 17 18
	addrDataCon,
	addrTy,
	addrTyCon,
19 20 21
	ptrDataCon,
	ptrTy,
	ptrTyCon,
22 23 24
	funPtrDataCon,
	funPtrTy,
	funPtrTyCon,
25 26 27 28 29 30 31 32 33
	boolTy,
	boolTyCon,
	charDataCon,
	charTy,
	charTyCon,
	consDataCon,
	doubleDataCon,
	doubleTy,
	doubleTyCon,
34
	falseDataCon, falseDataConId,
35 36 37
	floatDataCon,
	floatTy,
	floatTyCon,
38

39 40 41
	intDataCon,
	intTy,
	intTyCon,
sof's avatar
sof committed
42

43 44
	integerTy,
	integerTyCon,
45 46
	smallIntegerDataCon,
	largeIntegerDataCon,
sof's avatar
sof committed
47

48
	listTyCon,
49

50
	mkListTy,
51 52 53
	nilDataCon,

	-- tuples
54
	mkTupleTy,
55
	tupleTyCon, tupleCon, 
56
	unitTyCon, unitDataCon, unitDataConId, pairTyCon, 
57
	unboxedSingletonTyCon, unboxedSingletonDataCon,
58 59
	unboxedPairTyCon, unboxedPairDataCon,

60 61 62 63 64
	-- Generics
        genUnitTyCon, genUnitDataCon, 
	plusTyCon, inrDataCon, inlDataCon,
	crossTyCon, crossDataCon,

65
	stablePtrTyCon,
66
	stringTy,
67
	trueDataCon, trueDataConId,
68
	unitTy,
sof's avatar
sof committed
69
	voidTy,
70 71
	wordDataCon,
	wordTy,
chak's avatar
chak committed
72 73 74 75 76
	wordTyCon,

        -- parallel arrays
	mkPArrTy,
	parrTyCon, parrFakeCon, isPArrTyCon, isPArrFakeCon
77 78
    ) where

79 80
#include "HsVersions.h"

81
import {-# SOURCE #-} MkId( mkDataConWorkId )
82
import {-# SOURCE #-} Generics( mkTyConGenInfo )
83

84
-- friends:
85
import PrelNames
86 87
import TysPrim

88
-- others:
89
import Constants	( mAX_TUPLE_SIZE )
90
import Module		( mkBasePkgModule )
91
import Name		( Name, nameUnique, nameOccName, 
92
			  nameModule, mkWiredInName )
93
import OccName		( mkOccFS, tcName, dataName, mkDataConWorkerOcc, mkGenOcc1, mkGenOcc2 )
94
import DataCon		( DataCon, mkDataCon, dataConWorkId, dataConSourceArity )
95
import Var		( TyVar, tyVarKind )
96
import TyCon		( TyCon, AlgTyConFlavour(..), DataConDetails(..), tyConDataCons,
chak's avatar
chak committed
97
			  mkTupleTyCon, mkAlgTyCon, tyConName
98
			)
99

100
import BasicTypes	( Arity, RecFlag(..), Boxity(..), isBoxed )
101

chak's avatar
chak committed
102
import Type		( Type, mkTyConTy, mkTyConApp, mkTyVarTy, mkTyVarTys, 
103
			  mkArrowKinds, liftedTypeKind, unliftedTypeKind,
104
			  ThetaType )
chak's avatar
chak committed
105 106
import Unique		( incrUnique, mkTupleTyConUnique,
			  mkTupleDataConUnique, mkPArrDataConUnique )
107
import PrelNames
108
import Array
109
import FastString
sof's avatar
sof committed
110

111 112 113
alpha_tyvar	  = [alphaTyVar]
alpha_ty	  = [alphaTy]
alpha_beta_tyvars = [alphaTyVar, betaTyVar]
114
\end{code}
115 116


117 118 119 120 121
%************************************************************************
%*									*
\subsection{Wired in type constructors}
%*									*
%************************************************************************
122

123 124 125
If you change which things are wired in, make sure you change their
names in PrelNames, so they use wTcQual, wDataQual, etc

126 127 128 129 130 131
\begin{code}
wiredInTyCons :: [TyCon]
wiredInTyCons = data_tycons ++ tuple_tycons ++ unboxed_tuple_tycons

data_tycons = genericTyCons ++
	      [ addrTyCon
132
	      , ptrTyCon
133
	      , funPtrTyCon
134 135 136 137 138 139 140
    	      , boolTyCon
    	      , charTyCon
    	      , doubleTyCon
    	      , floatTyCon
    	      , intTyCon
    	      , integerTyCon
    	      , listTyCon
chak's avatar
chak committed
141
	      , parrTyCon
142 143 144 145 146 147
    	      , wordTyCon
    	      ]

genericTyCons :: [TyCon]
genericTyCons = [ plusTyCon, crossTyCon, genUnitTyCon ]

148 149
tuple_tycons = unitTyCon : [tupleTyCon Boxed   i | i <- [2..mAX_TUPLE_SIZE] ]
unboxed_tuple_tycons     = [tupleTyCon Unboxed i | i <- [1..mAX_TUPLE_SIZE] ]
150
\end{code}
151

152

153 154 155 156 157 158 159 160 161 162
%************************************************************************
%*                                                                      *
\subsection{mkWiredInTyCon}
%*                                                                      *
%************************************************************************

\begin{code}
pcNonRecDataTyCon = pcTyCon DataTyCon NonRecursive
pcRecDataTyCon = pcTyCon DataTyCon Recursive

163
pcTyCon new_or_data is_rec name tyvars argvrcs cons
164 165
  = tycon
  where
166
    tycon = mkAlgTyCon name kind
167 168 169
                tyvars
                []              -- No context
                argvrcs
170
                (DataCons cons)
171
		[]		-- No record selectors
172 173 174 175
                new_or_data
                is_rec
		gen_info

176
    mod      = nameModule name
177
    kind     = mkArrowKinds (map tyVarKind tyvars) liftedTypeKind
178
    gen_info = mk_tc_gen_info mod (nameUnique name) name tycon
179

180 181 182 183
-- We generate names for the generic to/from Ids by incrementing
-- the TyCon unique.  So each Prelude tycon needs 3 slots, one
-- for itself and two more for the generic Ids.
mk_tc_gen_info mod tc_uniq tc_name tycon
184
  = mkTyConGenInfo tycon [name1, name2]
185 186 187 188 189 190 191 192 193
  where
	tc_occ_name = nameOccName tc_name
	occ_name1   = mkGenOcc1 tc_occ_name
	occ_name2   = mkGenOcc2 tc_occ_name
	fn1_key     = incrUnique tc_uniq
	fn2_key     = incrUnique fn1_key
	name1	    = mkWiredInName  mod occ_name1 fn1_key
	name2	    = mkWiredInName  mod occ_name2 fn2_key

194
pcDataCon :: Name -> [TyVar] -> ThetaType -> [Type] -> TyCon -> DataCon
195 196 197
-- The Name should be in the DataName name space; it's the name
-- of the DataCon itself.
--
198
-- The unique is the first of two free uniques;
199 200
-- the first is used for the datacon itself,
-- the second is used for the "worker name"
201

202
pcDataCon dc_name tyvars context arg_tys tycon
203 204
  = data_con
  where
205 206 207 208 209 210 211 212 213 214 215 216
    data_con = mkDataCon dc_name	
                [{- No strictness -}]
                [{- No labelled fields -}]
                tyvars context [] [] arg_tys tycon work_id 
		Nothing {- No wrapper for wired-in things
			   (they are too simple to need one) -}

    mod      = nameModule dc_name
    wrk_occ  = mkDataConWorkerOcc (nameOccName dc_name)
    wrk_key  = incrUnique (nameUnique dc_name)
    wrk_name = mkWiredInName mod wrk_occ wrk_key
    work_id  = mkDataConWorkId wrk_name data_con
217 218
\end{code}

219

220 221 222 223 224 225 226
%************************************************************************
%*									*
\subsection[TysWiredIn-tuples]{The tuple types}
%*									*
%************************************************************************

\begin{code}
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
tupleTyCon :: Boxity -> Arity -> TyCon
tupleTyCon boxity i | i > mAX_TUPLE_SIZE = fst (mk_tuple boxity i)	-- Build one specially
tupleTyCon Boxed   i = fst (boxedTupleArr   ! i)
tupleTyCon Unboxed i = fst (unboxedTupleArr ! i)

tupleCon :: Boxity -> Arity -> DataCon
tupleCon boxity i | i > mAX_TUPLE_SIZE = snd (mk_tuple boxity i)	-- Build one specially
tupleCon Boxed   i = snd (boxedTupleArr   ! i)
tupleCon Unboxed i = snd (unboxedTupleArr ! i)

boxedTupleArr, unboxedTupleArr :: Array Int (TyCon,DataCon)
boxedTupleArr   = array (0,mAX_TUPLE_SIZE) [(i,mk_tuple Boxed i)   | i <- [0..mAX_TUPLE_SIZE]]
unboxedTupleArr = array (0,mAX_TUPLE_SIZE) [(i,mk_tuple Unboxed i) | i <- [0..mAX_TUPLE_SIZE]]

mk_tuple :: Boxity -> Int -> (TyCon,DataCon)
mk_tuple boxity arity = (tycon, tuple_con)
243
  where
244
	tycon   = mkTupleTyCon tc_name tc_kind arity tyvars tuple_con boxity gen_info 
245
	tc_name = mkWiredInName mod (mkOccFS tcName name_str) tc_uniq
246
    	tc_kind = mkArrowKinds (map tyVarKind tyvars) res_kind
247 248
	res_kind | isBoxed boxity = liftedTypeKind
		 | otherwise	  = unliftedTypeKind
249 250 251

	tyvars   | isBoxed boxity = take arity alphaTyVars
		 | otherwise	  = take arity openAlphaTyVars
252

253
	tuple_con = pcDataCon name tyvars [] tyvar_tys tycon
254
	tyvar_tys = mkTyVarTys tyvars
255
	(mod_name, name_str) = mkTupNameStr boxity arity
256
	name      = mkWiredInName mod (mkOccFS dataName name_str) dc_uniq
257 258
 	tc_uniq   = mkTupleTyConUnique   boxity arity
	dc_uniq   = mkTupleDataConUnique boxity arity
259
	mod	  = mkBasePkgModule mod_name
260 261
	gen_info  = mk_tc_gen_info mod tc_uniq tc_name tycon

262
unitTyCon     = tupleTyCon Boxed 0
263 264
unitDataCon   = head (tyConDataCons unitTyCon)
unitDataConId = dataConWorkId unitDataCon
265

266
pairTyCon = tupleTyCon Boxed 2
267

268 269
unboxedSingletonTyCon   = tupleTyCon Unboxed 1
unboxedSingletonDataCon = tupleCon   Unboxed 1
270

271 272
unboxedPairTyCon   = tupleTyCon Unboxed 2
unboxedPairDataCon = tupleCon   Unboxed 2
273
\end{code}
274

275 276 277 278 279 280
%************************************************************************
%*									*
\subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
%*									*
%************************************************************************

281 282 283 284 285 286 287
\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!
--
288
-- ) It's lifted; there is only one value of this
289
-- type, namely "void", whose semantics is just bottom.
sof's avatar
sof committed
290 291 292 293
--
-- Haskell 98 drops the definition of a Void type, so we just 'simulate'
-- voidTy using ().
voidTy = unitTy
294 295
\end{code}

sof's avatar
sof committed
296

297
\begin{code}
298
charTy = mkTyConTy charTyCon
299

300 301
charTyCon   = pcNonRecDataTyCon charTyConName [] [] [charDataCon]
charDataCon = pcDataCon charDataConName [] [] [charPrimTy] charTyCon
302 303

stringTy = mkListTy charTy -- convenience only
304 305 306
\end{code}

\begin{code}
307
intTy = mkTyConTy intTyCon 
308

309 310
intTyCon = pcNonRecDataTyCon intTyConName [] [] [intDataCon]
intDataCon = pcDataCon intDataConName [] [] [intPrimTy] intTyCon
311 312 313
\end{code}

\begin{code}
314
wordTy = mkTyConTy wordTyCon
315

316 317
wordTyCon = pcNonRecDataTyCon wordTyConName [] [] [wordDataCon]
wordDataCon = pcDataCon wordDataConName [] [] [wordPrimTy] wordTyCon
318 319 320
\end{code}

\begin{code}
321
addrTy = mkTyConTy addrTyCon
322

323 324
addrTyCon = pcNonRecDataTyCon addrTyConName [] [] [addrDataCon]
addrDataCon = pcDataCon addrDataConName [] [] [addrPrimTy] addrTyCon
325 326
\end{code}

327 328 329 330 331 332 333
\begin{code}
ptrTy = mkTyConTy ptrTyCon

ptrTyCon = pcNonRecDataTyCon ptrTyConName alpha_tyvar [(True,False)] [ptrDataCon]
ptrDataCon = pcDataCon ptrDataConName alpha_tyvar [] [addrPrimTy] ptrTyCon
\end{code}

334 335 336 337 338 339 340
\begin{code}
funPtrTy = mkTyConTy funPtrTyCon

funPtrTyCon = pcNonRecDataTyCon funPtrTyConName alpha_tyvar [(True,False)] [funPtrDataCon]
funPtrDataCon = pcDataCon funPtrDataConName alpha_tyvar [] [addrPrimTy] funPtrTyCon
\end{code}

341
\begin{code}
342
floatTy	= mkTyConTy floatTyCon
343

344 345
floatTyCon   = pcNonRecDataTyCon floatTyConName   [] [] [floatDataCon]
floatDataCon = pcDataCon         floatDataConName [] [] [floatPrimTy] floatTyCon
346 347 348
\end{code}

\begin{code}
349
doubleTy = mkTyConTy doubleTyCon
350

351 352
doubleTyCon   = pcNonRecDataTyCon doubleTyConName     [] [] [doubleDataCon]
doubleDataCon = pcDataCon	  doubleDataConName [] [] [doublePrimTy] doubleTyCon
353 354 355 356
\end{code}

\begin{code}
stablePtrTyCon
357
  = pcNonRecDataTyCon stablePtrTyConName
358
	alpha_tyvar [(True,False)] [stablePtrDataCon]
359 360
  where
    stablePtrDataCon
361
      = pcDataCon stablePtrDataConName
362
	    alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon
363 364 365 366 367 368 369 370 371 372
\end{code}

%************************************************************************
%*									*
\subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
%*									*
%************************************************************************

@Integer@ and its pals are not really primitive.  @Integer@ itself, first:
\begin{code}
373 374
integerTy :: Type
integerTy = mkTyConTy integerTyCon
375

376
integerTyCon = pcNonRecDataTyCon integerTyConName
377
                   [] [] [smallIntegerDataCon, largeIntegerDataCon]
378

379
smallIntegerDataCon = pcDataCon smallIntegerDataConName
380
		[] [] [intPrimTy] integerTyCon
381
largeIntegerDataCon = pcDataCon largeIntegerDataConName
382
		[] [] [intPrimTy, byteArrayPrimTy] integerTyCon
383 384
\end{code}

sof's avatar
sof committed
385

386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
%************************************************************************
%*									*
\subsection[TysWiredIn-Bool]{The @Bool@ type}
%*									*
%************************************************************************

An ordinary enumeration type, but deeply wired in.  There are no
magical operations on @Bool@ (just the regular Prelude code).

{\em BEGIN IDLE SPECULATION BY SIMON}

This is not the only way to encode @Bool@.  A more obvious coding makes
@Bool@ just a boxed up version of @Bool#@, like this:
\begin{verbatim}
type Bool# = Int#
data Bool = MkBool Bool#
\end{verbatim}

Unfortunately, this doesn't correspond to what the Report says @Bool@
looks like!  Furthermore, we get slightly less efficient code (I
think) with this coding. @gtInt@ would look like this:

\begin{verbatim}
gtInt :: Int -> Int -> Bool
gtInt x y = case x of I# x# ->
	    case y of I# y# ->
	    case (gtIntPrim x# y#) of
		b# -> MkBool b#
\end{verbatim}

Notice that the result of the @gtIntPrim@ comparison has to be turned
into an integer (here called @b#@), and returned in a @MkBool@ box.

The @if@ expression would compile to this:
\begin{verbatim}
case (gtInt x y) of
  MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
\end{verbatim}

I think this code is a little less efficient than the previous code,
but I'm not certain.  At all events, corresponding with the Report is
important.  The interesting thing is that the language is expressive
enough to describe more than one alternative; and that a type doesn't
necessarily need to be a straightforwardly boxed version of its
primitive counterpart.

{\em END IDLE SPECULATION BY SIMON}

\begin{code}
435
boolTy = mkTyConTy boolTyCon
436

437 438
boolTyCon = pcTyCon EnumTyCon NonRecursive boolTyConName
		    [] [] [falseDataCon, trueDataCon]
439

440 441
falseDataCon = pcDataCon falseDataConName [] [] [] boolTyCon
trueDataCon  = pcDataCon trueDataConName  [] [] [] boolTyCon
442

443 444
falseDataConId = dataConWorkId falseDataCon
trueDataConId  = dataConWorkId trueDataCon
445 446 447 448 449 450 451 452 453
\end{code}

%************************************************************************
%*									*
\subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
%*									*
%************************************************************************

Special syntax, deeply wired in, but otherwise an ordinary algebraic
454
data types:
455
\begin{verbatim}
456 457 458 459
data [] a = [] | a : (List a)
data () = ()
data (,) a b = (,,) a b
...
460 461 462
\end{verbatim}

\begin{code}
463
mkListTy :: Type -> Type
464
mkListTy ty = mkTyConApp listTyCon [ty]
465

466
listTyCon = pcRecDataTyCon listTyConName
467
			alpha_tyvar [(True,False)] [nilDataCon, consDataCon]
468

469 470 471
nilDataCon  = pcDataCon nilDataConName alpha_tyvar [] [] listTyCon
consDataCon = pcDataCon consDataConName
 	       alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
472 473 474
-- 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)
475 476 477 478 479 480 481 482 483 484 485 486 487
\end{code}

%************************************************************************
%*									*
\subsection[TysWiredIn-Tuples]{The @Tuple@ types}
%*									*
%************************************************************************

The tuple types are definitely magic, because they form an infinite
family.

\begin{itemize}
\item
488
They have a special family of type constructors, of type @TyCon@
489 490 491 492
These contain the tycon arity, but don't require a Unique.

\item
They have a special family of constructors, of type
493
@Id@. Again these contain their arity but don't need a Unique.
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523

\item
There should be a magic way of generating the info tables and
entry code for all tuples.

But at the moment we just compile a Haskell source
file\srcloc{lib/prelude/...} containing declarations like:
\begin{verbatim}
data Tuple0		= Tup0
data Tuple2  a b	= Tup2	a b
data Tuple3  a b c	= Tup3	a b c
data Tuple4  a b c d	= Tup4	a b c d
...
\end{verbatim}
The print-names associated with the magic @Id@s for tuple constructors
``just happen'' to be the same as those generated by these
declarations.

\item
The instance environment should have a magic way to know
that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
so on. \ToDo{Not implemented yet.}

\item
There should also be a way to generate the appropriate code for each
of these instances, but (like the info tables and entry code) it is
done by enumeration\srcloc{lib/prelude/InTup?.hs}.
\end{itemize}

\begin{code}
524 525
mkTupleTy :: Boxity -> Int -> [Type] -> Type
mkTupleTy boxity arity tys = mkTyConApp (tupleTyCon boxity arity) tys
526

527
unitTy    = mkTupleTy Boxed 0 []
528
\end{code}
529

chak's avatar
chak committed
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
%************************************************************************
%*									*
\subsection[TysWiredIn-PArr]{The @[::]@ type}
%*									*
%************************************************************************

Special syntax for parallel arrays needs some wired in definitions.

\begin{code}
-- 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
--
-- * 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'.
--
parrTyCon :: TyCon
parrTyCon  = tycon
  where
    tycon   = mkAlgTyCon 
		parrTyConName 
		kind
		tyvars
560
		[]              	 -- No context
chak's avatar
chak committed
561
		[(True, False)]
562 563
		(DataCons [parrDataCon]) -- The constructor defined in `PrelPArr'
		[]			 -- No record selectors
chak's avatar
chak committed
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
		DataTyCon
		NonRecursive
		genInfo
    tyvars  = alpha_tyvar
    mod     = nameModule parrTyConName
    kind    = mkArrowKinds (map tyVarKind tyvars) liftedTypeKind
    genInfo = mk_tc_gen_info mod (nameUnique parrTyConName) parrTyConName tycon

parrDataCon :: DataCon
parrDataCon  = pcDataCon 
	         parrDataConName 
		 alpha_tyvar		-- forall'ed type variables
		 []			-- context
		 [intPrimTy,		-- 1st argument: Int#
		  mkTyConApp		-- 2nd argument: Array# a
		    arrayPrimTyCon 
		    alpha_ty] 
		 parrTyCon

-- check whether a type constructor is the constructor for parallel arrays
--
isPArrTyCon    :: TyCon -> Bool
isPArrTyCon tc  = tyConName tc == parrTyConName

-- fake array constructors
--
-- * 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
--
parrFakeCon                        :: Arity -> DataCon
parrFakeCon i | i > mAX_TUPLE_SIZE  = mkPArrFakeCon  i	-- build one specially
parrFakeCon i                       = parrFakeConArr!i

-- pre-defined set of constructors
--
parrFakeConArr :: Array Int DataCon
parrFakeConArr  = array (0, mAX_TUPLE_SIZE) [(i, mkPArrFakeCon i)   
					    | i <- [0..mAX_TUPLE_SIZE]]

-- build a fake parallel array constructor for the given arity
--
mkPArrFakeCon       :: Int -> DataCon
mkPArrFakeCon arity  = pcDataCon name [tyvar] [] tyvarTys parrTyCon
  where
	tyvar     = head alphaTyVars
	tyvarTys  = replicate arity $ mkTyVarTy tyvar
612
        nameStr   = mkFastString ("MkPArr" ++ show arity)
chak's avatar
chak committed
613 614
	name      = mkWiredInName mod (mkOccFS dataName nameStr) uniq
	uniq      = mkPArrDataConUnique arity
615
	mod	  = mkBasePkgModule pREL_PARR_Name
chak's avatar
chak committed
616 617 618 619 620 621 622

-- checks whether a data constructor is a fake constructor for parallel arrays
--
isPArrFakeCon      :: DataCon -> Bool
isPArrFakeCon dcon  = dcon == parrFakeCon (dataConSourceArity dcon)
\end{code}

623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
%************************************************************************
%*                                                                      *
\subsection{Wired In Type Constructors for Representation Types}
%*                                                                      *
%************************************************************************

The following code defines the wired in datatypes cross, plus, unit
and c_of needed for the generic methods.

Ok, so the basic story is that for each type constructor I need to
create 2 things - a TyCon and a DataCon and then we are basically
ok. There are going to be no arguments passed to these functions
because -well- there is nothing to pass to these functions.

\begin{code}
crossTyCon :: TyCon
639
crossTyCon = pcNonRecDataTyCon crossTyConName alpha_beta_tyvars [] [crossDataCon]
640 641

crossDataCon :: DataCon
642
crossDataCon = pcDataCon crossDataConName alpha_beta_tyvars [] [alphaTy, betaTy] crossTyCon
643 644

plusTyCon :: TyCon
645
plusTyCon = pcNonRecDataTyCon plusTyConName alpha_beta_tyvars [] [inlDataCon, inrDataCon]
646 647

inlDataCon, inrDataCon :: DataCon
648 649
inlDataCon = pcDataCon inlDataConName alpha_beta_tyvars [] [alphaTy] plusTyCon
inrDataCon = pcDataCon inrDataConName alpha_beta_tyvars [] [betaTy]  plusTyCon
650 651

genUnitTyCon :: TyCon 	-- The "1" type constructor for generics
652
genUnitTyCon = pcNonRecDataTyCon genUnitTyConName [] [] [genUnitDataCon]
653 654

genUnitDataCon :: DataCon
655
genUnitDataCon = pcDataCon genUnitDataConName [] [] [] genUnitTyCon
656
\end{code}