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