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 #-} Id ( Id, mkDataCon, mkTupleCon, StrictnessMark(..) )
102 import Kind ( mkBoxedTypeKind, mkArrowKind )
103 import Name ( mkWiredInTyConName, mkWiredInIdName )
104 import TyCon ( mkDataTyCon, mkTupleTyCon, mkSynTyCon,
107 import BasicTypes ( Module, NewOrData(..), RecFlag(..) )
108 import Type ( Type, mkTyConTy, mkTyConApp, mkSigmaTy, mkTyVarTys,
109 mkFunTy, mkFunTys, splitTyConApp_maybe, splitAlgTyConApp_maybe,
110 GenType(..), ThetaType, TauType )
111 import TyVar ( GenTyVar, TyVar, tyVarKind, alphaTyVars, alphaTyVar, betaTyVar )
112 import Lex ( mkTupNameStr )
114 import Util ( assoc, panic )
116 alpha_tyvar = [alphaTyVar]
118 alpha_beta_tyvars = [alphaTyVar, betaTyVar]
120 pcRecDataTyCon, pcNonRecDataTyCon, pcNonRecNewTyCon
121 :: Unique{-TyConKey-} -> Module -> FAST_STRING
122 -> [TyVar] -> [Id] -> TyCon
124 pcRecDataTyCon = pc_tycon DataType Recursive
125 pcNonRecDataTyCon = pc_tycon DataType NonRecursive
126 pcNonRecNewTyCon = pc_tycon NewType NonRecursive
128 pc_tycon new_or_data is_rec key mod str tyvars cons
131 tycon = mkDataTyCon name tycon_kind
136 Nothing -- Not a dictionary
140 name = mkWiredInTyConName key mod str tycon
141 tycon_kind = foldr (mkArrowKind . tyVarKind) mkBoxedTypeKind tyvars
143 pcSynTyCon key mod str kind arity tyvars expansion
146 tycon = mkSynTyCon name kind arity tyvars expansion
147 name = mkWiredInTyConName key mod str tycon
149 pcDataCon :: Unique{-DataConKey-} -> Module -> FAST_STRING
150 -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> Id
151 pcDataCon key mod str tyvars context arg_tys tycon
154 data_con = mkDataCon name
155 [ NotMarkedStrict | a <- arg_tys ]
156 [ {- no labelled fields -} ]
157 tyvars context [] [] arg_tys tycon
158 name = mkWiredInIdName key mod str data_con
161 %************************************************************************
163 \subsection[TysWiredIn-tuples]{The tuple types}
165 %************************************************************************
168 tupleTyCon :: Arity -> TyCon
172 tycon = mkTupleTyCon uniq name arity
173 uniq = mkTupleTyConUnique arity
174 name = mkWiredInTyConName uniq mod_name (mkTupNameStr arity) tycon
175 mod_name | arity == 0 = pREL_BASE
176 | otherwise = pREL_TUP
178 tupleCon :: Arity -> Id
182 tuple_con = mkTupleCon arity name ty
183 uniq = mkTupleDataConUnique arity
184 name = mkWiredInIdName uniq mod_name (mkTupNameStr arity) tuple_con
185 mod_name | arity == 0 = pREL_BASE
186 | otherwise = pREL_TUP
187 ty = mkSigmaTy tyvars [] (mkFunTys tyvar_tys (mkTyConApp tycon tyvar_tys))
188 tyvars = take arity alphaTyVars
189 tyvar_tys = mkTyVarTys tyvars
190 tycon = tupleTyCon arity
192 unitTyCon = tupleTyCon 0
193 pairTyCon = tupleTyCon 2
195 unitDataCon = tupleCon 0
196 pairDataCon = tupleCon 2
200 %************************************************************************
202 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
204 %************************************************************************
207 charTy = mkTyConTy charTyCon
209 charTyCon = pcNonRecDataTyCon charTyConKey pREL_BASE SLIT("Char") [] [charDataCon]
210 charDataCon = pcDataCon charDataConKey pREL_BASE SLIT("C#") [] [] [charPrimTy] charTyCon
212 stringTy = mkListTy charTy -- convenience only
216 intTy = mkTyConTy intTyCon
218 intTyCon = pcNonRecDataTyCon intTyConKey pREL_BASE SLIT("Int") [] [intDataCon]
219 intDataCon = pcDataCon intDataConKey pREL_BASE SLIT("I#") [] [] [intPrimTy] intTyCon
221 isIntTy :: GenType flexi -> Bool
223 = case (splitAlgTyConApp_maybe ty) of
224 Just (tycon, [], _) -> uniqueOf tycon == intTyConKey
227 inIntRange :: Integer -> Bool -- Tells if an integer lies in the legal range of Ints
228 inIntRange i = (min_int <= i) && (i <= max_int)
230 max_int, min_int :: Integer
231 max_int = toInteger maxInt
232 min_int = toInteger minInt
236 wordTy = mkTyConTy wordTyCon
238 wordTyCon = pcNonRecDataTyCon wordTyConKey fOREIGN SLIT("Word") [] [wordDataCon]
239 wordDataCon = pcDataCon wordDataConKey fOREIGN SLIT("W#") [] [] [wordPrimTy] wordTyCon
243 addrTy = mkTyConTy addrTyCon
245 addrTyCon = pcNonRecDataTyCon addrTyConKey aDDR SLIT("Addr") [] [addrDataCon]
246 addrDataCon = pcDataCon addrDataConKey aDDR SLIT("A#") [] [] [addrPrimTy] addrTyCon
250 floatTy = mkTyConTy floatTyCon
252 floatTyCon = pcNonRecDataTyCon floatTyConKey pREL_BASE SLIT("Float") [] [floatDataCon]
253 floatDataCon = pcDataCon floatDataConKey pREL_BASE SLIT("F#") [] [] [floatPrimTy] floatTyCon
257 doubleTy = mkTyConTy doubleTyCon
259 doubleTyCon = pcNonRecDataTyCon doubleTyConKey pREL_BASE SLIT("Double") [] [doubleDataCon]
260 doubleDataCon = pcDataCon doubleDataConKey pREL_BASE SLIT("D#") [] [] [doublePrimTy] doubleTyCon
264 mkStateTy ty = mkTyConApp stateTyCon [ty]
265 realWorldStateTy = mkStateTy realWorldTy -- a common use
267 stateTyCon = pcNonRecDataTyCon stateTyConKey sT_BASE SLIT("State") alpha_tyvar [stateDataCon]
269 = pcDataCon stateDataConKey sT_BASE SLIT("S#")
270 alpha_tyvar [] [mkStatePrimTy alphaTy] stateTyCon
275 = pcNonRecDataTyCon stablePtrTyConKey fOREIGN SLIT("StablePtr")
276 alpha_tyvar [stablePtrDataCon]
279 = pcDataCon stablePtrDataConKey fOREIGN SLIT("StablePtr")
280 alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon
285 = pcNonRecDataTyCon foreignObjTyConKey fOREIGN SLIT("ForeignObj")
286 [] [foreignObjDataCon]
289 = pcDataCon foreignObjDataConKey fOREIGN SLIT("ForeignObj")
290 [] [] [foreignObjPrimTy] foreignObjTyCon
293 %************************************************************************
295 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
297 %************************************************************************
299 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
301 integerTy :: GenType t
302 integerTy = mkTyConTy integerTyCon
304 integerTyCon = pcNonRecDataTyCon integerTyConKey pREL_BASE SLIT("Integer") [] [integerDataCon]
306 integerDataCon = pcDataCon integerDataConKey pREL_BASE SLIT("J#")
307 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon
309 isIntegerTy :: GenType flexi -> Bool
311 = case (splitAlgTyConApp_maybe ty) of
312 Just (tycon, [], _) -> uniqueOf tycon == integerTyConKey
316 And the other pairing types:
318 return2GMPsTyCon = pcNonRecDataTyCon return2GMPsTyConKey
319 pREL_NUM SLIT("Return2GMPs") [] [return2GMPsDataCon]
322 = pcDataCon return2GMPsDataConKey pREL_NUM SLIT("Return2GMPs") [] []
323 [intPrimTy, intPrimTy, byteArrayPrimTy,
324 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon
326 returnIntAndGMPTyCon = pcNonRecDataTyCon returnIntAndGMPTyConKey
327 pREL_NUM SLIT("ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
329 returnIntAndGMPDataCon
330 = pcDataCon returnIntAndGMPDataConKey pREL_NUM SLIT("ReturnIntAndGMP") [] []
331 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon
334 %************************************************************************
336 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
338 %************************************************************************
340 These boring types pair a \tr{State#} with another primitive type.
341 They are not really primitive, so they are given here, not in
344 We fish one of these \tr{StateAnd<blah>#} things with
345 @getStatePairingConInfo@ (given a little way down).
349 = pcNonRecDataTyCon stateAndPtrPrimTyConKey sT_BASE SLIT("StateAndPtr#")
350 alpha_beta_tyvars [stateAndPtrPrimDataCon]
351 stateAndPtrPrimDataCon
352 = pcDataCon stateAndPtrPrimDataConKey sT_BASE SLIT("StateAndPtr#")
353 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
356 stateAndCharPrimTyCon
357 = pcNonRecDataTyCon stateAndCharPrimTyConKey sT_BASE SLIT("StateAndChar#")
358 alpha_tyvar [stateAndCharPrimDataCon]
359 stateAndCharPrimDataCon
360 = pcDataCon stateAndCharPrimDataConKey sT_BASE SLIT("StateAndChar#")
361 alpha_tyvar [] [mkStatePrimTy alphaTy, charPrimTy]
362 stateAndCharPrimTyCon
365 = pcNonRecDataTyCon stateAndIntPrimTyConKey sT_BASE SLIT("StateAndInt#")
366 alpha_tyvar [stateAndIntPrimDataCon]
367 stateAndIntPrimDataCon
368 = pcDataCon stateAndIntPrimDataConKey sT_BASE SLIT("StateAndInt#")
369 alpha_tyvar [] [mkStatePrimTy alphaTy, intPrimTy]
372 stateAndWordPrimTyCon
373 = pcNonRecDataTyCon stateAndWordPrimTyConKey sT_BASE SLIT("StateAndWord#")
374 alpha_tyvar [stateAndWordPrimDataCon]
375 stateAndWordPrimDataCon
376 = pcDataCon stateAndWordPrimDataConKey sT_BASE SLIT("StateAndWord#")
377 alpha_tyvar [] [mkStatePrimTy alphaTy, wordPrimTy]
378 stateAndWordPrimTyCon
380 stateAndAddrPrimTyCon
381 = pcNonRecDataTyCon stateAndAddrPrimTyConKey sT_BASE SLIT("StateAndAddr#")
382 alpha_tyvar [stateAndAddrPrimDataCon]
383 stateAndAddrPrimDataCon
384 = pcDataCon stateAndAddrPrimDataConKey sT_BASE SLIT("StateAndAddr#")
385 alpha_tyvar [] [mkStatePrimTy alphaTy, addrPrimTy]
386 stateAndAddrPrimTyCon
388 stateAndStablePtrPrimTyCon
389 = pcNonRecDataTyCon stateAndStablePtrPrimTyConKey fOREIGN SLIT("StateAndStablePtr#")
390 alpha_beta_tyvars [stateAndStablePtrPrimDataCon]
391 stateAndStablePtrPrimDataCon
392 = pcDataCon stateAndStablePtrPrimDataConKey fOREIGN SLIT("StateAndStablePtr#")
394 [mkStatePrimTy alphaTy, mkTyConApp stablePtrPrimTyCon [betaTy]]
395 stateAndStablePtrPrimTyCon
397 stateAndForeignObjPrimTyCon
398 = pcNonRecDataTyCon stateAndForeignObjPrimTyConKey fOREIGN SLIT("StateAndForeignObj#")
399 alpha_tyvar [stateAndForeignObjPrimDataCon]
400 stateAndForeignObjPrimDataCon
401 = pcDataCon stateAndForeignObjPrimDataConKey fOREIGN SLIT("StateAndForeignObj#")
403 [mkStatePrimTy alphaTy, mkTyConTy foreignObjPrimTyCon]
404 stateAndForeignObjPrimTyCon
406 stateAndFloatPrimTyCon
407 = pcNonRecDataTyCon stateAndFloatPrimTyConKey sT_BASE SLIT("StateAndFloat#")
408 alpha_tyvar [stateAndFloatPrimDataCon]
409 stateAndFloatPrimDataCon
410 = pcDataCon stateAndFloatPrimDataConKey sT_BASE SLIT("StateAndFloat#")
411 alpha_tyvar [] [mkStatePrimTy alphaTy, floatPrimTy]
412 stateAndFloatPrimTyCon
414 stateAndDoublePrimTyCon
415 = pcNonRecDataTyCon stateAndDoublePrimTyConKey sT_BASE SLIT("StateAndDouble#")
416 alpha_tyvar [stateAndDoublePrimDataCon]
417 stateAndDoublePrimDataCon
418 = pcDataCon stateAndDoublePrimDataConKey sT_BASE SLIT("StateAndDouble#")
419 alpha_tyvar [] [mkStatePrimTy alphaTy, doublePrimTy]
420 stateAndDoublePrimTyCon
424 stateAndArrayPrimTyCon
425 = pcNonRecDataTyCon stateAndArrayPrimTyConKey aRR_BASE SLIT("StateAndArray#")
426 alpha_beta_tyvars [stateAndArrayPrimDataCon]
427 stateAndArrayPrimDataCon
428 = pcDataCon stateAndArrayPrimDataConKey aRR_BASE SLIT("StateAndArray#")
429 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
430 stateAndArrayPrimTyCon
432 stateAndMutableArrayPrimTyCon
433 = pcNonRecDataTyCon stateAndMutableArrayPrimTyConKey aRR_BASE SLIT("StateAndMutableArray#")
434 alpha_beta_tyvars [stateAndMutableArrayPrimDataCon]
435 stateAndMutableArrayPrimDataCon
436 = pcDataCon stateAndMutableArrayPrimDataConKey aRR_BASE SLIT("StateAndMutableArray#")
437 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
438 stateAndMutableArrayPrimTyCon
440 stateAndByteArrayPrimTyCon
441 = pcNonRecDataTyCon stateAndByteArrayPrimTyConKey aRR_BASE SLIT("StateAndByteArray#")
442 alpha_tyvar [stateAndByteArrayPrimDataCon]
443 stateAndByteArrayPrimDataCon
444 = pcDataCon stateAndByteArrayPrimDataConKey aRR_BASE SLIT("StateAndByteArray#")
445 alpha_tyvar [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
446 stateAndByteArrayPrimTyCon
448 stateAndMutableByteArrayPrimTyCon
449 = pcNonRecDataTyCon stateAndMutableByteArrayPrimTyConKey aRR_BASE SLIT("StateAndMutableByteArray#")
450 alpha_tyvar [stateAndMutableByteArrayPrimDataCon]
451 stateAndMutableByteArrayPrimDataCon
452 = pcDataCon stateAndMutableByteArrayPrimDataConKey aRR_BASE SLIT("StateAndMutableByteArray#")
453 alpha_tyvar [] [mkStatePrimTy alphaTy, mkTyConApp mutableByteArrayPrimTyCon alpha_ty]
454 stateAndMutableByteArrayPrimTyCon
456 stateAndSynchVarPrimTyCon
457 = pcNonRecDataTyCon stateAndSynchVarPrimTyConKey cONC_BASE SLIT("StateAndSynchVar#")
458 alpha_beta_tyvars [stateAndSynchVarPrimDataCon]
459 stateAndSynchVarPrimDataCon
460 = pcDataCon stateAndSynchVarPrimDataConKey cONC_BASE SLIT("StateAndSynchVar#")
461 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
462 stateAndSynchVarPrimTyCon
465 The ccall-desugaring mechanism uses this function to figure out how to
466 rebox the result. It's really a HACK, especially the part about
467 how many types to drop from \tr{tys_applied}.
470 getStatePairingConInfo
471 :: Type -- primitive type
472 -> (Id, -- state pair constructor for prim type
473 Type) -- type of state pair
475 getStatePairingConInfo prim_ty
476 = case (splitTyConApp_maybe prim_ty) of
477 Nothing -> panic "getStatePairingConInfo:1"
478 Just (prim_tycon, tys_applied) ->
480 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
481 pair_ty = mkTyConApp pair_tycon (realWorldTy : drop num_tys tys_applied)
486 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
487 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
488 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
489 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
490 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
491 (foreignObjPrimTyCon, (stateAndForeignObjPrimDataCon, stateAndForeignObjPrimTyCon, 0)),
492 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
493 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
494 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
495 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
496 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
497 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
498 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
499 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
503 %************************************************************************
505 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
507 %************************************************************************
509 The only reason this is wired in is because we have to represent the
513 mkStateTransformerTy s a = mkTyConApp stTyCon [s, a]
515 stTyCon = pcNonRecNewTyCon stTyConKey sT_BASE SLIT("ST") alpha_beta_tyvars [stDataCon]
517 stDataCon = pcDataCon stDataConKey sT_BASE SLIT("ST")
518 alpha_beta_tyvars [] [ty] stTyCon
520 ty = mkFunTy (mkStatePrimTy alphaTy) (mkSTretTy alphaTy betaTy)
522 mkSTretTy alpha beta = mkTyConApp stRetTyCon [alpha,beta]
525 = pcNonRecDataTyCon stRetTyConKey sT_BASE SLIT("STret")
526 alpha_beta_tyvars [stRetDataCon]
528 = pcDataCon stRetDataConKey sT_BASE SLIT("STret")
529 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
533 %************************************************************************
535 \subsection[TysWiredIn-Bool]{The @Bool@ type}
537 %************************************************************************
539 An ordinary enumeration type, but deeply wired in. There are no
540 magical operations on @Bool@ (just the regular Prelude code).
542 {\em BEGIN IDLE SPECULATION BY SIMON}
544 This is not the only way to encode @Bool@. A more obvious coding makes
545 @Bool@ just a boxed up version of @Bool#@, like this:
548 data Bool = MkBool Bool#
551 Unfortunately, this doesn't correspond to what the Report says @Bool@
552 looks like! Furthermore, we get slightly less efficient code (I
553 think) with this coding. @gtInt@ would look like this:
556 gtInt :: Int -> Int -> Bool
557 gtInt x y = case x of I# x# ->
559 case (gtIntPrim x# y#) of
563 Notice that the result of the @gtIntPrim@ comparison has to be turned
564 into an integer (here called @b#@), and returned in a @MkBool@ box.
566 The @if@ expression would compile to this:
569 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
572 I think this code is a little less efficient than the previous code,
573 but I'm not certain. At all events, corresponding with the Report is
574 important. The interesting thing is that the language is expressive
575 enough to describe more than one alternative; and that a type doesn't
576 necessarily need to be a straightforwardly boxed version of its
577 primitive counterpart.
579 {\em END IDLE SPECULATION BY SIMON}
582 boolTy = mkTyConTy boolTyCon
584 boolTyCon = pcNonRecDataTyCon boolTyConKey pREL_BASE SLIT("Bool") [] [falseDataCon, trueDataCon]
586 falseDataCon = pcDataCon falseDataConKey pREL_BASE SLIT("False") [] [] [] boolTyCon
587 trueDataCon = pcDataCon trueDataConKey pREL_BASE SLIT("True") [] [] [] boolTyCon
590 %************************************************************************
592 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
594 %************************************************************************
596 Special syntax, deeply wired in, but otherwise an ordinary algebraic
599 data [] a = [] | a : (List a)
601 data (,) a b = (,,) a b
606 mkListTy :: GenType t -> GenType t
607 mkListTy ty = mkTyConApp listTyCon [ty]
609 alphaListTy = mkSigmaTy alpha_tyvar [] (mkTyConApp listTyCon alpha_ty)
611 listTyCon = pcRecDataTyCon listTyConKey pREL_BASE SLIT("[]")
612 alpha_tyvar [nilDataCon, consDataCon]
614 nilDataCon = pcDataCon nilDataConKey pREL_BASE SLIT("[]") alpha_tyvar [] [] listTyCon
615 consDataCon = pcDataCon consDataConKey pREL_BASE SLIT(":")
616 alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
617 -- Interesting: polymorphic recursion would help here.
618 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
619 -- gets the over-specific type (Type -> Type)
622 %************************************************************************
624 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
626 %************************************************************************
628 The tuple types are definitely magic, because they form an infinite
633 They have a special family of type constructors, of type @TyCon@
634 These contain the tycon arity, but don't require a Unique.
637 They have a special family of constructors, of type
638 @Id@. Again these contain their arity but don't need a Unique.
641 There should be a magic way of generating the info tables and
642 entry code for all tuples.
644 But at the moment we just compile a Haskell source
645 file\srcloc{lib/prelude/...} containing declarations like:
648 data Tuple2 a b = Tup2 a b
649 data Tuple3 a b c = Tup3 a b c
650 data Tuple4 a b c d = Tup4 a b c d
653 The print-names associated with the magic @Id@s for tuple constructors
654 ``just happen'' to be the same as those generated by these
658 The instance environment should have a magic way to know
659 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
660 so on. \ToDo{Not implemented yet.}
663 There should also be a way to generate the appropriate code for each
664 of these instances, but (like the info tables and entry code) it is
665 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
669 mkTupleTy :: Int -> [GenType t] -> GenType t
671 mkTupleTy arity tys = mkTyConApp (tupleTyCon arity) tys
673 unitTy = mkTupleTy 0 []
676 %************************************************************************
678 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
680 %************************************************************************
682 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
685 mkLiftTy ty = mkTyConApp liftTyCon [ty]
689 = mkSigmaTy tvs theta (mkTyConApp liftTyCon [tau])
691 (tvs, theta, tau) = splitSigmaTy ty
694 = case (splitAlgTyConApp_maybeExpandingDicts tau) of
695 Just (tycon, tys, _) -> tycon == liftTyCon
698 (tvs, theta, tau) = splitSigmaTy ty
702 alphaLiftTy = mkSigmaTy alpha_tyvar [] (mkTyConApp liftTyCon alpha_ty)
705 = pcNonRecDataTyCon liftTyConKey pREL_BASE SLIT("Lift") alpha_tyvar [liftDataCon]
708 = pcDataCon liftDataConKey pREL_BASE SLIT("Lift")
709 alpha_tyvar [] alpha_ty liftTyCon
711 bottom = panic "liftDataCon:State# _RealWorld"