Document TysWiredIn and follow OccName changes
[ghc-hetmet.git] / 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 tracks the ``state interface'' document, ``GHC prelude:
7 types and operations.''
8
9 \begin{code}
10 -- | This module is about types that can be defined in Haskell, but which
11 -- must be wired into the compiler nonetheless.
12 module TysWiredIn (
13         -- * All wired in things
14         wiredInTyCons, 
15
16         -- * Bool
17         boolTy, boolTyCon, boolTyCon_RDR, boolTyConName,
18         trueDataCon,  trueDataConId,  true_RDR,
19         falseDataCon, falseDataConId, false_RDR,
20
21         -- * Char
22         charTyCon, charDataCon, charTyCon_RDR,
23         charTy, stringTy, charTyConName,
24
25         -- * Double
26         doubleTyCon, doubleDataCon, doubleTy, doubleTyConName, 
27         
28         -- * Float
29         floatTyCon, floatDataCon, floatTy, floatTyConName,
30
31         -- * Int
32         intTyCon, intDataCon, intTyCon_RDR, intDataCon_RDR, intTyConName,
33         intTy,
34
35         -- * Word
36         wordTyCon, wordDataCon, wordTyConName, wordTy,
37
38         -- * List
39         listTyCon, nilDataCon, consDataCon,
40         listTyCon_RDR, consDataCon_RDR, listTyConName,
41         mkListTy,
42
43         -- * Tuples
44         mkTupleTy,
45         tupleTyCon, tupleCon, 
46         unitTyCon, unitDataCon, unitDataConId, pairTyCon, 
47         unboxedSingletonTyCon, unboxedSingletonDataCon,
48         unboxedPairTyCon, unboxedPairDataCon,
49
50         -- * Unit
51         unitTy,
52
53         -- * Parallel arrays
54         mkPArrTy,
55         parrTyCon, parrFakeCon, isPArrTyCon, isPArrFakeCon,
56         parrTyCon_RDR, parrTyConName
57     ) where
58
59 import {-# SOURCE #-} MkId( mkDataConIds )
60
61 -- friends:
62 import PrelNames
63 import TysPrim
64
65 -- others:
66 import Constants        ( mAX_TUPLE_SIZE )
67 import Module           ( Module )
68 import RdrName
69 import Name             ( Name, BuiltInSyntax(..), nameUnique, nameOccName, 
70                           nameModule, mkWiredInName )
71 import OccName          ( mkTcOccFS, mkDataOccFS, mkTupleOcc, mkDataConWorkerOcc,
72                           tcName, dataName )
73 import DataCon          ( DataCon, mkDataCon, dataConWorkId, dataConSourceArity )
74 import Var
75 import TyCon            ( TyCon, AlgTyConRhs(DataTyCon), tyConDataCons,
76                           mkTupleTyCon, mkAlgTyCon, tyConName,
77                           TyConParent(NoParentTyCon) )
78
79 import BasicTypes       ( Arity, RecFlag(..), Boxity(..), isBoxed,
80                           StrictnessMark(..) )
81
82 import Type             ( Type, mkTyConTy, mkTyConApp, mkTyVarTy, mkTyVarTys,
83                           TyThing(..) )
84 import Coercion         ( unsafeCoercionTyCon, symCoercionTyCon,
85                           transCoercionTyCon, leftCoercionTyCon, 
86                           rightCoercionTyCon, instCoercionTyCon )
87 import TypeRep          ( mkArrowKinds, liftedTypeKind, ubxTupleKind )
88 import Unique           ( incrUnique, mkTupleTyConUnique,
89                           mkTupleDataConUnique, mkPArrDataConUnique )
90 import Array
91 import FastString
92 import Outputable
93
94 alpha_tyvar :: [TyVar]
95 alpha_tyvar = [alphaTyVar]
96
97 alpha_ty :: [Type]
98 alpha_ty = [alphaTy]
99 \end{code}
100
101
102 %************************************************************************
103 %*                                                                      *
104 \subsection{Wired in type constructors}
105 %*                                                                      *
106 %************************************************************************
107
108 If you change which things are wired in, make sure you change their
109 names in PrelNames, so they use wTcQual, wDataQual, etc
110
111 \begin{code}
112 wiredInTyCons :: [TyCon]        -- Excludes tuples
113 -- This list is used only to define PrelInfo.wiredInThings
114
115 -- It does not need to include kind constructors, because
116 -- all that wiredInThings does is to initialise the Name table,
117 -- and kind constructors don't appear in source code.
118
119 wiredInTyCons = [ unitTyCon     -- Not treated like other tuples, because
120                                 -- it's defined in GHC.Base, and there's only
121                                 -- one of it.  We put it in wiredInTyCons so
122                                 -- that it'll pre-populate the name cache, so
123                                 -- the special case in lookupOrigNameCache 
124                                 -- doesn't need to look out for it
125               , boolTyCon
126               , charTyCon
127               , doubleTyCon
128               , floatTyCon
129               , intTyCon
130               , listTyCon
131               , parrTyCon
132               , unsafeCoercionTyCon
133               , symCoercionTyCon
134               , transCoercionTyCon
135               , leftCoercionTyCon
136               , rightCoercionTyCon
137               , instCoercionTyCon
138               ]
139 \end{code}
140
141 \begin{code}
142 mkWiredInTyConName :: BuiltInSyntax -> Module -> FastString -> Unique -> TyCon -> Name
143 mkWiredInTyConName built_in modu fs unique tycon
144   = mkWiredInName modu (mkTcOccFS fs) unique
145                   (ATyCon tycon)        -- Relevant TyCon
146                   built_in
147
148 mkWiredInDataConName :: BuiltInSyntax -> Module -> FastString -> Unique -> DataCon -> Name
149 mkWiredInDataConName built_in modu fs unique datacon
150   = mkWiredInName modu (mkDataOccFS fs) unique
151                   (ADataCon datacon)    -- Relevant DataCon
152                   built_in
153
154 charTyConName, charDataConName, intTyConName, intDataConName :: Name
155 charTyConName     = mkWiredInTyConName   UserSyntax gHC_TYPES (fsLit "Char") charTyConKey charTyCon
156 charDataConName   = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "C#") charDataConKey charDataCon
157 intTyConName      = mkWiredInTyConName   UserSyntax gHC_TYPES (fsLit "Int") intTyConKey   intTyCon
158 intDataConName    = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "I#") intDataConKey  intDataCon
159
160 boolTyConName, falseDataConName, trueDataConName :: Name
161 boolTyConName     = mkWiredInTyConName   UserSyntax gHC_BOOL (fsLit "Bool") boolTyConKey boolTyCon
162 falseDataConName  = mkWiredInDataConName UserSyntax gHC_BOOL (fsLit "False") falseDataConKey falseDataCon
163 trueDataConName   = mkWiredInDataConName UserSyntax gHC_BOOL (fsLit "True")  trueDataConKey  trueDataCon 
164
165 listTyConName, nilDataConName, consDataConName :: Name
166 listTyConName     = mkWiredInTyConName   BuiltInSyntax gHC_TYPES (fsLit "[]") listTyConKey listTyCon
167 nilDataConName    = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit "[]") nilDataConKey nilDataCon 
168 consDataConName   = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit ":") consDataConKey consDataCon
169
170 floatTyConName, floatDataConName, doubleTyConName, doubleDataConName :: Name
171 floatTyConName     = mkWiredInTyConName   UserSyntax gHC_TYPES (fsLit "Float") floatTyConKey floatTyCon
172 floatDataConName   = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "F#") floatDataConKey floatDataCon
173 doubleTyConName    = mkWiredInTyConName   UserSyntax gHC_TYPES (fsLit "Double") doubleTyConKey doubleTyCon
174 doubleDataConName  = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "D#") doubleDataConKey doubleDataCon
175
176 parrTyConName, parrDataConName :: Name
177 parrTyConName     = mkWiredInTyConName   BuiltInSyntax gHC_PARR (fsLit "[::]") parrTyConKey parrTyCon 
178 parrDataConName   = mkWiredInDataConName UserSyntax    gHC_PARR (fsLit "PArr") parrDataConKey parrDataCon
179
180 boolTyCon_RDR, false_RDR, true_RDR, intTyCon_RDR, charTyCon_RDR,
181     intDataCon_RDR, listTyCon_RDR, consDataCon_RDR, parrTyCon_RDR:: RdrName
182 boolTyCon_RDR   = nameRdrName boolTyConName
183 false_RDR       = nameRdrName falseDataConName
184 true_RDR        = nameRdrName trueDataConName
185 intTyCon_RDR    = nameRdrName intTyConName
186 charTyCon_RDR   = nameRdrName charTyConName
187 intDataCon_RDR  = nameRdrName intDataConName
188 listTyCon_RDR   = nameRdrName listTyConName
189 consDataCon_RDR = nameRdrName consDataConName
190 parrTyCon_RDR   = nameRdrName parrTyConName
191 {-
192 tySuperKindTyCon_RDR     = nameRdrName tySuperKindTyConName
193 coSuperKindTyCon_RDR = nameRdrName coSuperKindTyConName
194 liftedTypeKindTyCon_RDR   = nameRdrName liftedTypeKindTyConName
195 openTypeKindTyCon_RDR     = nameRdrName openTypeKindTyConName
196 unliftedTypeKindTyCon_RDR = nameRdrName unliftedTypeKindTyConName
197 ubxTupleKindTyCon_RDR     = nameRdrName ubxTupleKindTyConName
198 argTypeKindTyCon_RDR      = nameRdrName argTypeKindTyConName
199 funKindTyCon_RDR          = nameRdrName funKindTyConName
200 -}
201 \end{code}
202
203
204 %************************************************************************
205 %*                                                                      *
206 \subsection{mkWiredInTyCon}
207 %*                                                                      *
208 %************************************************************************
209
210 \begin{code}
211 pcNonRecDataTyCon :: Name -> [TyVar] -> [DataCon] -> TyCon
212 pcNonRecDataTyCon = pcTyCon False NonRecursive
213 pcRecDataTyCon :: Name -> [TyVar] -> [DataCon] -> TyCon
214 pcRecDataTyCon    = pcTyCon False Recursive
215
216 pcTyCon :: Bool -> RecFlag -> Name -> [TyVar] -> [DataCon] -> TyCon
217 pcTyCon is_enum is_rec name tyvars cons
218   = tycon
219   where
220     tycon = mkAlgTyCon name
221                 (mkArrowKinds (map tyVarKind tyvars) liftedTypeKind)
222                 tyvars
223                 []              -- No stupid theta
224                 (DataTyCon cons is_enum)
225                 []              -- No record selectors
226                 NoParentTyCon
227                 is_rec
228                 True            -- All the wired-in tycons have generics
229                 False           -- Not in GADT syntax
230
231 pcDataCon :: Name -> [TyVar] -> [Type] -> TyCon -> DataCon
232 pcDataCon = pcDataConWithFixity False
233
234 pcDataConWithFixity :: Bool -> Name -> [TyVar] -> [Type] -> TyCon -> DataCon
235 -- The Name should be in the DataName name space; it's the name
236 -- of the DataCon itself.
237 --
238 -- The unique is the first of two free uniques;
239 -- the first is used for the datacon itself,
240 -- the second is used for the "worker name"
241
242 pcDataConWithFixity declared_infix dc_name tyvars arg_tys tycon
243   = data_con
244   where
245     data_con = mkDataCon dc_name declared_infix
246                 (map (const NotMarkedStrict) arg_tys)
247                 []      -- No labelled fields
248                 tyvars
249                 []      -- No existential type variables
250                 []      -- No equality spec
251                 []      -- No theta
252                 arg_tys tycon
253                 []      -- No stupid theta
254                 (mkDataConIds bogus_wrap_name wrk_name data_con)
255                 
256
257     modu      = nameModule dc_name
258     wrk_occ  = mkDataConWorkerOcc (nameOccName dc_name)
259     wrk_key  = incrUnique (nameUnique dc_name)
260     wrk_name = mkWiredInName modu wrk_occ wrk_key
261                              (AnId (dataConWorkId data_con)) UserSyntax
262     bogus_wrap_name = pprPanic "Wired-in data wrapper id" (ppr dc_name)
263         -- Wired-in types are too simple to need wrappers
264 \end{code}
265
266
267 %************************************************************************
268 %*                                                                      *
269 \subsection[TysWiredIn-tuples]{The tuple types}
270 %*                                                                      *
271 %************************************************************************
272
273 \begin{code}
274 tupleTyCon :: Boxity -> Arity -> TyCon
275 tupleTyCon boxity i | i > mAX_TUPLE_SIZE = fst (mk_tuple boxity i)      -- Build one specially
276 tupleTyCon Boxed   i = fst (boxedTupleArr   ! i)
277 tupleTyCon Unboxed i = fst (unboxedTupleArr ! i)
278
279 tupleCon :: Boxity -> Arity -> DataCon
280 tupleCon boxity i | i > mAX_TUPLE_SIZE = snd (mk_tuple boxity i)        -- Build one specially
281 tupleCon Boxed   i = snd (boxedTupleArr   ! i)
282 tupleCon Unboxed i = snd (unboxedTupleArr ! i)
283
284 boxedTupleArr, unboxedTupleArr :: Array Int (TyCon,DataCon)
285 boxedTupleArr   = listArray (0,mAX_TUPLE_SIZE) [mk_tuple Boxed i | i <- [0..mAX_TUPLE_SIZE]]
286 unboxedTupleArr = listArray (0,mAX_TUPLE_SIZE) [mk_tuple Unboxed i | i <- [0..mAX_TUPLE_SIZE]]
287
288 mk_tuple :: Boxity -> Int -> (TyCon,DataCon)
289 mk_tuple boxity arity = (tycon, tuple_con)
290   where
291         tycon   = mkTupleTyCon tc_name tc_kind arity tyvars tuple_con boxity gen_info 
292         modu    = mkTupleModule boxity arity
293         tc_name = mkWiredInName modu (mkTupleOcc tcName boxity arity) tc_uniq
294                                 (ATyCon tycon) BuiltInSyntax
295         tc_kind = mkArrowKinds (map tyVarKind tyvars) res_kind
296         res_kind | isBoxed boxity = liftedTypeKind
297                  | otherwise      = ubxTupleKind
298
299         tyvars   | isBoxed boxity = take arity alphaTyVars
300                  | otherwise      = take arity openAlphaTyVars
301
302         tuple_con = pcDataCon dc_name tyvars tyvar_tys tycon
303         tyvar_tys = mkTyVarTys tyvars
304         dc_name   = mkWiredInName modu (mkTupleOcc dataName boxity arity) dc_uniq
305                                   (ADataCon tuple_con) BuiltInSyntax
306         tc_uniq   = mkTupleTyConUnique   boxity arity
307         dc_uniq   = mkTupleDataConUnique boxity arity
308         gen_info  = True                -- Tuples all have generics..
309                                         -- hmm: that's a *lot* of code
310
311 unitTyCon :: TyCon
312 unitTyCon     = tupleTyCon Boxed 0
313 unitDataCon :: DataCon
314 unitDataCon   = head (tyConDataCons unitTyCon)
315 unitDataConId :: Id
316 unitDataConId = dataConWorkId unitDataCon
317
318 pairTyCon :: TyCon
319 pairTyCon = tupleTyCon Boxed 2
320
321 unboxedSingletonTyCon :: TyCon
322 unboxedSingletonTyCon   = tupleTyCon Unboxed 1
323 unboxedSingletonDataCon :: DataCon
324 unboxedSingletonDataCon = tupleCon   Unboxed 1
325
326 unboxedPairTyCon :: TyCon
327 unboxedPairTyCon   = tupleTyCon Unboxed 2
328 unboxedPairDataCon :: DataCon
329 unboxedPairDataCon = tupleCon   Unboxed 2
330 \end{code}
331
332 %************************************************************************
333 %*                                                                      *
334 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
335 %*                                                                      *
336 %************************************************************************
337
338 \begin{code}
339 charTy :: Type
340 charTy = mkTyConTy charTyCon
341
342 charTyCon :: TyCon
343 charTyCon   = pcNonRecDataTyCon charTyConName [] [charDataCon]
344 charDataCon :: DataCon
345 charDataCon = pcDataCon charDataConName [] [charPrimTy] charTyCon
346
347 stringTy :: Type
348 stringTy = mkListTy charTy -- convenience only
349 \end{code}
350
351 \begin{code}
352 intTy :: Type
353 intTy = mkTyConTy intTyCon 
354
355 intTyCon :: TyCon
356 intTyCon = pcNonRecDataTyCon intTyConName [] [intDataCon]
357 intDataCon :: DataCon
358 intDataCon = pcDataCon intDataConName [] [intPrimTy] intTyCon
359 \end{code}
360
361 \begin{code}
362 wordTy :: Type
363 wordTy = mkTyConTy wordTyCon 
364
365 wordTyCon :: TyCon
366 wordTyCon = pcNonRecDataTyCon wordTyConName [] [wordDataCon]
367 wordDataCon :: DataCon
368 wordDataCon = pcDataCon wordDataConName [] [wordPrimTy] wordTyCon
369 \end{code}
370
371 \begin{code}
372 floatTy :: Type
373 floatTy = mkTyConTy floatTyCon
374
375 floatTyCon :: TyCon
376 floatTyCon   = pcNonRecDataTyCon floatTyConName   [] [floatDataCon]
377 floatDataCon :: DataCon
378 floatDataCon = pcDataCon         floatDataConName [] [floatPrimTy] floatTyCon
379 \end{code}
380
381 \begin{code}
382 doubleTy :: Type
383 doubleTy = mkTyConTy doubleTyCon
384
385 doubleTyCon :: TyCon
386 doubleTyCon = pcNonRecDataTyCon doubleTyConName [] [doubleDataCon]
387
388 doubleDataCon :: DataCon
389 doubleDataCon = pcDataCon doubleDataConName [] [doublePrimTy] doubleTyCon
390 \end{code}
391
392
393 %************************************************************************
394 %*                                                                      *
395 \subsection[TysWiredIn-Bool]{The @Bool@ type}
396 %*                                                                      *
397 %************************************************************************
398
399 An ordinary enumeration type, but deeply wired in.  There are no
400 magical operations on @Bool@ (just the regular Prelude code).
401
402 {\em BEGIN IDLE SPECULATION BY SIMON}
403
404 This is not the only way to encode @Bool@.  A more obvious coding makes
405 @Bool@ just a boxed up version of @Bool#@, like this:
406 \begin{verbatim}
407 type Bool# = Int#
408 data Bool = MkBool Bool#
409 \end{verbatim}
410
411 Unfortunately, this doesn't correspond to what the Report says @Bool@
412 looks like!  Furthermore, we get slightly less efficient code (I
413 think) with this coding. @gtInt@ would look like this:
414
415 \begin{verbatim}
416 gtInt :: Int -> Int -> Bool
417 gtInt x y = case x of I# x# ->
418             case y of I# y# ->
419             case (gtIntPrim x# y#) of
420                 b# -> MkBool b#
421 \end{verbatim}
422
423 Notice that the result of the @gtIntPrim@ comparison has to be turned
424 into an integer (here called @b#@), and returned in a @MkBool@ box.
425
426 The @if@ expression would compile to this:
427 \begin{verbatim}
428 case (gtInt x y) of
429   MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
430 \end{verbatim}
431
432 I think this code is a little less efficient than the previous code,
433 but I'm not certain.  At all events, corresponding with the Report is
434 important.  The interesting thing is that the language is expressive
435 enough to describe more than one alternative; and that a type doesn't
436 necessarily need to be a straightforwardly boxed version of its
437 primitive counterpart.
438
439 {\em END IDLE SPECULATION BY SIMON}
440
441 \begin{code}
442 boolTy :: Type
443 boolTy = mkTyConTy boolTyCon
444
445 boolTyCon :: TyCon
446 boolTyCon = pcTyCon True NonRecursive boolTyConName
447                     [] [falseDataCon, trueDataCon]
448
449 falseDataCon, trueDataCon :: DataCon
450 falseDataCon = pcDataCon falseDataConName [] [] boolTyCon
451 trueDataCon  = pcDataCon trueDataConName  [] [] boolTyCon
452
453 falseDataConId, trueDataConId :: Id
454 falseDataConId = dataConWorkId falseDataCon
455 trueDataConId  = dataConWorkId trueDataCon
456 \end{code}
457
458 %************************************************************************
459 %*                                                                      *
460 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
461 %*                                                                      *
462 %************************************************************************
463
464 Special syntax, deeply wired in, but otherwise an ordinary algebraic
465 data types:
466 \begin{verbatim}
467 data [] a = [] | a : (List a)
468 data () = ()
469 data (,) a b = (,,) a b
470 ...
471 \end{verbatim}
472
473 \begin{code}
474 mkListTy :: Type -> Type
475 mkListTy ty = mkTyConApp listTyCon [ty]
476
477 listTyCon :: TyCon
478 listTyCon = pcRecDataTyCon listTyConName alpha_tyvar [nilDataCon, consDataCon]
479
480 nilDataCon :: DataCon
481 nilDataCon  = pcDataCon nilDataConName alpha_tyvar [] listTyCon
482
483 consDataCon :: DataCon
484 consDataCon = pcDataConWithFixity True {- Declared infix -}
485                consDataConName
486                alpha_tyvar [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
487 -- Interesting: polymorphic recursion would help here.
488 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
489 -- gets the over-specific type (Type -> Type)
490 \end{code}
491
492 %************************************************************************
493 %*                                                                      *
494 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
495 %*                                                                      *
496 %************************************************************************
497
498 The tuple types are definitely magic, because they form an infinite
499 family.
500
501 \begin{itemize}
502 \item
503 They have a special family of type constructors, of type @TyCon@
504 These contain the tycon arity, but don't require a Unique.
505
506 \item
507 They have a special family of constructors, of type
508 @Id@. Again these contain their arity but don't need a Unique.
509
510 \item
511 There should be a magic way of generating the info tables and
512 entry code for all tuples.
513
514 But at the moment we just compile a Haskell source
515 file\srcloc{lib/prelude/...} containing declarations like:
516 \begin{verbatim}
517 data Tuple0             = Tup0
518 data Tuple2  a b        = Tup2  a b
519 data Tuple3  a b c      = Tup3  a b c
520 data Tuple4  a b c d    = Tup4  a b c d
521 ...
522 \end{verbatim}
523 The print-names associated with the magic @Id@s for tuple constructors
524 ``just happen'' to be the same as those generated by these
525 declarations.
526
527 \item
528 The instance environment should have a magic way to know
529 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
530 so on. \ToDo{Not implemented yet.}
531
532 \item
533 There should also be a way to generate the appropriate code for each
534 of these instances, but (like the info tables and entry code) it is
535 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
536 \end{itemize}
537
538 \begin{code}
539 mkTupleTy :: Boxity -> Int -> [Type] -> Type
540 mkTupleTy boxity arity tys = mkTyConApp (tupleTyCon boxity arity) tys
541
542 unitTy :: Type
543 unitTy = mkTupleTy Boxed 0 []
544 \end{code}
545
546 %************************************************************************
547 %*                                                                      *
548 \subsection[TysWiredIn-PArr]{The @[::]@ type}
549 %*                                                                      *
550 %************************************************************************
551
552 Special syntax for parallel arrays needs some wired in definitions.
553
554 \begin{code}
555 -- | Construct a type representing the application of the parallel array constructor 
556 mkPArrTy    :: Type -> Type
557 mkPArrTy ty  = mkTyConApp parrTyCon [ty]
558
559 -- | Represents the type constructor of parallel arrays
560 --
561 --  * This must match the definition in @PrelPArr@
562 --
563 -- NB: Although the constructor is given here, it will not be accessible in
564 --     user code as it is not in the environment of any compiled module except
565 --     @PrelPArr@.
566 --
567 parrTyCon :: TyCon
568 parrTyCon  = pcNonRecDataTyCon parrTyConName alpha_tyvar [parrDataCon]
569
570 parrDataCon :: DataCon
571 parrDataCon  = pcDataCon 
572                  parrDataConName 
573                  alpha_tyvar            -- forall'ed type variables
574                  [intPrimTy,            -- 1st argument: Int#
575                   mkTyConApp            -- 2nd argument: Array# a
576                     arrayPrimTyCon 
577                     alpha_ty] 
578                  parrTyCon
579
580 -- | Check whether a type constructor is the constructor for parallel arrays
581 isPArrTyCon    :: TyCon -> Bool
582 isPArrTyCon tc  = tyConName tc == parrTyConName
583
584 -- | Fake array constructors
585 --
586 -- * These constructors are never really used to represent array values;
587 --   however, they are very convenient during desugaring (and, in particular,
588 --   in the pattern matching compiler) to treat array pattern just like
589 --   yet another constructor pattern
590 --
591 parrFakeCon                        :: Arity -> DataCon
592 parrFakeCon i | i > mAX_TUPLE_SIZE  = mkPArrFakeCon  i  -- build one specially
593 parrFakeCon i                       = parrFakeConArr!i
594
595 -- pre-defined set of constructors
596 --
597 parrFakeConArr :: Array Int DataCon
598 parrFakeConArr  = array (0, mAX_TUPLE_SIZE) [(i, mkPArrFakeCon i)   
599                                             | i <- [0..mAX_TUPLE_SIZE]]
600
601 -- build a fake parallel array constructor for the given arity
602 --
603 mkPArrFakeCon       :: Int -> DataCon
604 mkPArrFakeCon arity  = data_con
605   where
606         data_con  = pcDataCon name [tyvar] tyvarTys parrTyCon
607         tyvar     = head alphaTyVars
608         tyvarTys  = replicate arity $ mkTyVarTy tyvar
609         nameStr   = mkFastString ("MkPArr" ++ show arity)
610         name      = mkWiredInName gHC_PARR (mkDataOccFS nameStr) unique
611                                   (ADataCon data_con) UserSyntax
612         unique      = mkPArrDataConUnique arity
613
614 -- | Checks whether a data constructor is a fake constructor for parallel arrays
615 isPArrFakeCon      :: DataCon -> Bool
616 isPArrFakeCon dcon  = dcon == parrFakeCon (dataConSourceArity dcon)
617 \end{code}
618
619