Remove GHC's haskell98 dependency
[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 DataCon          ( DataCon, mkDataCon, dataConWorkId, dataConSourceArity )
73 import Var
74 import TyCon            ( TyCon, AlgTyConRhs(DataTyCon), tyConDataCons,
75                           mkTupleTyCon, mkAlgTyCon, tyConName,
76                           TyConParent(NoParentTyCon) )
77
78 import BasicTypes       ( Arity, RecFlag(..), Boxity(..), isBoxed,
79                           StrictnessMark(..) )
80
81 import Type             ( Type, mkTyConTy, mkTyConApp, mkTyVarTy, mkTyVarTys,
82                           TyThing(..) )
83 import Coercion         ( unsafeCoercionTyCon, symCoercionTyCon,
84                           transCoercionTyCon, leftCoercionTyCon, 
85                           rightCoercionTyCon, instCoercionTyCon )
86 import TypeRep          ( mkArrowKinds, liftedTypeKind, ubxTupleKind )
87 import Unique           ( incrUnique, mkTupleTyConUnique,
88                           mkTupleDataConUnique, mkPArrDataConUnique )
89 import Data.Array
90 import FastString
91 import Outputable
92
93 alpha_tyvar :: [TyVar]
94 alpha_tyvar = [alphaTyVar]
95
96 alpha_ty :: [Type]
97 alpha_ty = [alphaTy]
98 \end{code}
99
100
101 %************************************************************************
102 %*                                                                      *
103 \subsection{Wired in type constructors}
104 %*                                                                      *
105 %************************************************************************
106
107 If you change which things are wired in, make sure you change their
108 names in PrelNames, so they use wTcQual, wDataQual, etc
109
110 \begin{code}
111 wiredInTyCons :: [TyCon]        -- Excludes tuples
112 -- This list is used only to define PrelInfo.wiredInThings
113
114 -- It does not need to include kind constructors, because
115 -- all that wiredInThings does is to initialise the Name table,
116 -- and kind constructors don't appear in source code.
117
118 wiredInTyCons = [ unitTyCon     -- Not treated like other tuples, because
119                                 -- it's defined in GHC.Base, and there's only
120                                 -- one of it.  We put it in wiredInTyCons so
121                                 -- that it'll pre-populate the name cache, so
122                                 -- the special case in lookupOrigNameCache 
123                                 -- doesn't need to look out for it
124               , boolTyCon
125               , charTyCon
126               , doubleTyCon
127               , floatTyCon
128               , intTyCon
129               , listTyCon
130               , parrTyCon
131               , unsafeCoercionTyCon
132               , symCoercionTyCon
133               , transCoercionTyCon
134               , leftCoercionTyCon
135               , rightCoercionTyCon
136               , instCoercionTyCon
137               ]
138 \end{code}
139
140 \begin{code}
141 mkWiredInTyConName :: BuiltInSyntax -> Module -> FastString -> Unique -> TyCon -> Name
142 mkWiredInTyConName built_in modu fs unique tycon
143   = mkWiredInName modu (mkTcOccFS fs) unique
144                   (ATyCon tycon)        -- Relevant TyCon
145                   built_in
146
147 mkWiredInDataConName :: BuiltInSyntax -> Module -> FastString -> Unique -> DataCon -> Name
148 mkWiredInDataConName built_in modu fs unique datacon
149   = mkWiredInName modu (mkDataOccFS fs) unique
150                   (ADataCon datacon)    -- Relevant DataCon
151                   built_in
152
153 charTyConName, charDataConName, intTyConName, intDataConName :: Name
154 charTyConName     = mkWiredInTyConName   UserSyntax gHC_TYPES (fsLit "Char") charTyConKey charTyCon
155 charDataConName   = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "C#") charDataConKey charDataCon
156 intTyConName      = mkWiredInTyConName   UserSyntax gHC_TYPES (fsLit "Int") intTyConKey   intTyCon
157 intDataConName    = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "I#") intDataConKey  intDataCon
158
159 boolTyConName, falseDataConName, trueDataConName :: Name
160 boolTyConName     = mkWiredInTyConName   UserSyntax gHC_BOOL (fsLit "Bool") boolTyConKey boolTyCon
161 falseDataConName  = mkWiredInDataConName UserSyntax gHC_BOOL (fsLit "False") falseDataConKey falseDataCon
162 trueDataConName   = mkWiredInDataConName UserSyntax gHC_BOOL (fsLit "True")  trueDataConKey  trueDataCon 
163
164 listTyConName, nilDataConName, consDataConName :: Name
165 listTyConName     = mkWiredInTyConName   BuiltInSyntax gHC_TYPES (fsLit "[]") listTyConKey listTyCon
166 nilDataConName    = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit "[]") nilDataConKey nilDataCon 
167 consDataConName   = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit ":") consDataConKey consDataCon
168
169 floatTyConName, floatDataConName, doubleTyConName, doubleDataConName :: Name
170 floatTyConName     = mkWiredInTyConName   UserSyntax gHC_TYPES (fsLit "Float") floatTyConKey floatTyCon
171 floatDataConName   = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "F#") floatDataConKey floatDataCon
172 doubleTyConName    = mkWiredInTyConName   UserSyntax gHC_TYPES (fsLit "Double") doubleTyConKey doubleTyCon
173 doubleDataConName  = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "D#") doubleDataConKey doubleDataCon
174
175 parrTyConName, parrDataConName :: Name
176 parrTyConName     = mkWiredInTyConName   BuiltInSyntax gHC_PARR (fsLit "[::]") parrTyConKey parrTyCon 
177 parrDataConName   = mkWiredInDataConName UserSyntax    gHC_PARR (fsLit "PArr") parrDataConKey parrDataCon
178
179 boolTyCon_RDR, false_RDR, true_RDR, intTyCon_RDR, charTyCon_RDR,
180     intDataCon_RDR, listTyCon_RDR, consDataCon_RDR, parrTyCon_RDR:: RdrName
181 boolTyCon_RDR   = nameRdrName boolTyConName
182 false_RDR       = nameRdrName falseDataConName
183 true_RDR        = nameRdrName trueDataConName
184 intTyCon_RDR    = nameRdrName intTyConName
185 charTyCon_RDR   = nameRdrName charTyConName
186 intDataCon_RDR  = nameRdrName intDataConName
187 listTyCon_RDR   = nameRdrName listTyConName
188 consDataCon_RDR = nameRdrName consDataConName
189 parrTyCon_RDR   = nameRdrName parrTyConName
190 {-
191 tySuperKindTyCon_RDR     = nameRdrName tySuperKindTyConName
192 coSuperKindTyCon_RDR = nameRdrName coSuperKindTyConName
193 liftedTypeKindTyCon_RDR   = nameRdrName liftedTypeKindTyConName
194 openTypeKindTyCon_RDR     = nameRdrName openTypeKindTyConName
195 unliftedTypeKindTyCon_RDR = nameRdrName unliftedTypeKindTyConName
196 ubxTupleKindTyCon_RDR     = nameRdrName ubxTupleKindTyConName
197 argTypeKindTyCon_RDR      = nameRdrName argTypeKindTyConName
198 funKindTyCon_RDR          = nameRdrName funKindTyConName
199 -}
200 \end{code}
201
202
203 %************************************************************************
204 %*                                                                      *
205 \subsection{mkWiredInTyCon}
206 %*                                                                      *
207 %************************************************************************
208
209 \begin{code}
210 pcNonRecDataTyCon :: Name -> [TyVar] -> [DataCon] -> TyCon
211 pcNonRecDataTyCon = pcTyCon False NonRecursive
212 pcRecDataTyCon :: Name -> [TyVar] -> [DataCon] -> TyCon
213 pcRecDataTyCon    = pcTyCon False Recursive
214
215 pcTyCon :: Bool -> RecFlag -> Name -> [TyVar] -> [DataCon] -> TyCon
216 pcTyCon is_enum is_rec name tyvars cons
217   = tycon
218   where
219     tycon = mkAlgTyCon name
220                 (mkArrowKinds (map tyVarKind tyvars) liftedTypeKind)
221                 tyvars
222                 []              -- No stupid theta
223                 (DataTyCon cons is_enum)
224                 NoParentTyCon
225                 is_rec
226                 True            -- All the wired-in tycons have generics
227                 False           -- Not in GADT syntax
228
229 pcDataCon :: Name -> [TyVar] -> [Type] -> TyCon -> DataCon
230 pcDataCon = pcDataConWithFixity False
231
232 pcDataConWithFixity :: Bool -> Name -> [TyVar] -> [Type] -> TyCon -> DataCon
233 -- The Name should be in the DataName name space; it's the name
234 -- of the DataCon itself.
235 --
236 -- The unique is the first of two free uniques;
237 -- the first is used for the datacon itself,
238 -- the second is used for the "worker name"
239
240 pcDataConWithFixity declared_infix dc_name tyvars arg_tys tycon
241   = data_con
242   where
243     data_con = mkDataCon dc_name declared_infix
244                 (map (const NotMarkedStrict) arg_tys)
245                 []      -- No labelled fields
246                 tyvars
247                 []      -- No existential type variables
248                 []      -- No equality spec
249                 []      -- No theta
250                 arg_tys (mkTyConApp tycon (mkTyVarTys tyvars)) 
251                 tycon
252                 []      -- No stupid theta
253                 (mkDataConIds bogus_wrap_name wrk_name data_con)
254                 
255
256     modu     = ASSERT( isExternalName dc_name ) 
257                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