2 % (c) The GRASP Project, Glasgow University, 1994-1995
4 \section[TysWiredIn]{Wired-in knowledge about {\em non-primitive} types}
6 This module is about types that can be defined in Haskell, but which
7 must be wired into the compiler nonetheless.
9 This module tracks the ``state interface'' document, ``GHC prelude:
10 types and operations.''
32 getStatePairingConInfo,
53 tupleTyCon, tupleCon, unitTyCon, unitDataCon, pairTyCon, pairDataCon,
69 stateAndAddrPrimTyCon,
70 stateAndArrayPrimTyCon,
71 stateAndByteArrayPrimTyCon,
72 stateAndCharPrimTyCon,
73 stateAndDoublePrimTyCon,
74 stateAndFloatPrimTyCon,
76 stateAndForeignObjPrimTyCon,
77 stateAndMutableArrayPrimTyCon,
78 stateAndMutableByteArrayPrimTyCon,
80 stateAndStablePtrPrimTyCon,
81 stateAndSynchVarPrimTyCon,
82 stateAndWordPrimTyCon,
95 #include "HsVersions.h"
97 import {-# SOURCE #-} MkId ( mkDataCon, mkTupleCon )
98 import {-# SOURCE #-} Id ( Id, StrictnessMark(..) )
105 import Kind ( mkBoxedTypeKind, mkArrowKind )
106 import Name ( mkWiredInTyConName, mkWiredInIdName )
107 import TyCon ( mkDataTyCon, mkTupleTyCon, mkSynTyCon,
110 import BasicTypes ( Module, NewOrData(..), RecFlag(..) )
111 import Type ( Type, mkTyConTy, mkTyConApp, mkSigmaTy, mkTyVarTys,
112 mkFunTy, mkFunTys, splitTyConApp_maybe, splitAlgTyConApp_maybe,
113 GenType(..), ThetaType, TauType )
114 import TyVar ( GenTyVar, TyVar, tyVarKind, alphaTyVars, alphaTyVar, betaTyVar )
115 import Lex ( mkTupNameStr )
117 import Util ( assoc, panic )
119 alpha_tyvar = [alphaTyVar]
121 alpha_beta_tyvars = [alphaTyVar, betaTyVar]
123 pcRecDataTyCon, pcNonRecDataTyCon, pcNonRecNewTyCon
124 :: Unique{-TyConKey-} -> Module -> FAST_STRING
125 -> [TyVar] -> [Id] -> TyCon
127 pcRecDataTyCon = pc_tycon DataType Recursive
128 pcNonRecDataTyCon = pc_tycon DataType NonRecursive
129 pcNonRecNewTyCon = pc_tycon NewType NonRecursive
131 pc_tycon new_or_data is_rec key mod str tyvars cons
134 tycon = mkDataTyCon name tycon_kind
139 Nothing -- Not a dictionary
143 name = mkWiredInTyConName key mod str tycon
144 tycon_kind = foldr (mkArrowKind . tyVarKind) mkBoxedTypeKind tyvars
146 pcSynTyCon key mod str kind arity tyvars expansion
149 tycon = mkSynTyCon name kind arity tyvars expansion
150 name = mkWiredInTyConName key mod str tycon
152 pcDataCon :: Unique{-DataConKey-} -> Module -> FAST_STRING
153 -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> Id
154 pcDataCon key mod str tyvars context arg_tys tycon
157 data_con = mkDataCon name
158 [ NotMarkedStrict | a <- arg_tys ]
159 [ {- no labelled fields -} ]
160 tyvars context [] [] arg_tys tycon
161 name = mkWiredInIdName key mod str data_con
164 %************************************************************************
166 \subsection[TysWiredIn-tuples]{The tuple types}
168 %************************************************************************
171 tupleTyCon :: Arity -> TyCon
175 tycon = mkTupleTyCon uniq name arity
176 uniq = mkTupleTyConUnique arity
177 name = mkWiredInTyConName uniq mod_name (mkTupNameStr arity) tycon
178 mod_name | arity == 0 = pREL_BASE
179 | otherwise = pREL_TUP
181 tupleCon :: Arity -> Id
185 tuple_con = mkTupleCon arity name ty
186 uniq = mkTupleDataConUnique arity
187 name = mkWiredInIdName uniq mod_name (mkTupNameStr arity) tuple_con
188 mod_name | arity == 0 = pREL_BASE
189 | otherwise = pREL_TUP
190 ty = mkSigmaTy tyvars [] (mkFunTys tyvar_tys (mkTyConApp tycon tyvar_tys))
191 tyvars = take arity alphaTyVars
192 tyvar_tys = mkTyVarTys tyvars
193 tycon = tupleTyCon arity
195 unitTyCon = tupleTyCon 0
196 pairTyCon = tupleTyCon 2
198 unitDataCon = tupleCon 0
199 pairDataCon = tupleCon 2
203 %************************************************************************
205 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
207 %************************************************************************
210 charTy = mkTyConTy charTyCon
212 charTyCon = pcNonRecDataTyCon charTyConKey pREL_BASE SLIT("Char") [] [charDataCon]
213 charDataCon = pcDataCon charDataConKey pREL_BASE SLIT("C#") [] [] [charPrimTy] charTyCon
215 stringTy = mkListTy charTy -- convenience only
219 intTy = mkTyConTy intTyCon
221 intTyCon = pcNonRecDataTyCon intTyConKey pREL_BASE SLIT("Int") [] [intDataCon]
222 intDataCon = pcDataCon intDataConKey pREL_BASE SLIT("I#") [] [] [intPrimTy] intTyCon
224 isIntTy :: GenType flexi -> Bool
226 = case (splitAlgTyConApp_maybe ty) of
227 Just (tycon, [], _) -> uniqueOf tycon == intTyConKey
230 inIntRange :: Integer -> Bool -- Tells if an integer lies in the legal range of Ints
231 inIntRange i = (min_int <= i) && (i <= max_int)
233 max_int, min_int :: Integer
234 max_int = toInteger maxInt
235 min_int = toInteger minInt
239 wordTy = mkTyConTy wordTyCon
241 wordTyCon = pcNonRecDataTyCon wordTyConKey pREL_FOREIGN SLIT("Word") [] [wordDataCon]
242 wordDataCon = pcDataCon wordDataConKey pREL_FOREIGN SLIT("W#") [] [] [wordPrimTy] wordTyCon
246 addrTy = mkTyConTy addrTyCon
248 addrTyCon = pcNonRecDataTyCon addrTyConKey pREL_ADDR SLIT("Addr") [] [addrDataCon]
249 addrDataCon = pcDataCon addrDataConKey pREL_ADDR SLIT("A#") [] [] [addrPrimTy] addrTyCon
253 floatTy = mkTyConTy floatTyCon
255 floatTyCon = pcNonRecDataTyCon floatTyConKey pREL_BASE SLIT("Float") [] [floatDataCon]
256 floatDataCon = pcDataCon floatDataConKey pREL_BASE SLIT("F#") [] [] [floatPrimTy] floatTyCon
258 isFloatTy :: GenType flexi -> Bool
260 = case (splitAlgTyConApp_maybe ty) of
261 Just (tycon, [], _) -> uniqueOf tycon == floatTyConKey
267 doubleTy = mkTyConTy doubleTyCon
269 isDoubleTy :: GenType flexi -> Bool
271 = case (splitAlgTyConApp_maybe ty) of
272 Just (tycon, [], _) -> uniqueOf tycon == doubleTyConKey
275 doubleTyCon = pcNonRecDataTyCon doubleTyConKey pREL_BASE SLIT("Double") [] [doubleDataCon]
276 doubleDataCon = pcDataCon doubleDataConKey pREL_BASE SLIT("D#") [] [] [doublePrimTy] doubleTyCon
280 mkStateTy ty = mkTyConApp stateTyCon [ty]
281 realWorldStateTy = mkStateTy realWorldTy -- a common use
283 stateTyCon = pcNonRecDataTyCon stateTyConKey pREL_ST SLIT("State") alpha_tyvar [stateDataCon]
285 = pcDataCon stateDataConKey pREL_ST SLIT("S#")
286 alpha_tyvar [] [mkStatePrimTy alphaTy] stateTyCon
291 = pcNonRecDataTyCon stablePtrTyConKey pREL_FOREIGN SLIT("StablePtr")
292 alpha_tyvar [stablePtrDataCon]
295 = pcDataCon stablePtrDataConKey pREL_FOREIGN SLIT("StablePtr")
296 alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon
301 = pcNonRecDataTyCon foreignObjTyConKey pREL_FOREIGN SLIT("ForeignObj")
302 [] [foreignObjDataCon]
305 = pcDataCon foreignObjDataConKey pREL_FOREIGN SLIT("ForeignObj")
306 [] [] [foreignObjPrimTy] foreignObjTyCon
309 %************************************************************************
311 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
313 %************************************************************************
315 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
317 integerTy :: GenType t
318 integerTy = mkTyConTy integerTyCon
320 integerTyCon = pcNonRecDataTyCon integerTyConKey pREL_BASE SLIT("Integer") [] [integerDataCon]
322 integerDataCon = pcDataCon integerDataConKey pREL_BASE SLIT("J#")
323 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon
325 isIntegerTy :: GenType flexi -> Bool
327 = case (splitAlgTyConApp_maybe ty) of
328 Just (tycon, [], _) -> uniqueOf tycon == integerTyConKey
332 And the other pairing types:
334 return2GMPsTyCon = pcNonRecDataTyCon return2GMPsTyConKey
335 pREL_NUM SLIT("Return2GMPs") [] [return2GMPsDataCon]
338 = pcDataCon return2GMPsDataConKey pREL_NUM SLIT("Return2GMPs") [] []
339 [intPrimTy, intPrimTy, byteArrayPrimTy,
340 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon
342 returnIntAndGMPTyCon = pcNonRecDataTyCon returnIntAndGMPTyConKey
343 pREL_NUM SLIT("ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
345 returnIntAndGMPDataCon
346 = pcDataCon returnIntAndGMPDataConKey pREL_NUM SLIT("ReturnIntAndGMP") [] []
347 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon
350 %************************************************************************
352 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
354 %************************************************************************
356 These boring types pair a \tr{State#} with another primitive type.
357 They are not really primitive, so they are given here, not in
360 We fish one of these \tr{StateAnd<blah>#} things with
361 @getStatePairingConInfo@ (given a little way down).
365 = pcNonRecDataTyCon stateAndPtrPrimTyConKey pREL_ST SLIT("StateAndPtr#")
366 alpha_beta_tyvars [stateAndPtrPrimDataCon]
367 stateAndPtrPrimDataCon
368 = pcDataCon stateAndPtrPrimDataConKey pREL_ST SLIT("StateAndPtr#")
369 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
372 stateAndCharPrimTyCon
373 = pcNonRecDataTyCon stateAndCharPrimTyConKey pREL_ST SLIT("StateAndChar#")
374 alpha_tyvar [stateAndCharPrimDataCon]
375 stateAndCharPrimDataCon
376 = pcDataCon stateAndCharPrimDataConKey pREL_ST SLIT("StateAndChar#")
377 alpha_tyvar [] [mkStatePrimTy alphaTy, charPrimTy]
378 stateAndCharPrimTyCon
381 = pcNonRecDataTyCon stateAndIntPrimTyConKey pREL_ST SLIT("StateAndInt#")
382 alpha_tyvar [stateAndIntPrimDataCon]
383 stateAndIntPrimDataCon
384 = pcDataCon stateAndIntPrimDataConKey pREL_ST SLIT("StateAndInt#")
385 alpha_tyvar [] [mkStatePrimTy alphaTy, intPrimTy]
388 stateAndWordPrimTyCon
389 = pcNonRecDataTyCon stateAndWordPrimTyConKey pREL_ST SLIT("StateAndWord#")
390 alpha_tyvar [stateAndWordPrimDataCon]
391 stateAndWordPrimDataCon
392 = pcDataCon stateAndWordPrimDataConKey pREL_ST SLIT("StateAndWord#")
393 alpha_tyvar [] [mkStatePrimTy alphaTy, wordPrimTy]
394 stateAndWordPrimTyCon
396 stateAndAddrPrimTyCon
397 = pcNonRecDataTyCon stateAndAddrPrimTyConKey pREL_ST SLIT("StateAndAddr#")
398 alpha_tyvar [stateAndAddrPrimDataCon]
399 stateAndAddrPrimDataCon
400 = pcDataCon stateAndAddrPrimDataConKey pREL_ST SLIT("StateAndAddr#")
401 alpha_tyvar [] [mkStatePrimTy alphaTy, addrPrimTy]
402 stateAndAddrPrimTyCon
404 stateAndStablePtrPrimTyCon
405 = pcNonRecDataTyCon stateAndStablePtrPrimTyConKey pREL_FOREIGN SLIT("StateAndStablePtr#")
406 alpha_beta_tyvars [stateAndStablePtrPrimDataCon]
407 stateAndStablePtrPrimDataCon
408 = pcDataCon stateAndStablePtrPrimDataConKey pREL_FOREIGN SLIT("StateAndStablePtr#")
410 [mkStatePrimTy alphaTy, mkTyConApp stablePtrPrimTyCon [betaTy]]
411 stateAndStablePtrPrimTyCon
413 stateAndForeignObjPrimTyCon
414 = pcNonRecDataTyCon stateAndForeignObjPrimTyConKey pREL_FOREIGN SLIT("StateAndForeignObj#")
415 alpha_tyvar [stateAndForeignObjPrimDataCon]
416 stateAndForeignObjPrimDataCon
417 = pcDataCon stateAndForeignObjPrimDataConKey pREL_FOREIGN SLIT("StateAndForeignObj#")
419 [mkStatePrimTy alphaTy, mkTyConTy foreignObjPrimTyCon]
420 stateAndForeignObjPrimTyCon
422 stateAndFloatPrimTyCon
423 = pcNonRecDataTyCon stateAndFloatPrimTyConKey pREL_ST SLIT("StateAndFloat#")
424 alpha_tyvar [stateAndFloatPrimDataCon]
425 stateAndFloatPrimDataCon
426 = pcDataCon stateAndFloatPrimDataConKey pREL_ST SLIT("StateAndFloat#")
427 alpha_tyvar [] [mkStatePrimTy alphaTy, floatPrimTy]
428 stateAndFloatPrimTyCon
430 stateAndDoublePrimTyCon
431 = pcNonRecDataTyCon stateAndDoublePrimTyConKey pREL_ST SLIT("StateAndDouble#")
432 alpha_tyvar [stateAndDoublePrimDataCon]
433 stateAndDoublePrimDataCon
434 = pcDataCon stateAndDoublePrimDataConKey pREL_ST SLIT("StateAndDouble#")
435 alpha_tyvar [] [mkStatePrimTy alphaTy, doublePrimTy]
436 stateAndDoublePrimTyCon
440 stateAndArrayPrimTyCon
441 = pcNonRecDataTyCon stateAndArrayPrimTyConKey pREL_ARR SLIT("StateAndArray#")
442 alpha_beta_tyvars [stateAndArrayPrimDataCon]
443 stateAndArrayPrimDataCon
444 = pcDataCon stateAndArrayPrimDataConKey pREL_ARR SLIT("StateAndArray#")
445 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
446 stateAndArrayPrimTyCon
448 stateAndMutableArrayPrimTyCon
449 = pcNonRecDataTyCon stateAndMutableArrayPrimTyConKey pREL_ARR SLIT("StateAndMutableArray#")
450 alpha_beta_tyvars [stateAndMutableArrayPrimDataCon]
451 stateAndMutableArrayPrimDataCon
452 = pcDataCon stateAndMutableArrayPrimDataConKey pREL_ARR SLIT("StateAndMutableArray#")
453 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
454 stateAndMutableArrayPrimTyCon
456 stateAndByteArrayPrimTyCon
457 = pcNonRecDataTyCon stateAndByteArrayPrimTyConKey pREL_ARR SLIT("StateAndByteArray#")
458 alpha_tyvar [stateAndByteArrayPrimDataCon]
459 stateAndByteArrayPrimDataCon
460 = pcDataCon stateAndByteArrayPrimDataConKey pREL_ARR SLIT("StateAndByteArray#")
461 alpha_tyvar [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
462 stateAndByteArrayPrimTyCon
464 stateAndMutableByteArrayPrimTyCon
465 = pcNonRecDataTyCon stateAndMutableByteArrayPrimTyConKey pREL_ARR SLIT("StateAndMutableByteArray#")
466 alpha_tyvar [stateAndMutableByteArrayPrimDataCon]
467 stateAndMutableByteArrayPrimDataCon
468 = pcDataCon stateAndMutableByteArrayPrimDataConKey pREL_ARR SLIT("StateAndMutableByteArray#")
469 alpha_tyvar [] [mkStatePrimTy alphaTy, mkTyConApp mutableByteArrayPrimTyCon alpha_ty]
470 stateAndMutableByteArrayPrimTyCon
472 stateAndSynchVarPrimTyCon
473 = pcNonRecDataTyCon stateAndSynchVarPrimTyConKey pREL_CONC SLIT("StateAndSynchVar#")
474 alpha_beta_tyvars [stateAndSynchVarPrimDataCon]
475 stateAndSynchVarPrimDataCon
476 = pcDataCon stateAndSynchVarPrimDataConKey pREL_CONC SLIT("StateAndSynchVar#")
477 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
478 stateAndSynchVarPrimTyCon
481 The ccall-desugaring mechanism uses this function to figure out how to
482 rebox the result. It's really a HACK, especially the part about
483 how many types to drop from \tr{tys_applied}.
486 getStatePairingConInfo
487 :: Type -- primitive type
488 -> (Id, -- state pair constructor for prim type
489 Type) -- type of state pair
491 getStatePairingConInfo prim_ty
492 = case (splitTyConApp_maybe prim_ty) of
493 Nothing -> panic "getStatePairingConInfo:1"
494 Just (prim_tycon, tys_applied) ->
496 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
497 pair_ty = mkTyConApp pair_tycon (realWorldTy : drop num_tys tys_applied)
502 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
503 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
504 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
505 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
506 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
507 (foreignObjPrimTyCon, (stateAndForeignObjPrimDataCon, stateAndForeignObjPrimTyCon, 0)),
508 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
509 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
510 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
511 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
512 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
513 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
514 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
515 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
519 %************************************************************************
521 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
523 %************************************************************************
525 The only reason this is wired in is because we have to represent the
529 mkStateTransformerTy s a = mkTyConApp stTyCon [s, a]
531 stTyCon = pcNonRecNewTyCon stTyConKey pREL_ST SLIT("ST") alpha_beta_tyvars [stDataCon]
533 stDataCon = pcDataCon stDataConKey pREL_ST SLIT("ST")
534 alpha_beta_tyvars [] [ty] stTyCon
536 ty = mkFunTy (mkStatePrimTy alphaTy) (mkSTretTy alphaTy betaTy)
538 mkSTretTy alpha beta = mkTyConApp stRetTyCon [alpha,beta]
541 = pcNonRecDataTyCon stRetTyConKey pREL_ST SLIT("STret")
542 alpha_beta_tyvars [stRetDataCon]
544 = pcDataCon stRetDataConKey pREL_ST SLIT("STret")
545 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
549 %************************************************************************
551 \subsection[TysWiredIn-Bool]{The @Bool@ type}
553 %************************************************************************
555 An ordinary enumeration type, but deeply wired in. There are no
556 magical operations on @Bool@ (just the regular Prelude code).
558 {\em BEGIN IDLE SPECULATION BY SIMON}
560 This is not the only way to encode @Bool@. A more obvious coding makes
561 @Bool@ just a boxed up version of @Bool#@, like this:
564 data Bool = MkBool Bool#
567 Unfortunately, this doesn't correspond to what the Report says @Bool@
568 looks like! Furthermore, we get slightly less efficient code (I
569 think) with this coding. @gtInt@ would look like this:
572 gtInt :: Int -> Int -> Bool
573 gtInt x y = case x of I# x# ->
575 case (gtIntPrim x# y#) of
579 Notice that the result of the @gtIntPrim@ comparison has to be turned
580 into an integer (here called @b#@), and returned in a @MkBool@ box.
582 The @if@ expression would compile to this:
585 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
588 I think this code is a little less efficient than the previous code,
589 but I'm not certain. At all events, corresponding with the Report is
590 important. The interesting thing is that the language is expressive
591 enough to describe more than one alternative; and that a type doesn't
592 necessarily need to be a straightforwardly boxed version of its
593 primitive counterpart.
595 {\em END IDLE SPECULATION BY SIMON}
598 boolTy = mkTyConTy boolTyCon
600 boolTyCon = pcNonRecDataTyCon boolTyConKey pREL_BASE SLIT("Bool") [] [falseDataCon, trueDataCon]
602 falseDataCon = pcDataCon falseDataConKey pREL_BASE SLIT("False") [] [] [] boolTyCon
603 trueDataCon = pcDataCon trueDataConKey pREL_BASE SLIT("True") [] [] [] boolTyCon
606 %************************************************************************
608 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
610 %************************************************************************
612 Special syntax, deeply wired in, but otherwise an ordinary algebraic
615 data [] a = [] | a : (List a)
617 data (,) a b = (,,) a b
622 mkListTy :: GenType t -> GenType t
623 mkListTy ty = mkTyConApp listTyCon [ty]
625 alphaListTy = mkSigmaTy alpha_tyvar [] (mkTyConApp listTyCon alpha_ty)
627 listTyCon = pcRecDataTyCon listTyConKey pREL_BASE SLIT("[]")
628 alpha_tyvar [nilDataCon, consDataCon]
630 nilDataCon = pcDataCon nilDataConKey pREL_BASE SLIT("[]") alpha_tyvar [] [] listTyCon
631 consDataCon = pcDataCon consDataConKey pREL_BASE SLIT(":")
632 alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
633 -- Interesting: polymorphic recursion would help here.
634 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
635 -- gets the over-specific type (Type -> Type)
638 %************************************************************************
640 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
642 %************************************************************************
644 The tuple types are definitely magic, because they form an infinite
649 They have a special family of type constructors, of type @TyCon@
650 These contain the tycon arity, but don't require a Unique.
653 They have a special family of constructors, of type
654 @Id@. Again these contain their arity but don't need a Unique.
657 There should be a magic way of generating the info tables and
658 entry code for all tuples.
660 But at the moment we just compile a Haskell source
661 file\srcloc{lib/prelude/...} containing declarations like:
664 data Tuple2 a b = Tup2 a b
665 data Tuple3 a b c = Tup3 a b c
666 data Tuple4 a b c d = Tup4 a b c d
669 The print-names associated with the magic @Id@s for tuple constructors
670 ``just happen'' to be the same as those generated by these
674 The instance environment should have a magic way to know
675 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
676 so on. \ToDo{Not implemented yet.}
679 There should also be a way to generate the appropriate code for each
680 of these instances, but (like the info tables and entry code) it is
681 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
685 mkTupleTy :: Int -> [GenType t] -> GenType t
687 mkTupleTy arity tys = mkTyConApp (tupleTyCon arity) tys
689 unitTy = mkTupleTy 0 []
692 %************************************************************************
694 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
696 %************************************************************************
698 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
701 mkLiftTy ty = mkTyConApp liftTyCon [ty]
705 = mkSigmaTy tvs theta (mkTyConApp liftTyCon [tau])
707 (tvs, theta, tau) = splitSigmaTy ty
710 = case (splitAlgTyConApp_maybeExpandingDicts tau) of
711 Just (tycon, tys, _) -> tycon == liftTyCon
714 (tvs, theta, tau) = splitSigmaTy ty
718 alphaLiftTy = mkSigmaTy alpha_tyvar [] (mkTyConApp liftTyCon alpha_ty)
721 = pcNonRecDataTyCon liftTyConKey pREL_BASE SLIT("Lift") alpha_tyvar [liftDataCon]
724 = pcDataCon liftDataConKey pREL_BASE SLIT("Lift")
725 alpha_tyvar [] alpha_ty liftTyCon
727 bottom = panic "liftDataCon:State# _RealWorld"