[project @ 2000-10-25 12:56:20 by simonpj]
[ghc-hetmet.git] / ghc / 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, genericTyCons,
15
16         addrDataCon,
17         addrTy,
18         addrTyCon,
19         boolTy,
20         boolTyCon,
21         charDataCon,
22         charTy,
23         charTyCon,
24         consDataCon,
25         doubleDataCon,
26         doubleTy,
27         isDoubleTy,
28         doubleTyCon,
29         falseDataCon, falseDataConId,
30         floatDataCon,
31         floatTy,
32         isFloatTy,
33         floatTyCon,
34
35         intDataCon,
36         intTy,
37         intTyCon,
38         isIntTy,
39
40         integerTy,
41         integerTyCon,
42         smallIntegerDataCon,
43         largeIntegerDataCon,
44         isIntegerTy,
45
46         listTyCon,
47
48         mkListTy,
49         nilDataCon,
50
51         -- tuples
52         mkTupleTy,
53         tupleTyCon, tupleCon, 
54         unitTyCon, unitDataConId, pairTyCon, 
55         unboxedSingletonTyCon, unboxedSingletonDataCon,
56         unboxedPairTyCon, unboxedPairDataCon,
57
58         -- Generics
59         genUnitTyCon, genUnitDataCon, 
60         plusTyCon, inrDataCon, inlDataCon,
61         crossTyCon, crossDataCon,
62
63         stablePtrTyCon,
64         stringTy,
65         trueDataCon, trueDataConId,
66         unitTy,
67         voidTy,
68         wordDataCon,
69         wordTy,
70         wordTyCon,
71
72         isFFIArgumentTy,    -- :: Bool -> Type -> Bool
73         isFFIResultTy,      -- :: Type -> Bool
74         isFFIExternalTy,    -- :: Type -> Bool
75         isFFIDynArgumentTy, -- :: Type -> Bool
76         isFFIDynResultTy,   -- :: Type -> Bool
77         isFFILabelTy,       -- :: Type -> Bool
78         isAddrTy,           -- :: Type -> Bool
79         isForeignObjTy      -- :: Type -> Bool
80
81     ) where
82
83 #include "HsVersions.h"
84
85 import {-# SOURCE #-} MkId( mkDataConId, mkDataConWrapId )
86 import {-# SOURCE #-} Generics( mkTyConGenInfo )
87
88 -- friends:
89 import PrelNames
90 import TysPrim
91
92 -- others:
93 import Constants        ( mAX_TUPLE_SIZE )
94 import Module           ( mkPrelModule )
95 import Name             ( Name, nameRdrName, nameUnique, nameOccName, 
96                           nameModule, mkWiredInName )
97 import OccName          ( mkOccFS, tcName, dataName, mkWorkerOcc, mkGenOcc1, mkGenOcc2 )
98 import RdrName          ( rdrNameOcc )
99 import DataCon          ( DataCon, StrictnessMark(..),  mkDataCon, dataConId )
100 import Var              ( TyVar, tyVarKind )
101 import TyCon            ( TyCon, AlgTyConFlavour(..), tyConDataCons,
102                           mkTupleTyCon, isUnLiftedTyCon, mkAlgTyConRep
103                         )
104
105 import BasicTypes       ( Arity, RecFlag(..), Boxity(..), isBoxed )
106
107 import Type             ( Type, mkTyConTy, mkTyConApp, mkTyVarTys, 
108                           mkArrowKinds, boxedTypeKind, unboxedTypeKind,
109                           splitTyConApp_maybe, repType,
110                           TauType, ClassContext )
111 import Unique           ( incrUnique, mkTupleTyConUnique, mkTupleDataConUnique )
112 import PrelNames
113 import CmdLineOpts
114 import Array
115
116 alpha_tyvar       = [alphaTyVar]
117 alpha_ty          = [alphaTy]
118 alpha_beta_tyvars = [alphaTyVar, betaTyVar]
119 \end{code}
120
121
122 %************************************************************************
123 %*                                                                      *
124 \subsection{Wired in type constructors}
125 %*                                                                      *
126 %************************************************************************
127
128 \begin{code}
129 wiredInTyCons :: [TyCon]
130 wiredInTyCons = data_tycons ++ tuple_tycons ++ unboxed_tuple_tycons
131
132 data_tycons = genericTyCons ++
133               [ addrTyCon
134               , boolTyCon
135               , charTyCon
136               , doubleTyCon
137               , floatTyCon
138               , intTyCon
139               , integerTyCon
140               , listTyCon
141               , wordTyCon
142               ]
143
144 genericTyCons :: [TyCon]
145 genericTyCons = [ plusTyCon, crossTyCon, genUnitTyCon ]
146
147
148 tuple_tycons = unitTyCon : [tupleTyCon Boxed i | i <- [2..37] ]
149 unboxed_tuple_tycons = [tupleTyCon Unboxed i | i <- [1..37] ]
150 \end{code}
151
152
153 %************************************************************************
154 %*                                                                      *
155 \subsection{mkWiredInTyCon}
156 %*                                                                      *
157 %************************************************************************
158
159 \begin{code}
160 pcNonRecDataTyCon = pcTyCon DataTyCon NonRecursive
161 pcRecDataTyCon = pcTyCon DataTyCon Recursive
162
163 pcTyCon new_or_data is_rec name tyvars argvrcs cons
164   = tycon
165   where
166     tycon = mkAlgTyConRep name kind
167                 tyvars
168                 []              -- No context
169                 argvrcs
170                 cons
171                 (length cons)
172                 []              -- No derivings
173                 new_or_data
174                 is_rec
175                 gen_info
176
177     mod      = nameModule name
178     kind     = mkArrowKinds (map tyVarKind tyvars) boxedTypeKind
179     gen_info = mk_tc_gen_info mod (nameUnique name) name tycon
180
181 pcDataCon :: Name -> [TyVar] -> ClassContext -> [TauType] -> TyCon -> DataCon
182 -- The unique is the first of two free uniques;
183 -- the first is used for the datacon itself and the worker;
184 -- the second is used for the wrapper.
185
186 pcDataCon name tyvars context arg_tys tycon
187   = data_con
188   where
189     data_con = mkDataCon name
190                 [ NotMarkedStrict | a <- arg_tys ]
191                 [ {- no labelled fields -} ]
192                 tyvars context [] [] arg_tys tycon work_id wrap_id
193
194     wrap_rdr  = nameRdrName name
195     wrap_occ  = rdrNameOcc wrap_rdr
196
197     mod       = nameModule name
198     wrap_id   = mkDataConWrapId data_con
199
200     work_occ  = mkWorkerOcc wrap_occ
201     work_key  = incrUnique (nameUnique name)
202     work_name = mkWiredInName mod work_occ work_key
203     work_id   = mkDataConId work_name data_con
204 \end{code}
205
206
207 %************************************************************************
208 %*                                                                      *
209 \subsection[TysWiredIn-tuples]{The tuple types}
210 %*                                                                      *
211 %************************************************************************
212
213 \begin{code}
214 tupleTyCon :: Boxity -> Arity -> TyCon
215 tupleTyCon boxity i | i > mAX_TUPLE_SIZE = fst (mk_tuple boxity i)      -- Build one specially
216 tupleTyCon Boxed   i = fst (boxedTupleArr   ! i)
217 tupleTyCon Unboxed i = fst (unboxedTupleArr ! i)
218
219 tupleCon :: Boxity -> Arity -> DataCon
220 tupleCon boxity i | i > mAX_TUPLE_SIZE = snd (mk_tuple boxity i)        -- Build one specially
221 tupleCon Boxed   i = snd (boxedTupleArr   ! i)
222 tupleCon Unboxed i = snd (unboxedTupleArr ! i)
223
224 boxedTupleArr, unboxedTupleArr :: Array Int (TyCon,DataCon)
225 boxedTupleArr   = array (0,mAX_TUPLE_SIZE) [(i,mk_tuple Boxed i)   | i <- [0..mAX_TUPLE_SIZE]]
226 unboxedTupleArr = array (0,mAX_TUPLE_SIZE) [(i,mk_tuple Unboxed i) | i <- [0..mAX_TUPLE_SIZE]]
227
228 mk_tuple :: Boxity -> Int -> (TyCon,DataCon)
229 mk_tuple boxity arity = (tycon, tuple_con)
230   where
231         tycon   = mkTupleTyCon tc_name tc_kind arity tyvars tuple_con boxity gen_info 
232         tc_name = mkWiredInName mod (mkOccFS tcName name_str) tc_uniq
233         tc_kind = mkArrowKinds (map tyVarKind tyvars) res_kind
234         res_kind | isBoxed boxity = boxedTypeKind
235                  | otherwise      = unboxedTypeKind
236
237         tyvars   | isBoxed boxity = take arity alphaTyVars
238                  | otherwise      = take arity openAlphaTyVars
239
240         tuple_con = pcDataCon name tyvars [] tyvar_tys tycon
241         tyvar_tys = mkTyVarTys tyvars
242         (mod_name, name_str) = mkTupNameStr boxity arity
243         name      = mkWiredInName mod (mkOccFS dataName name_str) dc_uniq
244         tc_uniq   = mkTupleTyConUnique   boxity arity
245         dc_uniq   = mkTupleDataConUnique boxity arity
246         mod       = mkPrelModule mod_name
247         gen_info  = mk_tc_gen_info mod tc_uniq tc_name tycon
248
249 mk_tc_gen_info mod tc_uniq tc_name tycon
250   = gen_info
251   where
252         tc_occ_name = nameOccName tc_name
253         occ_name1   = mkGenOcc1 tc_occ_name
254         occ_name2   = mkGenOcc2 tc_occ_name
255         fn1_key     = incrUnique tc_uniq
256         fn2_key     = incrUnique fn1_key
257         name1       = mkWiredInName  mod occ_name1 fn1_key
258         name2       = mkWiredInName  mod occ_name2 fn2_key
259         gen_info    = mkTyConGenInfo tycon name1 name2
260
261 unitTyCon     = tupleTyCon Boxed 0
262 unitDataConId = dataConId (head (tyConDataCons unitTyCon))
263
264 pairTyCon = tupleTyCon Boxed 2
265
266 unboxedSingletonTyCon   = tupleTyCon Unboxed 1
267 unboxedSingletonDataCon = tupleCon   Unboxed 1
268
269 unboxedPairTyCon   = tupleTyCon Unboxed 2
270 unboxedPairDataCon = tupleCon   Unboxed 2
271 \end{code}
272
273 %************************************************************************
274 %*                                                                      *
275 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
276 %*                                                                      *
277 %************************************************************************
278
279 \begin{code}
280 -- The Void type is represented as a data type with no constructors
281 -- It's a built in type (i.e. there's no way to define it in Haskell;
282 --      the nearest would be
283 --
284 --              data Void =             -- No constructors!
285 --
286 -- ) It's boxed; there is only one value of this
287 -- type, namely "void", whose semantics is just bottom.
288 --
289 -- Haskell 98 drops the definition of a Void type, so we just 'simulate'
290 -- voidTy using ().
291 voidTy = unitTy
292 \end{code}
293
294
295 \begin{code}
296 charTy = mkTyConTy charTyCon
297
298 charTyCon   = pcNonRecDataTyCon charTyConName [] [] [charDataCon]
299 charDataCon = pcDataCon charDataConName [] [] [charPrimTy] charTyCon
300
301 stringTy = mkListTy charTy -- convenience only
302 \end{code}
303
304 \begin{code}
305 intTy = mkTyConTy intTyCon 
306
307 intTyCon = pcNonRecDataTyCon intTyConName [] [] [intDataCon]
308 intDataCon = pcDataCon intDataConName [] [] [intPrimTy] intTyCon
309
310 isIntTy :: Type -> Bool
311 isIntTy = isTyCon intTyConKey
312 \end{code}
313
314 \begin{code}
315
316 wordTy = mkTyConTy wordTyCon
317
318 wordTyCon = pcNonRecDataTyCon wordTyConName [] [] [wordDataCon]
319 wordDataCon = pcDataCon wordDataConName [] [] [wordPrimTy] wordTyCon
320 \end{code}
321
322 \begin{code}
323 addrTy = mkTyConTy addrTyCon
324
325 addrTyCon = pcNonRecDataTyCon addrTyConName [] [] [addrDataCon]
326 addrDataCon = pcDataCon addrDataConName [] [] [addrPrimTy] addrTyCon
327
328 isAddrTy :: Type -> Bool
329 isAddrTy = isTyCon addrTyConKey
330 \end{code}
331
332 \begin{code}
333 floatTy = mkTyConTy floatTyCon
334
335 floatTyCon   = pcNonRecDataTyCon floatTyConName   [] [] [floatDataCon]
336 floatDataCon = pcDataCon         floatDataConName [] [] [floatPrimTy] floatTyCon
337
338 isFloatTy :: Type -> Bool
339 isFloatTy = isTyCon floatTyConKey
340 \end{code}
341
342 \begin{code}
343 doubleTy = mkTyConTy doubleTyCon
344
345 isDoubleTy :: Type -> Bool
346 isDoubleTy = isTyCon doubleTyConKey
347
348 doubleTyCon   = pcNonRecDataTyCon doubleTyConName     [] [] [doubleDataCon]
349 doubleDataCon = pcDataCon         doubleDataConName [] [] [doublePrimTy] doubleTyCon
350 \end{code}
351
352 \begin{code}
353 stablePtrTyCon
354   = pcNonRecDataTyCon stablePtrTyConName
355         alpha_tyvar [(True,False)] [stablePtrDataCon]
356   where
357     stablePtrDataCon
358       = pcDataCon stablePtrDataConName
359             alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon
360 \end{code}
361
362 \begin{code}
363 foreignObjTyCon
364   = pcNonRecDataTyCon foreignObjTyConName
365         [] [] [foreignObjDataCon]
366   where
367     foreignObjDataCon
368       = pcDataCon foreignObjDataConName
369             [] [] [foreignObjPrimTy] foreignObjTyCon
370
371 isForeignObjTy :: Type -> Bool
372 isForeignObjTy = isTyCon foreignObjTyConKey
373 \end{code}
374
375 %************************************************************************
376 %*                                                                      *
377 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
378 %*                                                                      *
379 %************************************************************************
380
381 @Integer@ and its pals are not really primitive.  @Integer@ itself, first:
382 \begin{code}
383 integerTy :: Type
384 integerTy = mkTyConTy integerTyCon
385
386 integerTyCon = pcNonRecDataTyCon integerTyConName
387                    [] [] [smallIntegerDataCon, largeIntegerDataCon]
388
389 smallIntegerDataCon = pcDataCon smallIntegerDataConName
390                 [] [] [intPrimTy] integerTyCon
391 largeIntegerDataCon = pcDataCon largeIntegerDataConName
392                 [] [] [intPrimTy, byteArrayPrimTy] integerTyCon
393
394
395 isIntegerTy :: Type -> Bool
396 isIntegerTy = isTyCon integerTyConKey
397 \end{code}
398
399
400 %************************************************************************
401 %*                                                                      *
402 \subsection[TysWiredIn-ext-type]{External types}
403 %*                                                                      *
404 %************************************************************************
405
406 The compiler's foreign function interface supports the passing of a
407 restricted set of types as arguments and results (the restricting factor
408 being the )
409
410 \begin{code}
411 isFFIArgumentTy :: DynFlags -> Bool -> Type -> Bool
412 -- Checks for valid argument type for a 'foreign import'
413 isFFIArgumentTy dflags is_safe ty 
414    = checkRepTyCon (legalOutgoingTyCon dflags is_safe) ty
415
416 isFFIExternalTy :: Type -> Bool
417 -- Types that are allowed as arguments of a 'foreign export'
418 isFFIExternalTy ty = checkRepTyCon legalIncomingTyCon ty
419
420 isFFIResultTy :: Type -> Bool
421 -- Types that are allowed as a result of a 'foreign import' or of a 'foreign export'
422 -- Maybe we should distinguish between import and export, but 
423 -- here we just choose the more restrictive 'incoming' predicate
424 -- But we allow () as well
425 isFFIResultTy ty = checkRepTyCon (\tc -> tc == unitTyCon || legalIncomingTyCon tc) ty
426
427 isFFIDynArgumentTy :: Type -> Bool
428 -- The argument type of a foreign import dynamic must be either Addr, or
429 -- a newtype of Addr.
430 isFFIDynArgumentTy = checkRepTyCon (== addrTyCon)
431
432 isFFIDynResultTy :: Type -> Bool
433 -- The result type of a foreign export dynamic must be either Addr, or
434 -- a newtype of Addr.
435 isFFIDynResultTy = checkRepTyCon (== addrTyCon)
436
437 isFFILabelTy :: Type -> Bool
438 -- The type of a foreign label must be either Addr, or
439 -- a newtype of Addr.
440 isFFILabelTy = checkRepTyCon (== addrTyCon)
441
442 checkRepTyCon :: (TyCon -> Bool) -> Type -> Bool
443         -- look through newtypes
444 checkRepTyCon check_tc ty = checkTyCon check_tc (repType ty)
445
446 checkTyCon :: (TyCon -> Bool) -> Type -> Bool
447 checkTyCon check_tc ty = case splitTyConApp_maybe ty of
448                                 Just (tycon, _) -> check_tc tycon
449                                 Nothing         -> False
450
451 isTyCon :: Unique -> Type -> Bool
452 isTyCon uniq ty = checkTyCon (\tc -> uniq == getUnique tc) ty
453 \end{code}
454
455 ----------------------------------------------
456 These chaps do the work; they are not exported
457 ----------------------------------------------
458
459 \begin{code}
460 legalIncomingTyCon :: TyCon -> Bool
461 -- It's illegal to return foreign objects and (mutable)
462 -- bytearrays from a _ccall_ / foreign declaration
463 -- (or be passed them as arguments in foreign exported functions).
464 legalIncomingTyCon tc
465   | getUnique tc `elem` [ foreignObjTyConKey, byteArrayTyConKey, 
466                                               mutableByteArrayTyConKey ] 
467   = False
468   -- It's also illegal to make foreign exports that take unboxed
469   -- arguments.  The RTS API currently can't invoke such things.  --SDM 7/2000
470   | otherwise
471   = boxedMarshalableTyCon tc
472
473 legalOutgoingTyCon :: DynFlags -> Bool -> TyCon -> Bool
474 -- Checks validity of types going from Haskell -> external world
475 -- The boolean is true for a 'safe' call (when we don't want to
476 -- pass Haskell pointers to the world)
477 legalOutgoingTyCon dflags be_safe tc
478   | be_safe && getUnique tc `elem` [byteArrayTyConKey, mutableByteArrayTyConKey]
479   = False
480   | otherwise
481   = marshalableTyCon dflags tc
482
483 marshalableTyCon dflags tc
484   =  (dopt Opt_GlasgowExts dflags && isUnLiftedTyCon tc)
485   || boxedMarshalableTyCon tc
486
487 boxedMarshalableTyCon tc
488    = getUnique tc `elem` [ intTyConKey, int8TyConKey, int16TyConKey, int32TyConKey, int64TyConKey
489                          , wordTyConKey, word8TyConKey, word16TyConKey, word32TyConKey, word64TyConKey
490                          , floatTyConKey, doubleTyConKey
491                          , addrTyConKey, charTyConKey, foreignObjTyConKey
492                          , stablePtrTyConKey
493                          , byteArrayTyConKey, mutableByteArrayTyConKey
494                          , boolTyConKey
495                          ]
496 \end{code}
497
498
499 %************************************************************************
500 %*                                                                      *
501 \subsection[TysWiredIn-Bool]{The @Bool@ type}
502 %*                                                                      *
503 %************************************************************************
504
505 An ordinary enumeration type, but deeply wired in.  There are no
506 magical operations on @Bool@ (just the regular Prelude code).
507
508 {\em BEGIN IDLE SPECULATION BY SIMON}
509
510 This is not the only way to encode @Bool@.  A more obvious coding makes
511 @Bool@ just a boxed up version of @Bool#@, like this:
512 \begin{verbatim}
513 type Bool# = Int#
514 data Bool = MkBool Bool#
515 \end{verbatim}
516
517 Unfortunately, this doesn't correspond to what the Report says @Bool@
518 looks like!  Furthermore, we get slightly less efficient code (I
519 think) with this coding. @gtInt@ would look like this:
520
521 \begin{verbatim}
522 gtInt :: Int -> Int -> Bool
523 gtInt x y = case x of I# x# ->
524             case y of I# y# ->
525             case (gtIntPrim x# y#) of
526                 b# -> MkBool b#
527 \end{verbatim}
528
529 Notice that the result of the @gtIntPrim@ comparison has to be turned
530 into an integer (here called @b#@), and returned in a @MkBool@ box.
531
532 The @if@ expression would compile to this:
533 \begin{verbatim}
534 case (gtInt x y) of
535   MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
536 \end{verbatim}
537
538 I think this code is a little less efficient than the previous code,
539 but I'm not certain.  At all events, corresponding with the Report is
540 important.  The interesting thing is that the language is expressive
541 enough to describe more than one alternative; and that a type doesn't
542 necessarily need to be a straightforwardly boxed version of its
543 primitive counterpart.
544
545 {\em END IDLE SPECULATION BY SIMON}
546
547 \begin{code}
548 boolTy = mkTyConTy boolTyCon
549
550 boolTyCon = pcTyCon EnumTyCon NonRecursive boolTyConName
551                     [] [] [falseDataCon, trueDataCon]
552
553 falseDataCon = pcDataCon falseDataConName [] [] [] boolTyCon
554 trueDataCon  = pcDataCon trueDataConName  [] [] [] boolTyCon
555
556 falseDataConId = dataConId falseDataCon
557 trueDataConId  = dataConId trueDataCon
558 \end{code}
559
560 %************************************************************************
561 %*                                                                      *
562 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
563 %*                                                                      *
564 %************************************************************************
565
566 Special syntax, deeply wired in, but otherwise an ordinary algebraic
567 data types:
568 \begin{verbatim}
569 data [] a = [] | a : (List a)
570 data () = ()
571 data (,) a b = (,,) a b
572 ...
573 \end{verbatim}
574
575 \begin{code}
576 mkListTy :: Type -> Type
577 mkListTy ty = mkTyConApp listTyCon [ty]
578
579 listTyCon = pcRecDataTyCon listTyConName
580                         alpha_tyvar [(True,False)] [nilDataCon, consDataCon]
581
582 nilDataCon  = pcDataCon nilDataConName alpha_tyvar [] [] listTyCon
583 consDataCon = pcDataCon consDataConName
584                alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
585 -- Interesting: polymorphic recursion would help here.
586 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
587 -- gets the over-specific type (Type -> Type)
588 \end{code}
589
590 %************************************************************************
591 %*                                                                      *
592 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
593 %*                                                                      *
594 %************************************************************************
595
596 The tuple types are definitely magic, because they form an infinite
597 family.
598
599 \begin{itemize}
600 \item
601 They have a special family of type constructors, of type @TyCon@
602 These contain the tycon arity, but don't require a Unique.
603
604 \item
605 They have a special family of constructors, of type
606 @Id@. Again these contain their arity but don't need a Unique.
607
608 \item
609 There should be a magic way of generating the info tables and
610 entry code for all tuples.
611
612 But at the moment we just compile a Haskell source
613 file\srcloc{lib/prelude/...} containing declarations like:
614 \begin{verbatim}
615 data Tuple0             = Tup0
616 data Tuple2  a b        = Tup2  a b
617 data Tuple3  a b c      = Tup3  a b c
618 data Tuple4  a b c d    = Tup4  a b c d
619 ...
620 \end{verbatim}
621 The print-names associated with the magic @Id@s for tuple constructors
622 ``just happen'' to be the same as those generated by these
623 declarations.
624
625 \item
626 The instance environment should have a magic way to know
627 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
628 so on. \ToDo{Not implemented yet.}
629
630 \item
631 There should also be a way to generate the appropriate code for each
632 of these instances, but (like the info tables and entry code) it is
633 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
634 \end{itemize}
635
636 \begin{code}
637 mkTupleTy :: Boxity -> Int -> [Type] -> Type
638 mkTupleTy boxity arity tys = mkTyConApp (tupleTyCon boxity arity) tys
639
640 unitTy    = mkTupleTy Boxed 0 []
641 \end{code}
642
643 %************************************************************************
644 %*                                                                      *
645 \subsection{Wired In Type Constructors for Representation Types}
646 %*                                                                      *
647 %************************************************************************
648
649 The following code defines the wired in datatypes cross, plus, unit
650 and c_of needed for the generic methods.
651
652 Ok, so the basic story is that for each type constructor I need to
653 create 2 things - a TyCon and a DataCon and then we are basically
654 ok. There are going to be no arguments passed to these functions
655 because -well- there is nothing to pass to these functions.
656
657 \begin{code}
658 crossTyCon :: TyCon
659 crossTyCon = pcNonRecDataTyCon crossTyConName alpha_beta_tyvars [] [crossDataCon]
660
661 crossDataCon :: DataCon
662 crossDataCon = pcDataCon crossDataConName alpha_beta_tyvars [] [alphaTy, betaTy] crossTyCon
663
664 plusTyCon :: TyCon
665 plusTyCon = pcNonRecDataTyCon plusTyConName alpha_beta_tyvars [] [inlDataCon, inrDataCon]
666
667 inlDataCon, inrDataCon :: DataCon
668 inlDataCon = pcDataCon inlDataConName alpha_beta_tyvars [] [alphaTy] plusTyCon
669 inrDataCon = pcDataCon inrDataConName alpha_beta_tyvars [] [betaTy]  plusTyCon
670
671 genUnitTyCon :: TyCon   -- The "1" type constructor for generics
672 genUnitTyCon = pcNonRecDataTyCon genUnitTyConName [] [] [genUnitDataCon]
673
674 genUnitDataCon :: DataCon
675 genUnitDataCon = pcDataCon genUnitDataConName [] [] [] genUnitTyCon
676 \end{code}
677
678
679
680
681