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.''
13 #include "HsVersions.h"
32 getStatePairingConInfo,
48 tupleTyCon, tupleCon, unitTyCon, unitDataCon, pairTyCon, pairDataCon,
58 stateAndAddrPrimTyCon,
59 stateAndArrayPrimTyCon,
60 stateAndByteArrayPrimTyCon,
61 stateAndCharPrimTyCon,
62 stateAndDoublePrimTyCon,
63 stateAndFloatPrimTyCon,
65 stateAndForeignObjPrimTyCon,
66 stateAndMutableArrayPrimTyCon,
67 stateAndMutableByteArrayPrimTyCon,
69 stateAndStablePtrPrimTyCon,
70 stateAndSynchVarPrimTyCon,
71 stateAndWordPrimTyCon,
90 IMPORT_DELOOPER(TyLoop) ( mkDataCon, mkTupleCon, StrictnessMark(..) )
91 IMPORT_DELOOPER(IdLoop) ( SpecEnv )
98 import Kind ( mkBoxedTypeKind, mkArrowKind )
99 import Name ( mkWiredInTyConName, mkWiredInIdName, mkTupNameStr )
100 import TyCon ( mkDataTyCon, mkTupleTyCon, mkSynTyCon,
103 import Type ( mkTyConTy, applyTyCon, mkSigmaTy, mkTyVarTys,
104 mkFunTy, mkFunTys, maybeAppTyCon,
105 GenType(..), SYN_IE(ThetaType), SYN_IE(TauType) )
106 import TyVar ( tyVarKind, alphaTyVars, alphaTyVar, betaTyVar )
107 import Lex ( mkTupNameStr )
109 import Util ( assoc, panic )
111 nullSpecEnv = error "TysWiredIn:nullSpecEnv = "
112 addOneToSpecEnv = error "TysWiredIn:addOneToSpecEnv = "
113 pc_gen_specs = error "TysWiredIn:pc_gen_specs "
114 mkSpecInfo = error "TysWiredIn:SpecInfo"
116 alpha_tyvar = [alphaTyVar]
118 alpha_beta_tyvars = [alphaTyVar, betaTyVar]
120 pcDataTyCon, pcNewTyCon
121 :: Unique{-TyConKey-} -> Module -> FAST_STRING
122 -> [TyVar] -> [Id] -> TyCon
124 pcDataTyCon = pc_tycon DataType
125 pcNewTyCon = pc_tycon NewType
127 pc_tycon new_or_data key mod str tyvars cons
130 tycon = mkDataTyCon name tycon_kind
131 tyvars [{-no context-}] cons [{-no derivings-}]
133 name = mkWiredInTyConName key mod str tycon
134 tycon_kind = foldr (mkArrowKind . tyVarKind) mkBoxedTypeKind tyvars
136 pcSynTyCon key mod str kind arity tyvars expansion
139 tycon = mkSynTyCon name kind arity tyvars expansion
140 name = mkWiredInTyConName key mod str tycon
142 pcDataCon :: Unique{-DataConKey-} -> Module -> FAST_STRING
143 -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> SpecEnv -> Id
144 pcDataCon key mod str tyvars context arg_tys tycon specenv
147 data_con = mkDataCon name
148 [ NotMarkedStrict | a <- arg_tys ]
149 [ {- no labelled fields -} ]
150 tyvars context arg_tys tycon
151 name = mkWiredInIdName key mod str data_con
153 pcGenerateDataSpecs :: Type -> SpecEnv
154 pcGenerateDataSpecs ty
155 = pc_gen_specs False err err err ty
157 err = panic "PrelUtils:GenerateDataSpecs"
160 %************************************************************************
162 \subsection[TysWiredIn-tuples]{The tuple types}
164 %************************************************************************
167 tupleTyCon :: Arity -> TyCon
171 tycon = mkTupleTyCon uniq name arity
172 uniq = mkTupleTyConUnique arity
173 name = mkWiredInTyConName uniq mod_name (mkTupNameStr arity) tycon
174 mod_name | arity == 0 = pREL_BASE
175 | otherwise = pREL_TUP
177 tupleCon :: Arity -> Id
181 tuple_con = mkTupleCon arity name ty
182 uniq = mkTupleDataConUnique arity
183 name = mkWiredInIdName uniq mod_name (mkTupNameStr arity) tuple_con
184 mod_name | arity == 0 = pREL_BASE
185 | otherwise = pREL_TUP
186 ty = mkSigmaTy tyvars [] (mkFunTys tyvar_tys (applyTyCon tycon tyvar_tys))
187 tyvars = take arity alphaTyVars
188 tyvar_tys = mkTyVarTys tyvars
189 tycon = tupleTyCon arity
191 unitTyCon = tupleTyCon 0
192 pairTyCon = tupleTyCon 2
194 unitDataCon = tupleCon 0
195 pairDataCon = tupleCon 2
199 %************************************************************************
201 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
203 %************************************************************************
206 charTy = mkTyConTy charTyCon
208 charTyCon = pcDataTyCon charTyConKey pREL_BASE SLIT("Char") [] [charDataCon]
209 charDataCon = pcDataCon charDataConKey pREL_BASE SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv
211 stringTy = mkListTy charTy -- convenience only
215 intTy = mkTyConTy intTyCon
217 intTyCon = pcDataTyCon intTyConKey pREL_BASE SLIT("Int") [] [intDataCon]
218 intDataCon = pcDataCon intDataConKey pREL_BASE SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv
222 wordTy = mkTyConTy wordTyCon
224 wordTyCon = pcDataTyCon wordTyConKey fOREIGN SLIT("Word") [] [wordDataCon]
225 wordDataCon = pcDataCon wordDataConKey gHC__ SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv
229 addrTy = mkTyConTy addrTyCon
231 addrTyCon = pcDataTyCon addrTyConKey fOREIGN SLIT("Addr") [] [addrDataCon]
232 addrDataCon = pcDataCon addrDataConKey gHC__ SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv
236 floatTy = mkTyConTy floatTyCon
238 floatTyCon = pcDataTyCon floatTyConKey pREL_BASE SLIT("Float") [] [floatDataCon]
239 floatDataCon = pcDataCon floatDataConKey pREL_BASE SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv
243 doubleTy = mkTyConTy doubleTyCon
245 doubleTyCon = pcDataTyCon doubleTyConKey pREL_BASE SLIT("Double") [] [doubleDataCon]
246 doubleDataCon = pcDataCon doubleDataConKey pREL_BASE SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv
250 mkStateTy ty = applyTyCon stateTyCon [ty]
251 realWorldStateTy = mkStateTy realWorldTy -- a common use
253 stateTyCon = pcDataTyCon stateTyConKey sT_BASE SLIT("State") alpha_tyvar [stateDataCon]
255 = pcDataCon stateDataConKey sT_BASE SLIT("S#")
256 alpha_tyvar [] [mkStatePrimTy alphaTy] stateTyCon nullSpecEnv
261 = pcDataTyCon stablePtrTyConKey fOREIGN SLIT("StablePtr")
262 alpha_tyvar [stablePtrDataCon]
265 = pcDataCon stablePtrDataConKey fOREIGN SLIT("StablePtr")
266 alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon nullSpecEnv
271 = pcDataTyCon foreignObjTyConKey fOREIGN SLIT("ForeignObj")
272 [] [foreignObjDataCon]
275 = pcDataCon foreignObjDataConKey fOREIGN SLIT("ForeignObj")
276 [] [] [foreignObjPrimTy] foreignObjTyCon nullSpecEnv
279 %************************************************************************
281 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
283 %************************************************************************
285 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
287 integerTy :: GenType t u
288 integerTy = mkTyConTy integerTyCon
290 integerTyCon = pcDataTyCon integerTyConKey pREL_BASE SLIT("Integer") [] [integerDataCon]
292 integerDataCon = pcDataCon integerDataConKey pREL_BASE SLIT("J#")
293 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv
296 And the other pairing types:
298 return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey
299 pREL_NUM SLIT("Return2GMPs") [] [return2GMPsDataCon]
302 = pcDataCon return2GMPsDataConKey pREL_NUM SLIT("Return2GMPs") [] []
303 [intPrimTy, intPrimTy, byteArrayPrimTy,
304 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv
306 returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey
307 pREL_NUM SLIT("ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
309 returnIntAndGMPDataCon
310 = pcDataCon returnIntAndGMPDataConKey pREL_NUM SLIT("ReturnIntAndGMP") [] []
311 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv
314 %************************************************************************
316 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
318 %************************************************************************
320 These boring types pair a \tr{State#} with another primitive type.
321 They are not really primitive, so they are given here, not in
324 We fish one of these \tr{StateAnd<blah>#} things with
325 @getStatePairingConInfo@ (given a little way down).
329 = pcDataTyCon stateAndPtrPrimTyConKey sT_BASE SLIT("StateAndPtr#")
330 alpha_beta_tyvars [stateAndPtrPrimDataCon]
331 stateAndPtrPrimDataCon
332 = pcDataCon stateAndPtrPrimDataConKey sT_BASE SLIT("StateAndPtr#")
333 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
334 stateAndPtrPrimTyCon nullSpecEnv
336 stateAndCharPrimTyCon
337 = pcDataTyCon stateAndCharPrimTyConKey sT_BASE SLIT("StateAndChar#")
338 alpha_tyvar [stateAndCharPrimDataCon]
339 stateAndCharPrimDataCon
340 = pcDataCon stateAndCharPrimDataConKey sT_BASE SLIT("StateAndChar#")
341 alpha_tyvar [] [mkStatePrimTy alphaTy, charPrimTy]
342 stateAndCharPrimTyCon nullSpecEnv
345 = pcDataTyCon stateAndIntPrimTyConKey sT_BASE SLIT("StateAndInt#")
346 alpha_tyvar [stateAndIntPrimDataCon]
347 stateAndIntPrimDataCon
348 = pcDataCon stateAndIntPrimDataConKey sT_BASE SLIT("StateAndInt#")
349 alpha_tyvar [] [mkStatePrimTy alphaTy, intPrimTy]
350 stateAndIntPrimTyCon nullSpecEnv
352 stateAndWordPrimTyCon
353 = pcDataTyCon stateAndWordPrimTyConKey sT_BASE SLIT("StateAndWord#")
354 alpha_tyvar [stateAndWordPrimDataCon]
355 stateAndWordPrimDataCon
356 = pcDataCon stateAndWordPrimDataConKey sT_BASE SLIT("StateAndWord#")
357 alpha_tyvar [] [mkStatePrimTy alphaTy, wordPrimTy]
358 stateAndWordPrimTyCon nullSpecEnv
360 stateAndAddrPrimTyCon
361 = pcDataTyCon stateAndAddrPrimTyConKey sT_BASE SLIT("StateAndAddr#")
362 alpha_tyvar [stateAndAddrPrimDataCon]
363 stateAndAddrPrimDataCon
364 = pcDataCon stateAndAddrPrimDataConKey sT_BASE SLIT("StateAndAddr#")
365 alpha_tyvar [] [mkStatePrimTy alphaTy, addrPrimTy]
366 stateAndAddrPrimTyCon nullSpecEnv
368 stateAndStablePtrPrimTyCon
369 = pcDataTyCon stateAndStablePtrPrimTyConKey fOREIGN SLIT("StateAndStablePtr#")
370 alpha_beta_tyvars [stateAndStablePtrPrimDataCon]
371 stateAndStablePtrPrimDataCon
372 = pcDataCon stateAndStablePtrPrimDataConKey fOREIGN SLIT("StateAndStablePtr#")
374 [mkStatePrimTy alphaTy, applyTyCon stablePtrPrimTyCon [betaTy]]
375 stateAndStablePtrPrimTyCon nullSpecEnv
377 stateAndForeignObjPrimTyCon
378 = pcDataTyCon stateAndForeignObjPrimTyConKey fOREIGN SLIT("StateAndForeignObj#")
379 alpha_tyvar [stateAndForeignObjPrimDataCon]
380 stateAndForeignObjPrimDataCon
381 = pcDataCon stateAndForeignObjPrimDataConKey fOREIGN SLIT("StateAndForeignObj#")
383 [mkStatePrimTy alphaTy, applyTyCon foreignObjPrimTyCon []]
384 stateAndForeignObjPrimTyCon nullSpecEnv
386 stateAndFloatPrimTyCon
387 = pcDataTyCon stateAndFloatPrimTyConKey sT_BASE SLIT("StateAndFloat#")
388 alpha_tyvar [stateAndFloatPrimDataCon]
389 stateAndFloatPrimDataCon
390 = pcDataCon stateAndFloatPrimDataConKey sT_BASE SLIT("StateAndFloat#")
391 alpha_tyvar [] [mkStatePrimTy alphaTy, floatPrimTy]
392 stateAndFloatPrimTyCon nullSpecEnv
394 stateAndDoublePrimTyCon
395 = pcDataTyCon stateAndDoublePrimTyConKey sT_BASE SLIT("StateAndDouble#")
396 alpha_tyvar [stateAndDoublePrimDataCon]
397 stateAndDoublePrimDataCon
398 = pcDataCon stateAndDoublePrimDataConKey sT_BASE SLIT("StateAndDouble#")
399 alpha_tyvar [] [mkStatePrimTy alphaTy, doublePrimTy]
400 stateAndDoublePrimTyCon nullSpecEnv
404 stateAndArrayPrimTyCon
405 = pcDataTyCon stateAndArrayPrimTyConKey aRR_BASE SLIT("StateAndArray#")
406 alpha_beta_tyvars [stateAndArrayPrimDataCon]
407 stateAndArrayPrimDataCon
408 = pcDataCon stateAndArrayPrimDataConKey aRR_BASE SLIT("StateAndArray#")
409 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
410 stateAndArrayPrimTyCon nullSpecEnv
412 stateAndMutableArrayPrimTyCon
413 = pcDataTyCon stateAndMutableArrayPrimTyConKey aRR_BASE SLIT("StateAndMutableArray#")
414 alpha_beta_tyvars [stateAndMutableArrayPrimDataCon]
415 stateAndMutableArrayPrimDataCon
416 = pcDataCon stateAndMutableArrayPrimDataConKey aRR_BASE SLIT("StateAndMutableArray#")
417 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
418 stateAndMutableArrayPrimTyCon nullSpecEnv
420 stateAndByteArrayPrimTyCon
421 = pcDataTyCon stateAndByteArrayPrimTyConKey aRR_BASE SLIT("StateAndByteArray#")
422 alpha_tyvar [stateAndByteArrayPrimDataCon]
423 stateAndByteArrayPrimDataCon
424 = pcDataCon stateAndByteArrayPrimDataConKey aRR_BASE SLIT("StateAndByteArray#")
425 alpha_tyvar [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
426 stateAndByteArrayPrimTyCon nullSpecEnv
428 stateAndMutableByteArrayPrimTyCon
429 = pcDataTyCon stateAndMutableByteArrayPrimTyConKey aRR_BASE SLIT("StateAndMutableByteArray#")
430 alpha_tyvar [stateAndMutableByteArrayPrimDataCon]
431 stateAndMutableByteArrayPrimDataCon
432 = pcDataCon stateAndMutableByteArrayPrimDataConKey aRR_BASE SLIT("StateAndMutableByteArray#")
433 alpha_tyvar [] [mkStatePrimTy alphaTy, applyTyCon mutableByteArrayPrimTyCon alpha_ty]
434 stateAndMutableByteArrayPrimTyCon nullSpecEnv
436 stateAndSynchVarPrimTyCon
437 = pcDataTyCon stateAndSynchVarPrimTyConKey cONC_BASE SLIT("StateAndSynchVar#")
438 alpha_beta_tyvars [stateAndSynchVarPrimDataCon]
439 stateAndSynchVarPrimDataCon
440 = pcDataCon stateAndSynchVarPrimDataConKey cONC_BASE SLIT("StateAndSynchVar#")
441 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
442 stateAndSynchVarPrimTyCon nullSpecEnv
445 The ccall-desugaring mechanism uses this function to figure out how to
446 rebox the result. It's really a HACK, especially the part about
447 how many types to drop from \tr{tys_applied}.
450 getStatePairingConInfo
451 :: Type -- primitive type
452 -> (Id, -- state pair constructor for prim type
453 Type) -- type of state pair
455 getStatePairingConInfo prim_ty
456 = case (maybeAppTyCon prim_ty) of
457 Nothing -> panic "getStatePairingConInfo:1"
458 Just (prim_tycon, tys_applied) ->
460 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
461 pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied)
466 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
467 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
468 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
469 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
470 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
471 (foreignObjPrimTyCon, (stateAndForeignObjPrimDataCon, stateAndForeignObjPrimTyCon, 0)),
472 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
473 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
474 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
475 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
476 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
477 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
478 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
479 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
483 %************************************************************************
485 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
487 %************************************************************************
489 This is really just an ordinary synonym, except it is ABSTRACT.
492 mkStateTransformerTy s a = applyTyCon stTyCon [s, a]
494 stTyCon = pcNewTyCon stTyConKey sT_BASE SLIT("ST") alpha_beta_tyvars [stDataCon]
496 stDataCon = pcDataCon stDataConKey sT_BASE SLIT("ST")
497 alpha_beta_tyvars [] [ty] stTyCon nullSpecEnv
499 ty = mkFunTy (mkStateTy alphaTy) (mkTupleTy 2 [betaTy, mkStateTy alphaTy])
502 %************************************************************************
504 \subsection[TysWiredIn-IO]{The @PrimIO@ monadic-I/O type}
506 %************************************************************************
509 mkPrimIoTy a = mkStateTransformerTy realWorldTy a
513 primIoTyConKey sT_BASE SLIT("PrimIO")
514 (mkBoxedTypeKind `mkArrowKind` mkBoxedTypeKind)
515 1 alpha_tyvar (mkPrimIoTy alphaTy)
518 %************************************************************************
520 \subsection[TysWiredIn-Bool]{The @Bool@ type}
522 %************************************************************************
524 An ordinary enumeration type, but deeply wired in. There are no
525 magical operations on @Bool@ (just the regular Prelude code).
527 {\em BEGIN IDLE SPECULATION BY SIMON}
529 This is not the only way to encode @Bool@. A more obvious coding makes
530 @Bool@ just a boxed up version of @Bool#@, like this:
533 data Bool = MkBool Bool#
536 Unfortunately, this doesn't correspond to what the Report says @Bool@
537 looks like! Furthermore, we get slightly less efficient code (I
538 think) with this coding. @gtInt@ would look like this:
541 gtInt :: Int -> Int -> Bool
542 gtInt x y = case x of I# x# ->
544 case (gtIntPrim x# y#) of
548 Notice that the result of the @gtIntPrim@ comparison has to be turned
549 into an integer (here called @b#@), and returned in a @MkBool@ box.
551 The @if@ expression would compile to this:
554 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
557 I think this code is a little less efficient than the previous code,
558 but I'm not certain. At all events, corresponding with the Report is
559 important. The interesting thing is that the language is expressive
560 enough to describe more than one alternative; and that a type doesn't
561 necessarily need to be a straightforwardly boxed version of its
562 primitive counterpart.
564 {\em END IDLE SPECULATION BY SIMON}
567 boolTy = mkTyConTy boolTyCon
569 boolTyCon = pcDataTyCon boolTyConKey pREL_BASE SLIT("Bool") [] [falseDataCon, trueDataCon]
571 falseDataCon = pcDataCon falseDataConKey pREL_BASE SLIT("False") [] [] [] boolTyCon nullSpecEnv
572 trueDataCon = pcDataCon trueDataConKey pREL_BASE SLIT("True") [] [] [] boolTyCon nullSpecEnv
575 %************************************************************************
577 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
579 %************************************************************************
581 Special syntax, deeply wired in, but otherwise an ordinary algebraic
584 data [] a = [] | a : (List a)
586 data (,) a b = (,,) a b
591 mkListTy :: GenType t u -> GenType t u
592 mkListTy ty = applyTyCon listTyCon [ty]
594 alphaListTy = mkSigmaTy alpha_tyvar [] (applyTyCon listTyCon alpha_ty)
596 listTyCon = pcDataTyCon listTyConKey pREL_BASE SLIT("[]")
597 alpha_tyvar [nilDataCon, consDataCon]
599 nilDataCon = pcDataCon nilDataConKey pREL_BASE SLIT("[]") alpha_tyvar [] [] listTyCon
600 (pcGenerateDataSpecs alphaListTy)
601 consDataCon = pcDataCon consDataConKey pREL_BASE SLIT(":")
602 alpha_tyvar [] [alphaTy, applyTyCon listTyCon alpha_ty] listTyCon
603 (pcGenerateDataSpecs alphaListTy)
604 -- Interesting: polymorphic recursion would help here.
605 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
606 -- gets the over-specific type (Type -> Type)
609 %************************************************************************
611 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
613 %************************************************************************
615 The tuple types are definitely magic, because they form an infinite
620 They have a special family of type constructors, of type @TyCon@
621 These contain the tycon arity, but don't require a Unique.
624 They have a special family of constructors, of type
625 @Id@. Again these contain their arity but don't need a Unique.
628 There should be a magic way of generating the info tables and
629 entry code for all tuples.
631 But at the moment we just compile a Haskell source
632 file\srcloc{lib/prelude/...} containing declarations like:
635 data Tuple2 a b = Tup2 a b
636 data Tuple3 a b c = Tup3 a b c
637 data Tuple4 a b c d = Tup4 a b c d
640 The print-names associated with the magic @Id@s for tuple constructors
641 ``just happen'' to be the same as those generated by these
645 The instance environment should have a magic way to know
646 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
647 so on. \ToDo{Not implemented yet.}
650 There should also be a way to generate the appropriate code for each
651 of these instances, but (like the info tables and entry code) it is
652 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
656 mkTupleTy :: Int -> [GenType t u] -> GenType t u
658 mkTupleTy arity tys = applyTyCon (tupleTyCon arity) tys
660 unitTy = mkTupleTy 0 []
663 %************************************************************************
665 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
667 %************************************************************************
669 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
672 mkLiftTy ty = applyTyCon liftTyCon [ty]
676 = mkSigmaTy tvs theta (applyTyCon liftTyCon [tau])
678 (tvs, theta, tau) = splitSigmaTy ty
681 = case (maybeAppDataTyConExpandingDicts tau) of
682 Just (tycon, tys, _) -> tycon == liftTyCon
685 (tvs, theta, tau) = splitSigmaTy ty
689 alphaLiftTy = mkSigmaTy alpha_tyvar [] (applyTyCon liftTyCon alpha_ty)
692 = pcDataTyCon liftTyConKey pREL_BASE SLIT("Lift") alpha_tyvar [liftDataCon]
695 = pcDataCon liftDataConKey pREL_BASE SLIT("Lift")
696 alpha_tyvar [] alpha_ty liftTyCon
697 ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv`
698 (mkSpecInfo [Just realWorldStatePrimTy] 0 bottom))
700 bottom = panic "liftDataCon:State# _RealWorld"