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