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.''
30 getStatePairingConInfo,
51 tupleTyCon, tupleCon, unitTyCon, unitDataCon, pairTyCon, pairDataCon,
67 stateAndAddrPrimTyCon,
68 stateAndArrayPrimTyCon,
69 stateAndByteArrayPrimTyCon,
70 stateAndCharPrimTyCon,
71 stateAndDoublePrimTyCon,
72 stateAndFloatPrimTyCon,
74 stateAndForeignObjPrimTyCon,
75 stateAndMutableArrayPrimTyCon,
76 stateAndMutableByteArrayPrimTyCon,
78 stateAndStablePtrPrimTyCon,
79 stateAndSynchVarPrimTyCon,
80 stateAndWordPrimTyCon,
93 #include "HsVersions.h"
95 import {-# SOURCE #-} MkId ( mkDataCon, mkTupleCon )
96 import {-# SOURCE #-} Id ( Id, StrictnessMark(..) )
103 import Kind ( mkBoxedTypeKind, mkArrowKind )
104 import Name ( mkWiredInTyConName, mkWiredInIdName )
105 import TyCon ( mkDataTyCon, mkTupleTyCon, mkSynTyCon,
108 import BasicTypes ( Module, NewOrData(..), RecFlag(..) )
109 import Type ( Type, mkTyConTy, mkTyConApp, mkSigmaTy, mkTyVarTys,
110 mkFunTy, mkFunTys, splitTyConApp_maybe, splitAlgTyConApp_maybe,
111 GenType(..), ThetaType, TauType )
112 import TyVar ( GenTyVar, TyVar, tyVarKind, alphaTyVars, alphaTyVar, betaTyVar )
113 import Lex ( mkTupNameStr )
115 import Util ( assoc, panic )
117 alpha_tyvar = [alphaTyVar]
119 alpha_beta_tyvars = [alphaTyVar, betaTyVar]
121 pcRecDataTyCon, pcNonRecDataTyCon, pcNonRecNewTyCon
122 :: Unique{-TyConKey-} -> Module -> FAST_STRING
123 -> [TyVar] -> [Id] -> TyCon
125 pcRecDataTyCon = pc_tycon DataType Recursive
126 pcNonRecDataTyCon = pc_tycon DataType NonRecursive
127 pcNonRecNewTyCon = pc_tycon NewType NonRecursive
129 pc_tycon new_or_data is_rec key mod str tyvars cons
132 tycon = mkDataTyCon name tycon_kind
137 Nothing -- Not a dictionary
141 name = mkWiredInTyConName key mod str tycon
142 tycon_kind = foldr (mkArrowKind . tyVarKind) mkBoxedTypeKind tyvars
144 pcSynTyCon key mod str kind arity tyvars expansion
147 tycon = mkSynTyCon name kind arity tyvars expansion
148 name = mkWiredInTyConName key mod str tycon
150 pcDataCon :: Unique{-DataConKey-} -> Module -> FAST_STRING
151 -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> Id
152 pcDataCon key mod str tyvars context arg_tys tycon
155 data_con = mkDataCon name
156 [ NotMarkedStrict | a <- arg_tys ]
157 [ {- no labelled fields -} ]
158 tyvars context [] [] arg_tys tycon
159 name = mkWiredInIdName key mod str data_con
162 %************************************************************************
164 \subsection[TysWiredIn-tuples]{The tuple types}
166 %************************************************************************
169 tupleTyCon :: Arity -> TyCon
173 tycon = mkTupleTyCon uniq name arity
174 uniq = mkTupleTyConUnique arity
175 name = mkWiredInTyConName uniq mod_name (mkTupNameStr arity) tycon
176 mod_name | arity == 0 = pREL_BASE
177 | otherwise = pREL_TUP
179 tupleCon :: Arity -> Id
183 tuple_con = mkTupleCon arity name ty
184 uniq = mkTupleDataConUnique arity
185 name = mkWiredInIdName uniq mod_name (mkTupNameStr arity) tuple_con
186 mod_name | arity == 0 = pREL_BASE
187 | otherwise = pREL_TUP
188 ty = mkSigmaTy tyvars [] (mkFunTys tyvar_tys (mkTyConApp tycon tyvar_tys))
189 tyvars = take arity alphaTyVars
190 tyvar_tys = mkTyVarTys tyvars
191 tycon = tupleTyCon arity
193 unitTyCon = tupleTyCon 0
194 pairTyCon = tupleTyCon 2
196 unitDataCon = tupleCon 0
197 pairDataCon = tupleCon 2
201 %************************************************************************
203 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
205 %************************************************************************
208 charTy = mkTyConTy charTyCon
210 charTyCon = pcNonRecDataTyCon charTyConKey pREL_BASE SLIT("Char") [] [charDataCon]
211 charDataCon = pcDataCon charDataConKey pREL_BASE SLIT("C#") [] [] [charPrimTy] charTyCon
213 stringTy = mkListTy charTy -- convenience only
217 intTy = mkTyConTy intTyCon
219 intTyCon = pcNonRecDataTyCon intTyConKey pREL_BASE SLIT("Int") [] [intDataCon]
220 intDataCon = pcDataCon intDataConKey pREL_BASE SLIT("I#") [] [] [intPrimTy] intTyCon
222 isIntTy :: GenType flexi -> Bool
224 = case (splitAlgTyConApp_maybe ty) of
225 Just (tycon, [], _) -> uniqueOf tycon == intTyConKey
228 inIntRange :: Integer -> Bool -- Tells if an integer lies in the legal range of Ints
229 inIntRange i = (min_int <= i) && (i <= max_int)
231 max_int, min_int :: Integer
232 max_int = toInteger maxInt
233 min_int = toInteger minInt
237 wordTy = mkTyConTy wordTyCon
239 wordTyCon = pcNonRecDataTyCon wordTyConKey pREL_FOREIGN SLIT("Word") [] [wordDataCon]
240 wordDataCon = pcDataCon wordDataConKey pREL_FOREIGN SLIT("W#") [] [] [wordPrimTy] wordTyCon
244 addrTy = mkTyConTy addrTyCon
246 addrTyCon = pcNonRecDataTyCon addrTyConKey pREL_ADDR SLIT("Addr") [] [addrDataCon]
247 addrDataCon = pcDataCon addrDataConKey pREL_ADDR SLIT("A#") [] [] [addrPrimTy] addrTyCon
251 floatTy = mkTyConTy floatTyCon
253 floatTyCon = pcNonRecDataTyCon floatTyConKey pREL_BASE SLIT("Float") [] [floatDataCon]
254 floatDataCon = pcDataCon floatDataConKey pREL_BASE SLIT("F#") [] [] [floatPrimTy] floatTyCon
258 doubleTy = mkTyConTy doubleTyCon
260 doubleTyCon = pcNonRecDataTyCon doubleTyConKey pREL_BASE SLIT("Double") [] [doubleDataCon]
261 doubleDataCon = pcDataCon doubleDataConKey pREL_BASE SLIT("D#") [] [] [doublePrimTy] doubleTyCon
265 mkStateTy ty = mkTyConApp stateTyCon [ty]
266 realWorldStateTy = mkStateTy realWorldTy -- a common use
268 stateTyCon = pcNonRecDataTyCon stateTyConKey pREL_ST SLIT("State") alpha_tyvar [stateDataCon]
270 = pcDataCon stateDataConKey pREL_ST SLIT("S#")
271 alpha_tyvar [] [mkStatePrimTy alphaTy] stateTyCon
276 = pcNonRecDataTyCon stablePtrTyConKey pREL_FOREIGN SLIT("StablePtr")
277 alpha_tyvar [stablePtrDataCon]
280 = pcDataCon stablePtrDataConKey pREL_FOREIGN SLIT("StablePtr")
281 alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon
286 = pcNonRecDataTyCon foreignObjTyConKey pREL_FOREIGN SLIT("ForeignObj")
287 [] [foreignObjDataCon]
290 = pcDataCon foreignObjDataConKey pREL_FOREIGN SLIT("ForeignObj")
291 [] [] [foreignObjPrimTy] foreignObjTyCon
294 %************************************************************************
296 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
298 %************************************************************************
300 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
302 integerTy :: GenType t
303 integerTy = mkTyConTy integerTyCon
305 integerTyCon = pcNonRecDataTyCon integerTyConKey pREL_BASE SLIT("Integer") [] [integerDataCon]
307 integerDataCon = pcDataCon integerDataConKey pREL_BASE SLIT("J#")
308 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon
310 isIntegerTy :: GenType flexi -> Bool
312 = case (splitAlgTyConApp_maybe ty) of
313 Just (tycon, [], _) -> uniqueOf tycon == integerTyConKey
317 And the other pairing types:
319 return2GMPsTyCon = pcNonRecDataTyCon return2GMPsTyConKey
320 pREL_NUM SLIT("Return2GMPs") [] [return2GMPsDataCon]
323 = pcDataCon return2GMPsDataConKey pREL_NUM SLIT("Return2GMPs") [] []
324 [intPrimTy, intPrimTy, byteArrayPrimTy,
325 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon
327 returnIntAndGMPTyCon = pcNonRecDataTyCon returnIntAndGMPTyConKey
328 pREL_NUM SLIT("ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
330 returnIntAndGMPDataCon
331 = pcDataCon returnIntAndGMPDataConKey pREL_NUM SLIT("ReturnIntAndGMP") [] []
332 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon
335 %************************************************************************
337 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
339 %************************************************************************
341 These boring types pair a \tr{State#} with another primitive type.
342 They are not really primitive, so they are given here, not in
345 We fish one of these \tr{StateAnd<blah>#} things with
346 @getStatePairingConInfo@ (given a little way down).
350 = pcNonRecDataTyCon stateAndPtrPrimTyConKey pREL_ST SLIT("StateAndPtr#")
351 alpha_beta_tyvars [stateAndPtrPrimDataCon]
352 stateAndPtrPrimDataCon
353 = pcDataCon stateAndPtrPrimDataConKey pREL_ST SLIT("StateAndPtr#")
354 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
357 stateAndCharPrimTyCon
358 = pcNonRecDataTyCon stateAndCharPrimTyConKey pREL_ST SLIT("StateAndChar#")
359 alpha_tyvar [stateAndCharPrimDataCon]
360 stateAndCharPrimDataCon
361 = pcDataCon stateAndCharPrimDataConKey pREL_ST SLIT("StateAndChar#")
362 alpha_tyvar [] [mkStatePrimTy alphaTy, charPrimTy]
363 stateAndCharPrimTyCon
366 = pcNonRecDataTyCon stateAndIntPrimTyConKey pREL_ST SLIT("StateAndInt#")
367 alpha_tyvar [stateAndIntPrimDataCon]
368 stateAndIntPrimDataCon
369 = pcDataCon stateAndIntPrimDataConKey pREL_ST SLIT("StateAndInt#")
370 alpha_tyvar [] [mkStatePrimTy alphaTy, intPrimTy]
373 stateAndWordPrimTyCon
374 = pcNonRecDataTyCon stateAndWordPrimTyConKey pREL_ST SLIT("StateAndWord#")
375 alpha_tyvar [stateAndWordPrimDataCon]
376 stateAndWordPrimDataCon
377 = pcDataCon stateAndWordPrimDataConKey pREL_ST SLIT("StateAndWord#")
378 alpha_tyvar [] [mkStatePrimTy alphaTy, wordPrimTy]
379 stateAndWordPrimTyCon
381 stateAndAddrPrimTyCon
382 = pcNonRecDataTyCon stateAndAddrPrimTyConKey pREL_ST SLIT("StateAndAddr#")
383 alpha_tyvar [stateAndAddrPrimDataCon]
384 stateAndAddrPrimDataCon
385 = pcDataCon stateAndAddrPrimDataConKey pREL_ST SLIT("StateAndAddr#")
386 alpha_tyvar [] [mkStatePrimTy alphaTy, addrPrimTy]
387 stateAndAddrPrimTyCon
389 stateAndStablePtrPrimTyCon
390 = pcNonRecDataTyCon stateAndStablePtrPrimTyConKey pREL_FOREIGN SLIT("StateAndStablePtr#")
391 alpha_beta_tyvars [stateAndStablePtrPrimDataCon]
392 stateAndStablePtrPrimDataCon
393 = pcDataCon stateAndStablePtrPrimDataConKey pREL_FOREIGN SLIT("StateAndStablePtr#")
395 [mkStatePrimTy alphaTy, mkTyConApp stablePtrPrimTyCon [betaTy]]
396 stateAndStablePtrPrimTyCon
398 stateAndForeignObjPrimTyCon
399 = pcNonRecDataTyCon stateAndForeignObjPrimTyConKey pREL_FOREIGN SLIT("StateAndForeignObj#")
400 alpha_tyvar [stateAndForeignObjPrimDataCon]
401 stateAndForeignObjPrimDataCon
402 = pcDataCon stateAndForeignObjPrimDataConKey pREL_FOREIGN SLIT("StateAndForeignObj#")
404 [mkStatePrimTy alphaTy, mkTyConTy foreignObjPrimTyCon]
405 stateAndForeignObjPrimTyCon
407 stateAndFloatPrimTyCon
408 = pcNonRecDataTyCon stateAndFloatPrimTyConKey pREL_ST SLIT("StateAndFloat#")
409 alpha_tyvar [stateAndFloatPrimDataCon]
410 stateAndFloatPrimDataCon
411 = pcDataCon stateAndFloatPrimDataConKey pREL_ST SLIT("StateAndFloat#")
412 alpha_tyvar [] [mkStatePrimTy alphaTy, floatPrimTy]
413 stateAndFloatPrimTyCon
415 stateAndDoublePrimTyCon
416 = pcNonRecDataTyCon stateAndDoublePrimTyConKey pREL_ST SLIT("StateAndDouble#")
417 alpha_tyvar [stateAndDoublePrimDataCon]
418 stateAndDoublePrimDataCon
419 = pcDataCon stateAndDoublePrimDataConKey pREL_ST SLIT("StateAndDouble#")
420 alpha_tyvar [] [mkStatePrimTy alphaTy, doublePrimTy]
421 stateAndDoublePrimTyCon
425 stateAndArrayPrimTyCon
426 = pcNonRecDataTyCon stateAndArrayPrimTyConKey pREL_ARR SLIT("StateAndArray#")
427 alpha_beta_tyvars [stateAndArrayPrimDataCon]
428 stateAndArrayPrimDataCon
429 = pcDataCon stateAndArrayPrimDataConKey pREL_ARR SLIT("StateAndArray#")
430 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
431 stateAndArrayPrimTyCon
433 stateAndMutableArrayPrimTyCon
434 = pcNonRecDataTyCon stateAndMutableArrayPrimTyConKey pREL_ARR SLIT("StateAndMutableArray#")
435 alpha_beta_tyvars [stateAndMutableArrayPrimDataCon]
436 stateAndMutableArrayPrimDataCon
437 = pcDataCon stateAndMutableArrayPrimDataConKey pREL_ARR SLIT("StateAndMutableArray#")
438 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
439 stateAndMutableArrayPrimTyCon
441 stateAndByteArrayPrimTyCon
442 = pcNonRecDataTyCon stateAndByteArrayPrimTyConKey pREL_ARR SLIT("StateAndByteArray#")
443 alpha_tyvar [stateAndByteArrayPrimDataCon]
444 stateAndByteArrayPrimDataCon
445 = pcDataCon stateAndByteArrayPrimDataConKey pREL_ARR SLIT("StateAndByteArray#")
446 alpha_tyvar [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
447 stateAndByteArrayPrimTyCon
449 stateAndMutableByteArrayPrimTyCon
450 = pcNonRecDataTyCon stateAndMutableByteArrayPrimTyConKey pREL_ARR SLIT("StateAndMutableByteArray#")
451 alpha_tyvar [stateAndMutableByteArrayPrimDataCon]
452 stateAndMutableByteArrayPrimDataCon
453 = pcDataCon stateAndMutableByteArrayPrimDataConKey pREL_ARR SLIT("StateAndMutableByteArray#")
454 alpha_tyvar [] [mkStatePrimTy alphaTy, mkTyConApp mutableByteArrayPrimTyCon alpha_ty]
455 stateAndMutableByteArrayPrimTyCon
457 stateAndSynchVarPrimTyCon
458 = pcNonRecDataTyCon stateAndSynchVarPrimTyConKey pREL_CONC SLIT("StateAndSynchVar#")
459 alpha_beta_tyvars [stateAndSynchVarPrimDataCon]
460 stateAndSynchVarPrimDataCon
461 = pcDataCon stateAndSynchVarPrimDataConKey pREL_CONC SLIT("StateAndSynchVar#")
462 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
463 stateAndSynchVarPrimTyCon
466 The ccall-desugaring mechanism uses this function to figure out how to
467 rebox the result. It's really a HACK, especially the part about
468 how many types to drop from \tr{tys_applied}.
471 getStatePairingConInfo
472 :: Type -- primitive type
473 -> (Id, -- state pair constructor for prim type
474 Type) -- type of state pair
476 getStatePairingConInfo prim_ty
477 = case (splitTyConApp_maybe prim_ty) of
478 Nothing -> panic "getStatePairingConInfo:1"
479 Just (prim_tycon, tys_applied) ->
481 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
482 pair_ty = mkTyConApp pair_tycon (realWorldTy : drop num_tys tys_applied)
487 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
488 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
489 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
490 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
491 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
492 (foreignObjPrimTyCon, (stateAndForeignObjPrimDataCon, stateAndForeignObjPrimTyCon, 0)),
493 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
494 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
495 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
496 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
497 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
498 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
499 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
500 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
504 %************************************************************************
506 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
508 %************************************************************************
510 The only reason this is wired in is because we have to represent the
514 mkStateTransformerTy s a = mkTyConApp stTyCon [s, a]
516 stTyCon = pcNonRecNewTyCon stTyConKey pREL_ST SLIT("ST") alpha_beta_tyvars [stDataCon]
518 stDataCon = pcDataCon stDataConKey pREL_ST SLIT("ST")
519 alpha_beta_tyvars [] [ty] stTyCon
521 ty = mkFunTy (mkStatePrimTy alphaTy) (mkSTretTy alphaTy betaTy)
523 mkSTretTy alpha beta = mkTyConApp stRetTyCon [alpha,beta]
526 = pcNonRecDataTyCon stRetTyConKey pREL_ST SLIT("STret")
527 alpha_beta_tyvars [stRetDataCon]
529 = pcDataCon stRetDataConKey pREL_ST SLIT("STret")
530 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
534 %************************************************************************
536 \subsection[TysWiredIn-Bool]{The @Bool@ type}
538 %************************************************************************
540 An ordinary enumeration type, but deeply wired in. There are no
541 magical operations on @Bool@ (just the regular Prelude code).
543 {\em BEGIN IDLE SPECULATION BY SIMON}
545 This is not the only way to encode @Bool@. A more obvious coding makes
546 @Bool@ just a boxed up version of @Bool#@, like this:
549 data Bool = MkBool Bool#
552 Unfortunately, this doesn't correspond to what the Report says @Bool@
553 looks like! Furthermore, we get slightly less efficient code (I
554 think) with this coding. @gtInt@ would look like this:
557 gtInt :: Int -> Int -> Bool
558 gtInt x y = case x of I# x# ->
560 case (gtIntPrim x# y#) of
564 Notice that the result of the @gtIntPrim@ comparison has to be turned
565 into an integer (here called @b#@), and returned in a @MkBool@ box.
567 The @if@ expression would compile to this:
570 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
573 I think this code is a little less efficient than the previous code,
574 but I'm not certain. At all events, corresponding with the Report is
575 important. The interesting thing is that the language is expressive
576 enough to describe more than one alternative; and that a type doesn't
577 necessarily need to be a straightforwardly boxed version of its
578 primitive counterpart.
580 {\em END IDLE SPECULATION BY SIMON}
583 boolTy = mkTyConTy boolTyCon
585 boolTyCon = pcNonRecDataTyCon boolTyConKey pREL_BASE SLIT("Bool") [] [falseDataCon, trueDataCon]
587 falseDataCon = pcDataCon falseDataConKey pREL_BASE SLIT("False") [] [] [] boolTyCon
588 trueDataCon = pcDataCon trueDataConKey pREL_BASE SLIT("True") [] [] [] boolTyCon
591 %************************************************************************
593 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
595 %************************************************************************
597 Special syntax, deeply wired in, but otherwise an ordinary algebraic
600 data [] a = [] | a : (List a)
602 data (,) a b = (,,) a b
607 mkListTy :: GenType t -> GenType t
608 mkListTy ty = mkTyConApp listTyCon [ty]
610 alphaListTy = mkSigmaTy alpha_tyvar [] (mkTyConApp listTyCon alpha_ty)
612 listTyCon = pcRecDataTyCon listTyConKey pREL_BASE SLIT("[]")
613 alpha_tyvar [nilDataCon, consDataCon]
615 nilDataCon = pcDataCon nilDataConKey pREL_BASE SLIT("[]") alpha_tyvar [] [] listTyCon
616 consDataCon = pcDataCon consDataConKey pREL_BASE SLIT(":")
617 alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
618 -- Interesting: polymorphic recursion would help here.
619 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
620 -- gets the over-specific type (Type -> Type)
623 %************************************************************************
625 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
627 %************************************************************************
629 The tuple types are definitely magic, because they form an infinite
634 They have a special family of type constructors, of type @TyCon@
635 These contain the tycon arity, but don't require a Unique.
638 They have a special family of constructors, of type
639 @Id@. Again these contain their arity but don't need a Unique.
642 There should be a magic way of generating the info tables and
643 entry code for all tuples.
645 But at the moment we just compile a Haskell source
646 file\srcloc{lib/prelude/...} containing declarations like:
649 data Tuple2 a b = Tup2 a b
650 data Tuple3 a b c = Tup3 a b c
651 data Tuple4 a b c d = Tup4 a b c d
654 The print-names associated with the magic @Id@s for tuple constructors
655 ``just happen'' to be the same as those generated by these
659 The instance environment should have a magic way to know
660 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
661 so on. \ToDo{Not implemented yet.}
664 There should also be a way to generate the appropriate code for each
665 of these instances, but (like the info tables and entry code) it is
666 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
670 mkTupleTy :: Int -> [GenType t] -> GenType t
672 mkTupleTy arity tys = mkTyConApp (tupleTyCon arity) tys
674 unitTy = mkTupleTy 0 []
677 %************************************************************************
679 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
681 %************************************************************************
683 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
686 mkLiftTy ty = mkTyConApp liftTyCon [ty]
690 = mkSigmaTy tvs theta (mkTyConApp liftTyCon [tau])
692 (tvs, theta, tau) = splitSigmaTy ty
695 = case (splitAlgTyConApp_maybeExpandingDicts tau) of
696 Just (tycon, tys, _) -> tycon == liftTyCon
699 (tvs, theta, tau) = splitSigmaTy ty
703 alphaLiftTy = mkSigmaTy alpha_tyvar [] (mkTyConApp liftTyCon alpha_ty)
706 = pcNonRecDataTyCon liftTyConKey pREL_BASE SLIT("Lift") alpha_tyvar [liftDataCon]
709 = pcDataCon liftDataConKey pREL_BASE SLIT("Lift")
710 alpha_tyvar [] alpha_ty liftTyCon
712 bottom = panic "liftDataCon:State# _RealWorld"