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