[project @ 2002-04-01 08:23:30 by simonpj]
[ghc-hetmet.git] / ghc / compiler / prelude / TysWiredIn.lhs
1 %
2 % (c) The GRASP Project, Glasgow University, 1994-1998
3 %
4 \section[TysWiredIn]{Wired-in knowledge about {\em non-primitive} types}
5
6 This module is about types that can be defined in Haskell, but which
7 must be wired into the compiler nonetheless.
8
9 This module tracks the ``state interface'' document, ``GHC prelude:
10 types and operations.''
11
12 \begin{code}
13 module TysWiredIn (
14         wiredInTyCons, genericTyCons,
15
16         addrDataCon,
17         addrTy,
18         addrTyCon,
19         ptrDataCon,
20         ptrTy,
21         ptrTyCon,
22         funPtrDataCon,
23         funPtrTy,
24         funPtrTyCon,
25         boolTy,
26         boolTyCon,
27         charDataCon,
28         charTy,
29         charTyCon,
30         consDataCon,
31         doubleDataCon,
32         doubleTy,
33         doubleTyCon,
34         falseDataCon, falseDataConId,
35         floatDataCon,
36         floatTy,
37         floatTyCon,
38
39         intDataCon,
40         intTy,
41         intTyCon,
42
43         integerTy,
44         integerTyCon,
45         smallIntegerDataCon,
46         largeIntegerDataCon,
47
48         listTyCon,
49
50         mkListTy,
51         nilDataCon,
52
53         -- tuples
54         mkTupleTy,
55         tupleTyCon, tupleCon, 
56         unitTyCon, unitDataConId, pairTyCon, 
57         unboxedSingletonTyCon, unboxedSingletonDataCon,
58         unboxedPairTyCon, unboxedPairDataCon,
59
60         -- Generics
61         genUnitTyCon, genUnitDataCon, 
62         plusTyCon, inrDataCon, inlDataCon,
63         crossTyCon, crossDataCon,
64
65         stablePtrTyCon,
66         stringTy,
67         trueDataCon, trueDataConId,
68         unitTy,
69         voidTy,
70         wordDataCon,
71         wordTy,
72         wordTyCon,
73
74         -- parallel arrays
75         mkPArrTy,
76         parrTyCon, parrFakeCon, isPArrTyCon, isPArrFakeCon
77     ) where
78
79 #include "HsVersions.h"
80
81 import {-# SOURCE #-} MkId( mkDataConId, mkDataConWrapId )
82 import {-# SOURCE #-} Generics( mkTyConGenInfo )
83
84 -- friends:
85 import PrelNames
86 import TysPrim
87
88 -- others:
89 import Constants        ( mAX_TUPLE_SIZE )
90 import Module           ( mkPrelModule )
91 import Name             ( Name, nameRdrName, nameUnique, nameOccName, 
92                           nameModule, mkWiredInName )
93 import OccName          ( mkOccFS, tcName, dataName, mkWorkerOcc, mkGenOcc1, mkGenOcc2 )
94 import RdrName          ( rdrNameOcc )
95 import DataCon          ( DataCon, mkDataCon, dataConWorkId, dataConSourceArity )
96 import Var              ( TyVar, tyVarKind )
97 import TyCon            ( TyCon, AlgTyConFlavour(..), DataConDetails(..), tyConDataCons,
98                           mkTupleTyCon, mkAlgTyCon, tyConName
99                         )
100
101 import BasicTypes       ( Arity, RecFlag(..), Boxity(..), isBoxed, StrictnessMark(..) )
102
103 import Type             ( Type, mkTyConTy, mkTyConApp, mkTyVarTy, mkTyVarTys, 
104                           mkArrowKinds, liftedTypeKind, unliftedTypeKind,
105                           ThetaType )
106 import Unique           ( incrUnique, mkTupleTyConUnique,
107                           mkTupleDataConUnique, mkPArrDataConUnique )
108 import PrelNames
109 import Array
110
111 alpha_tyvar       = [alphaTyVar]
112 alpha_ty          = [alphaTy]
113 alpha_beta_tyvars = [alphaTyVar, betaTyVar]
114 \end{code}
115
116
117 %************************************************************************
118 %*                                                                      *
119 \subsection{Wired in type constructors}
120 %*                                                                      *
121 %************************************************************************
122
123 \begin{code}
124 wiredInTyCons :: [TyCon]
125 wiredInTyCons = data_tycons ++ tuple_tycons ++ unboxed_tuple_tycons
126
127 data_tycons = genericTyCons ++
128               [ addrTyCon
129               , ptrTyCon
130               , funPtrTyCon
131               , boolTyCon
132               , charTyCon
133               , doubleTyCon
134               , floatTyCon
135               , intTyCon
136               , integerTyCon
137               , listTyCon
138               , parrTyCon
139               , wordTyCon
140               ]
141
142 genericTyCons :: [TyCon]
143 genericTyCons = [ plusTyCon, crossTyCon, genUnitTyCon ]
144
145
146 tuple_tycons = unitTyCon : [tupleTyCon Boxed   i | i <- [2..mAX_TUPLE_SIZE] ]
147 unboxed_tuple_tycons     = [tupleTyCon Unboxed i | i <- [1..mAX_TUPLE_SIZE] ]
148 \end{code}
149
150
151 %************************************************************************
152 %*                                                                      *
153 \subsection{mkWiredInTyCon}
154 %*                                                                      *
155 %************************************************************************
156
157 \begin{code}
158 pcNonRecDataTyCon = pcTyCon DataTyCon NonRecursive
159 pcRecDataTyCon = pcTyCon DataTyCon Recursive
160
161 pcTyCon new_or_data is_rec name tyvars argvrcs cons
162   = tycon
163   where
164     tycon = mkAlgTyCon name kind
165                 tyvars
166                 []              -- No context
167                 argvrcs
168                 (DataCons cons)
169                 []              -- No record selectors
170                 new_or_data
171                 is_rec
172                 gen_info
173
174     mod      = nameModule name
175     kind     = mkArrowKinds (map tyVarKind tyvars) liftedTypeKind
176     gen_info = mk_tc_gen_info mod (nameUnique name) name tycon
177
178 -- We generate names for the generic to/from Ids by incrementing
179 -- the TyCon unique.  So each Prelude tycon needs 3 slots, one
180 -- for itself and two more for the generic Ids.
181 mk_tc_gen_info mod tc_uniq tc_name tycon
182   = mkTyConGenInfo tycon [name1, name2]
183   where
184         tc_occ_name = nameOccName tc_name
185         occ_name1   = mkGenOcc1 tc_occ_name
186         occ_name2   = mkGenOcc2 tc_occ_name
187         fn1_key     = incrUnique tc_uniq
188         fn2_key     = incrUnique fn1_key
189         name1       = mkWiredInName  mod occ_name1 fn1_key
190         name2       = mkWiredInName  mod occ_name2 fn2_key
191
192 pcDataCon :: Name -> [TyVar] -> ThetaType -> [Type] -> TyCon -> DataCon
193 -- The unique is the first of two free uniques;
194 -- the first is used for the datacon itself and the worker;
195 -- the second is used for the wrapper.
196
197 pcDataCon name tyvars context arg_tys tycon
198   = data_con
199   where
200     data_con = mkDataCon name
201                 [ NotMarkedStrict | a <- arg_tys ]
202                 [ {- no labelled fields -} ]
203                 tyvars context [] [] arg_tys tycon work_id wrap_id
204
205     wrap_rdr  = nameRdrName name
206     wrap_occ  = rdrNameOcc wrap_rdr
207
208     mod       = nameModule name
209     wrap_id   = mkDataConWrapId data_con
210
211     work_occ  = mkWorkerOcc wrap_occ
212     work_key  = incrUnique (nameUnique name)
213     work_name = mkWiredInName mod work_occ work_key
214     work_id   = mkDataConId work_name data_con
215 \end{code}
216
217
218 %************************************************************************
219 %*                                                                      *
220 \subsection[TysWiredIn-tuples]{The tuple types}
221 %*                                                                      *
222 %************************************************************************
223
224 \begin{code}
225 tupleTyCon :: Boxity -> Arity -> TyCon
226 tupleTyCon boxity i | i > mAX_TUPLE_SIZE = fst (mk_tuple boxity i)      -- Build one specially
227 tupleTyCon Boxed   i = fst (boxedTupleArr   ! i)
228 tupleTyCon Unboxed i = fst (unboxedTupleArr ! i)
229
230 tupleCon :: Boxity -> Arity -> DataCon
231 tupleCon boxity i | i > mAX_TUPLE_SIZE = snd (mk_tuple boxity i)        -- Build one specially
232 tupleCon Boxed   i = snd (boxedTupleArr   ! i)
233 tupleCon Unboxed i = snd (unboxedTupleArr ! i)
234
235 boxedTupleArr, unboxedTupleArr :: Array Int (TyCon,DataCon)
236 boxedTupleArr   = array (0,mAX_TUPLE_SIZE) [(i,mk_tuple Boxed i)   | i <- [0..mAX_TUPLE_SIZE]]
237 unboxedTupleArr = array (0,mAX_TUPLE_SIZE) [(i,mk_tuple Unboxed i) | i <- [0..mAX_TUPLE_SIZE]]
238
239 mk_tuple :: Boxity -> Int -> (TyCon,DataCon)
240 mk_tuple boxity arity = (tycon, tuple_con)
241   where
242         tycon   = mkTupleTyCon tc_name tc_kind arity tyvars tuple_con boxity gen_info 
243         tc_name = mkWiredInName mod (mkOccFS tcName name_str) tc_uniq
244         tc_kind = mkArrowKinds (map tyVarKind tyvars) res_kind
245         res_kind | isBoxed boxity = liftedTypeKind
246                  | otherwise      = unliftedTypeKind
247
248         tyvars   | isBoxed boxity = take arity alphaTyVars
249                  | otherwise      = take arity openAlphaTyVars
250
251         tuple_con = pcDataCon name tyvars [] tyvar_tys tycon
252         tyvar_tys = mkTyVarTys tyvars
253         (mod_name, name_str) = mkTupNameStr boxity arity
254         name      = mkWiredInName mod (mkOccFS dataName name_str) dc_uniq
255         tc_uniq   = mkTupleTyConUnique   boxity arity
256         dc_uniq   = mkTupleDataConUnique boxity arity
257         mod       = mkPrelModule mod_name
258         gen_info  = mk_tc_gen_info mod tc_uniq tc_name tycon
259
260 unitTyCon     = tupleTyCon Boxed 0
261 unitDataConId = dataConWorkId (head (tyConDataCons unitTyCon))
262
263 pairTyCon = tupleTyCon Boxed 2
264
265 unboxedSingletonTyCon   = tupleTyCon Unboxed 1
266 unboxedSingletonDataCon = tupleCon   Unboxed 1
267
268 unboxedPairTyCon   = tupleTyCon Unboxed 2
269 unboxedPairDataCon = tupleCon   Unboxed 2
270 \end{code}
271
272 %************************************************************************
273 %*                                                                      *
274 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
275 %*                                                                      *
276 %************************************************************************
277
278 \begin{code}
279 -- The Void type is represented as a data type with no constructors
280 -- It's a built in type (i.e. there's no way to define it in Haskell;
281 --      the nearest would be
282 --
283 --              data Void =             -- No constructors!
284 --
285 -- ) It's lifted; there is only one value of this
286 -- type, namely "void", whose semantics is just bottom.
287 --
288 -- Haskell 98 drops the definition of a Void type, so we just 'simulate'
289 -- voidTy using ().
290 voidTy = unitTy
291 \end{code}
292
293
294 \begin{code}
295 charTy = mkTyConTy charTyCon
296
297 charTyCon   = pcNonRecDataTyCon charTyConName [] [] [charDataCon]
298 charDataCon = pcDataCon charDataConName [] [] [charPrimTy] charTyCon
299
300 stringTy = mkListTy charTy -- convenience only
301 \end{code}
302
303 \begin{code}
304 intTy = mkTyConTy intTyCon 
305
306 intTyCon = pcNonRecDataTyCon intTyConName [] [] [intDataCon]
307 intDataCon = pcDataCon intDataConName [] [] [intPrimTy] intTyCon
308 \end{code}
309
310 \begin{code}
311 wordTy = mkTyConTy wordTyCon
312
313 wordTyCon = pcNonRecDataTyCon wordTyConName [] [] [wordDataCon]
314 wordDataCon = pcDataCon wordDataConName [] [] [wordPrimTy] wordTyCon
315 \end{code}
316
317 \begin{code}
318 addrTy = mkTyConTy addrTyCon
319
320 addrTyCon = pcNonRecDataTyCon addrTyConName [] [] [addrDataCon]
321 addrDataCon = pcDataCon addrDataConName [] [] [addrPrimTy] addrTyCon
322 \end{code}
323
324 \begin{code}
325 ptrTy = mkTyConTy ptrTyCon
326
327 ptrTyCon = pcNonRecDataTyCon ptrTyConName alpha_tyvar [(True,False)] [ptrDataCon]
328 ptrDataCon = pcDataCon ptrDataConName alpha_tyvar [] [addrPrimTy] ptrTyCon
329 \end{code}
330
331 \begin{code}
332 funPtrTy = mkTyConTy funPtrTyCon
333
334 funPtrTyCon = pcNonRecDataTyCon funPtrTyConName alpha_tyvar [(True,False)] [funPtrDataCon]
335 funPtrDataCon = pcDataCon funPtrDataConName alpha_tyvar [] [addrPrimTy] funPtrTyCon
336 \end{code}
337
338 \begin{code}
339 floatTy = mkTyConTy floatTyCon
340
341 floatTyCon   = pcNonRecDataTyCon floatTyConName   [] [] [floatDataCon]
342 floatDataCon = pcDataCon         floatDataConName [] [] [floatPrimTy] floatTyCon
343 \end{code}
344
345 \begin{code}
346 doubleTy = mkTyConTy doubleTyCon
347
348 doubleTyCon   = pcNonRecDataTyCon doubleTyConName     [] [] [doubleDataCon]
349 doubleDataCon = pcDataCon         doubleDataConName [] [] [doublePrimTy] doubleTyCon
350 \end{code}
351
352 \begin{code}
353 stablePtrTyCon
354   = pcNonRecDataTyCon stablePtrTyConName
355         alpha_tyvar [(True,False)] [stablePtrDataCon]
356   where
357     stablePtrDataCon
358       = pcDataCon stablePtrDataConName
359             alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon
360 \end{code}
361
362 \begin{code}
363 foreignObjTyCon
364   = pcNonRecDataTyCon foreignObjTyConName
365         [] [] [foreignObjDataCon]
366   where
367     foreignObjDataCon
368       = pcDataCon foreignObjDataConName
369             [] [] [foreignObjPrimTy] foreignObjTyCon
370 \end{code}
371
372 \begin{code}
373 foreignPtrTyCon
374   = pcNonRecDataTyCon foreignPtrTyConName
375         alpha_tyvar  [(True,False)] [foreignPtrDataCon]
376   where
377     foreignPtrDataCon
378       = pcDataCon foreignPtrDataConName
379             alpha_tyvar [] [foreignObjPrimTy] foreignPtrTyCon
380 \end{code}
381
382 %************************************************************************
383 %*                                                                      *
384 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
385 %*                                                                      *
386 %************************************************************************
387
388 @Integer@ and its pals are not really primitive.  @Integer@ itself, first:
389 \begin{code}
390 integerTy :: Type
391 integerTy = mkTyConTy integerTyCon
392
393 integerTyCon = pcNonRecDataTyCon integerTyConName
394                    [] [] [smallIntegerDataCon, largeIntegerDataCon]
395
396 smallIntegerDataCon = pcDataCon smallIntegerDataConName
397                 [] [] [intPrimTy] integerTyCon
398 largeIntegerDataCon = pcDataCon largeIntegerDataConName
399                 [] [] [intPrimTy, byteArrayPrimTy] integerTyCon
400 \end{code}
401
402
403 %************************************************************************
404 %*                                                                      *
405 \subsection[TysWiredIn-Bool]{The @Bool@ type}
406 %*                                                                      *
407 %************************************************************************
408
409 An ordinary enumeration type, but deeply wired in.  There are no
410 magical operations on @Bool@ (just the regular Prelude code).
411
412 {\em BEGIN IDLE SPECULATION BY SIMON}
413
414 This is not the only way to encode @Bool@.  A more obvious coding makes
415 @Bool@ just a boxed up version of @Bool#@, like this:
416 \begin{verbatim}
417 type Bool# = Int#
418 data Bool = MkBool Bool#
419 \end{verbatim}
420
421 Unfortunately, this doesn't correspond to what the Report says @Bool@
422 looks like!  Furthermore, we get slightly less efficient code (I
423 think) with this coding. @gtInt@ would look like this:
424
425 \begin{verbatim}
426 gtInt :: Int -> Int -> Bool
427 gtInt x y = case x of I# x# ->
428             case y of I# y# ->
429             case (gtIntPrim x# y#) of
430                 b# -> MkBool b#
431 \end{verbatim}
432
433 Notice that the result of the @gtIntPrim@ comparison has to be turned
434 into an integer (here called @b#@), and returned in a @MkBool@ box.
435
436 The @if@ expression would compile to this:
437 \begin{verbatim}
438 case (gtInt x y) of
439   MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
440 \end{verbatim}
441
442 I think this code is a little less efficient than the previous code,
443 but I'm not certain.  At all events, corresponding with the Report is
444 important.  The interesting thing is that the language is expressive
445 enough to describe more than one alternative; and that a type doesn't
446 necessarily need to be a straightforwardly boxed version of its
447 primitive counterpart.
448
449 {\em END IDLE SPECULATION BY SIMON}
450
451 \begin{code}
452 boolTy = mkTyConTy boolTyCon
453
454 boolTyCon = pcTyCon EnumTyCon NonRecursive boolTyConName
455                     [] [] [falseDataCon, trueDataCon]
456
457 falseDataCon = pcDataCon falseDataConName [] [] [] boolTyCon
458 trueDataCon  = pcDataCon trueDataConName  [] [] [] boolTyCon
459
460 falseDataConId = dataConWorkId falseDataCon
461 trueDataConId  = dataConWorkId trueDataCon
462 \end{code}
463
464 %************************************************************************
465 %*                                                                      *
466 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
467 %*                                                                      *
468 %************************************************************************
469
470 Special syntax, deeply wired in, but otherwise an ordinary algebraic
471 data types:
472 \begin{verbatim}
473 data [] a = [] | a : (List a)
474 data () = ()
475 data (,) a b = (,,) a b
476 ...
477 \end{verbatim}
478
479 \begin{code}
480 mkListTy :: Type -> Type
481 mkListTy ty = mkTyConApp listTyCon [ty]
482
483 listTyCon = pcRecDataTyCon listTyConName
484                         alpha_tyvar [(True,False)] [nilDataCon, consDataCon]
485
486 nilDataCon  = pcDataCon nilDataConName alpha_tyvar [] [] listTyCon
487 consDataCon = pcDataCon consDataConName
488                alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
489 -- Interesting: polymorphic recursion would help here.
490 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
491 -- gets the over-specific type (Type -> Type)
492 \end{code}
493
494 %************************************************************************
495 %*                                                                      *
496 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
497 %*                                                                      *
498 %************************************************************************
499
500 The tuple types are definitely magic, because they form an infinite
501 family.
502
503 \begin{itemize}
504 \item
505 They have a special family of type constructors, of type @TyCon@
506 These contain the tycon arity, but don't require a Unique.
507
508 \item
509 They have a special family of constructors, of type
510 @Id@. Again these contain their arity but don't need a Unique.
511
512 \item
513 There should be a magic way of generating the info tables and
514 entry code for all tuples.
515
516 But at the moment we just compile a Haskell source
517 file\srcloc{lib/prelude/...} containing declarations like:
518 \begin{verbatim}
519 data Tuple0             = Tup0
520 data Tuple2  a b        = Tup2  a b
521 data Tuple3  a b c      = Tup3  a b c
522 data Tuple4  a b c d    = Tup4  a b c d
523 ...
524 \end{verbatim}
525 The print-names associated with the magic @Id@s for tuple constructors
526 ``just happen'' to be the same as those generated by these
527 declarations.
528
529 \item
530 The instance environment should have a magic way to know
531 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
532 so on. \ToDo{Not implemented yet.}
533
534 \item
535 There should also be a way to generate the appropriate code for each
536 of these instances, but (like the info tables and entry code) it is
537 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
538 \end{itemize}
539
540 \begin{code}
541 mkTupleTy :: Boxity -> Int -> [Type] -> Type
542 mkTupleTy boxity arity tys = mkTyConApp (tupleTyCon boxity arity) tys
543
544 unitTy    = mkTupleTy Boxed 0 []
545 \end{code}
546
547 %************************************************************************
548 %*                                                                      *
549 \subsection[TysWiredIn-PArr]{The @[::]@ type}
550 %*                                                                      *
551 %************************************************************************
552
553 Special syntax for parallel arrays needs some wired in definitions.
554
555 \begin{code}
556 -- construct a type representing the application of the parallel array
557 -- constructor 
558 --
559 mkPArrTy    :: Type -> Type
560 mkPArrTy ty  = mkTyConApp parrTyCon [ty]
561
562 -- represents the type constructor of parallel arrays
563 --
564 -- * this must match the definition in `PrelPArr'
565 --
566 -- NB: Although the constructor is given here, it will not be accessible in
567 --     user code as it is not in the environment of any compiled module except
568 --     `PrelPArr'.
569 --
570 parrTyCon :: TyCon
571 parrTyCon  = tycon
572   where
573     tycon   = mkAlgTyCon 
574                 parrTyConName 
575                 kind
576                 tyvars
577                 []                       -- No context
578                 [(True, False)]
579                 (DataCons [parrDataCon]) -- The constructor defined in `PrelPArr'
580                 []                       -- No record selectors
581                 DataTyCon
582                 NonRecursive
583                 genInfo
584     tyvars  = alpha_tyvar
585     mod     = nameModule parrTyConName
586     kind    = mkArrowKinds (map tyVarKind tyvars) liftedTypeKind
587     genInfo = mk_tc_gen_info mod (nameUnique parrTyConName) parrTyConName tycon
588
589 parrDataCon :: DataCon
590 parrDataCon  = pcDataCon 
591                  parrDataConName 
592                  alpha_tyvar            -- forall'ed type variables
593                  []                     -- context
594                  [intPrimTy,            -- 1st argument: Int#
595                   mkTyConApp            -- 2nd argument: Array# a
596                     arrayPrimTyCon 
597                     alpha_ty] 
598                  parrTyCon
599
600 -- check whether a type constructor is the constructor for parallel arrays
601 --
602 isPArrTyCon    :: TyCon -> Bool
603 isPArrTyCon tc  = tyConName tc == parrTyConName
604
605 -- fake array constructors
606 --
607 -- * these constructors are never really used to represent array values;
608 --   however, they are very convenient during desugaring (and, in particular,
609 --   in the pattern matching compiler) to treat array pattern just like
610 --   yet another constructor pattern
611 --
612 parrFakeCon                        :: Arity -> DataCon
613 parrFakeCon i | i > mAX_TUPLE_SIZE  = mkPArrFakeCon  i  -- build one specially
614 parrFakeCon i                       = parrFakeConArr!i
615
616 -- pre-defined set of constructors
617 --
618 parrFakeConArr :: Array Int DataCon
619 parrFakeConArr  = array (0, mAX_TUPLE_SIZE) [(i, mkPArrFakeCon i)   
620                                             | i <- [0..mAX_TUPLE_SIZE]]
621
622 -- build a fake parallel array constructor for the given arity
623 --
624 mkPArrFakeCon       :: Int -> DataCon
625 mkPArrFakeCon arity  = pcDataCon name [tyvar] [] tyvarTys parrTyCon
626   where
627         tyvar     = head alphaTyVars
628         tyvarTys  = replicate arity $ mkTyVarTy tyvar
629         nameStr   = _PK_ ("MkPArr" ++ show arity)
630         name      = mkWiredInName mod (mkOccFS dataName nameStr) uniq
631         uniq      = mkPArrDataConUnique arity
632         mod       = mkPrelModule pREL_PARR_Name
633
634 -- checks whether a data constructor is a fake constructor for parallel arrays
635 --
636 isPArrFakeCon      :: DataCon -> Bool
637 isPArrFakeCon dcon  = dcon == parrFakeCon (dataConSourceArity dcon)
638 \end{code}
639
640 %************************************************************************
641 %*                                                                      *
642 \subsection{Wired In Type Constructors for Representation Types}
643 %*                                                                      *
644 %************************************************************************
645
646 The following code defines the wired in datatypes cross, plus, unit
647 and c_of needed for the generic methods.
648
649 Ok, so the basic story is that for each type constructor I need to
650 create 2 things - a TyCon and a DataCon and then we are basically
651 ok. There are going to be no arguments passed to these functions
652 because -well- there is nothing to pass to these functions.
653
654 \begin{code}
655 crossTyCon :: TyCon
656 crossTyCon = pcNonRecDataTyCon crossTyConName alpha_beta_tyvars [] [crossDataCon]
657
658 crossDataCon :: DataCon
659 crossDataCon = pcDataCon crossDataConName alpha_beta_tyvars [] [alphaTy, betaTy] crossTyCon
660
661 plusTyCon :: TyCon
662 plusTyCon = pcNonRecDataTyCon plusTyConName alpha_beta_tyvars [] [inlDataCon, inrDataCon]
663
664 inlDataCon, inrDataCon :: DataCon
665 inlDataCon = pcDataCon inlDataConName alpha_beta_tyvars [] [alphaTy] plusTyCon
666 inrDataCon = pcDataCon inrDataConName alpha_beta_tyvars [] [betaTy]  plusTyCon
667
668 genUnitTyCon :: TyCon   -- The "1" type constructor for generics
669 genUnitTyCon = pcNonRecDataTyCon genUnitTyConName [] [] [genUnitDataCon]
670
671 genUnitDataCon :: DataCon
672 genUnitDataCon = pcDataCon genUnitDataConName [] [] [] genUnitTyCon
673 \end{code}