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