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,
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,
102 #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ <= 201
103 IMPORT_DELOOPER(TyLoop) ( mkDataCon, mkTupleCon, StrictnessMark(..) )
104 IMPORT_DELOOPER(IdLoop) ( SpecEnv, nullSpecEnv,
105 mkTupleCon, mkDataCon,
108 import {-# SOURCE #-} Id ( Id, mkDataCon, mkTupleCon, StrictnessMark(..) )
109 import {-# SOURCE #-} SpecEnv ( SpecEnv, nullSpecEnv )
117 import FieldLabel () --
118 import Kind ( mkBoxedTypeKind, mkArrowKind )
119 import Name ( mkWiredInTyConName, mkWiredInIdName )
120 import TyCon ( mkDataTyCon, mkTupleTyCon, mkSynTyCon,
123 import BasicTypes ( SYN_IE(Module), NewOrData(..) )
124 import Type ( SYN_IE(Type), mkTyConTy, applyTyCon, mkSigmaTy, mkTyVarTys,
125 mkFunTy, mkFunTys, maybeAppTyCon, maybeAppDataTyCon,
126 GenType(..), SYN_IE(ThetaType), SYN_IE(TauType) )
127 import TyVar ( GenTyVar, SYN_IE(TyVar), tyVarKind, alphaTyVars, alphaTyVar, betaTyVar )
128 import Lex ( mkTupNameStr )
130 import Util ( assoc, panic )
132 --nullSpecEnv = error "TysWiredIn:nullSpecEnv = "
133 addOneToSpecEnv = error "TysWiredIn:addOneToSpecEnv = "
134 pc_gen_specs = error "TysWiredIn:pc_gen_specs "
135 mkSpecInfo = error "TysWiredIn:SpecInfo"
137 alpha_tyvar = [alphaTyVar]
139 alpha_beta_tyvars = [alphaTyVar, betaTyVar]
141 pcDataTyCon, pcNewTyCon
142 :: Unique{-TyConKey-} -> Module -> FAST_STRING
143 -> [TyVar] -> [Id] -> TyCon
145 pcDataTyCon = pc_tycon DataType
146 pcNewTyCon = pc_tycon NewType
148 pc_tycon new_or_data key mod str tyvars cons
151 tycon = mkDataTyCon name tycon_kind
152 tyvars [{-no context-}] cons [{-no derivings-}]
154 name = mkWiredInTyConName key mod str tycon
155 tycon_kind = foldr (mkArrowKind . tyVarKind) mkBoxedTypeKind tyvars
157 pcSynTyCon key mod str kind arity tyvars expansion
160 tycon = mkSynTyCon name kind arity tyvars expansion
161 name = mkWiredInTyConName key mod str tycon
163 pcDataCon :: Unique{-DataConKey-} -> Module -> FAST_STRING
164 -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> SpecEnv -> Id
165 pcDataCon key mod str tyvars context arg_tys tycon specenv
168 data_con = mkDataCon name
169 [ NotMarkedStrict | a <- arg_tys ]
170 [ {- no labelled fields -} ]
171 tyvars context [] [] arg_tys tycon
172 name = mkWiredInIdName key mod str data_con
174 pcGenerateDataSpecs :: Type -> SpecEnv
175 pcGenerateDataSpecs ty
176 = pc_gen_specs --False err err err ty
178 err = panic "PrelUtils:GenerateDataSpecs"
181 %************************************************************************
183 \subsection[TysWiredIn-tuples]{The tuple types}
185 %************************************************************************
188 tupleTyCon :: Arity -> TyCon
192 tycon = mkTupleTyCon uniq name arity
193 uniq = mkTupleTyConUnique arity
194 name = mkWiredInTyConName uniq mod_name (mkTupNameStr arity) tycon
195 mod_name | arity == 0 = pREL_BASE
196 | otherwise = pREL_TUP
198 tupleCon :: Arity -> Id
202 tuple_con = mkTupleCon arity name ty
203 uniq = mkTupleDataConUnique arity
204 name = mkWiredInIdName uniq mod_name (mkTupNameStr arity) tuple_con
205 mod_name | arity == 0 = pREL_BASE
206 | otherwise = pREL_TUP
207 ty = mkSigmaTy tyvars [] (mkFunTys tyvar_tys (applyTyCon tycon tyvar_tys))
208 tyvars = take arity alphaTyVars
209 tyvar_tys = mkTyVarTys tyvars
210 tycon = tupleTyCon arity
212 unitTyCon = tupleTyCon 0
213 pairTyCon = tupleTyCon 2
215 unitDataCon = tupleCon 0
216 pairDataCon = tupleCon 2
220 %************************************************************************
222 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
224 %************************************************************************
227 charTy = mkTyConTy charTyCon
229 charTyCon = pcDataTyCon charTyConKey pREL_BASE SLIT("Char") [] [charDataCon]
230 charDataCon = pcDataCon charDataConKey pREL_BASE SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv
232 stringTy = mkListTy charTy -- convenience only
236 intTy = mkTyConTy intTyCon
238 intTyCon = pcDataTyCon intTyConKey pREL_BASE SLIT("Int") [] [intDataCon]
239 intDataCon = pcDataCon intDataConKey pREL_BASE SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv
241 isIntTy :: GenType (GenTyVar flexi) uvar -> Bool
243 = case (maybeAppDataTyCon ty) of
244 Just (tycon, [], _) -> uniqueOf tycon == intTyConKey
247 inIntRange :: Integer -> Bool -- Tells if an integer lies in the legal range of Ints
248 inIntRange i = (min_int <= i) && (i <= max_int)
250 max_int, min_int :: Integer
251 max_int = toInteger maxInt
252 min_int = toInteger minInt
256 wordTy = mkTyConTy wordTyCon
258 wordTyCon = pcDataTyCon wordTyConKey fOREIGN SLIT("Word") [] [wordDataCon]
259 wordDataCon = pcDataCon wordDataConKey fOREIGN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv
263 addrTy = mkTyConTy addrTyCon
265 addrTyCon = pcDataTyCon addrTyConKey aDDR SLIT("Addr") [] [addrDataCon]
266 addrDataCon = pcDataCon addrDataConKey aDDR SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv
270 floatTy = mkTyConTy floatTyCon
272 floatTyCon = pcDataTyCon floatTyConKey pREL_BASE SLIT("Float") [] [floatDataCon]
273 floatDataCon = pcDataCon floatDataConKey pREL_BASE SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv
277 doubleTy = mkTyConTy doubleTyCon
279 doubleTyCon = pcDataTyCon doubleTyConKey pREL_BASE SLIT("Double") [] [doubleDataCon]
280 doubleDataCon = pcDataCon doubleDataConKey pREL_BASE SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv
284 mkStateTy ty = applyTyCon stateTyCon [ty]
285 realWorldStateTy = mkStateTy realWorldTy -- a common use
287 stateTyCon = pcDataTyCon stateTyConKey sT_BASE SLIT("State") alpha_tyvar [stateDataCon]
289 = pcDataCon stateDataConKey sT_BASE SLIT("S#")
290 alpha_tyvar [] [mkStatePrimTy alphaTy] stateTyCon nullSpecEnv
295 = pcDataTyCon stablePtrTyConKey fOREIGN SLIT("StablePtr")
296 alpha_tyvar [stablePtrDataCon]
299 = pcDataCon stablePtrDataConKey fOREIGN SLIT("StablePtr")
300 alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon nullSpecEnv
305 = pcDataTyCon foreignObjTyConKey fOREIGN SLIT("ForeignObj")
306 [] [foreignObjDataCon]
309 = pcDataCon foreignObjDataConKey fOREIGN SLIT("ForeignObj")
310 [] [] [foreignObjPrimTy] foreignObjTyCon nullSpecEnv
313 %************************************************************************
315 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
317 %************************************************************************
319 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
321 integerTy :: GenType t u
322 integerTy = mkTyConTy integerTyCon
324 integerTyCon = pcDataTyCon integerTyConKey pREL_BASE SLIT("Integer") [] [integerDataCon]
326 integerDataCon = pcDataCon integerDataConKey pREL_BASE SLIT("J#")
327 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv
329 isIntegerTy :: GenType (GenTyVar flexi) uvar -> Bool
331 = case (maybeAppDataTyCon ty) of
332 Just (tycon, [], _) -> uniqueOf tycon == integerTyConKey
336 And the other pairing types:
338 return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey
339 pREL_NUM SLIT("Return2GMPs") [] [return2GMPsDataCon]
342 = pcDataCon return2GMPsDataConKey pREL_NUM SLIT("Return2GMPs") [] []
343 [intPrimTy, intPrimTy, byteArrayPrimTy,
344 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv
346 returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey
347 pREL_NUM SLIT("ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
349 returnIntAndGMPDataCon
350 = pcDataCon returnIntAndGMPDataConKey pREL_NUM SLIT("ReturnIntAndGMP") [] []
351 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv
354 %************************************************************************
356 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
358 %************************************************************************
360 These boring types pair a \tr{State#} with another primitive type.
361 They are not really primitive, so they are given here, not in
364 We fish one of these \tr{StateAnd<blah>#} things with
365 @getStatePairingConInfo@ (given a little way down).
369 = pcDataTyCon stateAndPtrPrimTyConKey sT_BASE SLIT("StateAndPtr#")
370 alpha_beta_tyvars [stateAndPtrPrimDataCon]
371 stateAndPtrPrimDataCon
372 = pcDataCon stateAndPtrPrimDataConKey sT_BASE SLIT("StateAndPtr#")
373 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
374 stateAndPtrPrimTyCon nullSpecEnv
376 stateAndCharPrimTyCon
377 = pcDataTyCon stateAndCharPrimTyConKey sT_BASE SLIT("StateAndChar#")
378 alpha_tyvar [stateAndCharPrimDataCon]
379 stateAndCharPrimDataCon
380 = pcDataCon stateAndCharPrimDataConKey sT_BASE SLIT("StateAndChar#")
381 alpha_tyvar [] [mkStatePrimTy alphaTy, charPrimTy]
382 stateAndCharPrimTyCon nullSpecEnv
385 = pcDataTyCon stateAndIntPrimTyConKey sT_BASE SLIT("StateAndInt#")
386 alpha_tyvar [stateAndIntPrimDataCon]
387 stateAndIntPrimDataCon
388 = pcDataCon stateAndIntPrimDataConKey sT_BASE SLIT("StateAndInt#")
389 alpha_tyvar [] [mkStatePrimTy alphaTy, intPrimTy]
390 stateAndIntPrimTyCon nullSpecEnv
392 stateAndWordPrimTyCon
393 = pcDataTyCon stateAndWordPrimTyConKey sT_BASE SLIT("StateAndWord#")
394 alpha_tyvar [stateAndWordPrimDataCon]
395 stateAndWordPrimDataCon
396 = pcDataCon stateAndWordPrimDataConKey sT_BASE SLIT("StateAndWord#")
397 alpha_tyvar [] [mkStatePrimTy alphaTy, wordPrimTy]
398 stateAndWordPrimTyCon nullSpecEnv
400 stateAndAddrPrimTyCon
401 = pcDataTyCon stateAndAddrPrimTyConKey sT_BASE SLIT("StateAndAddr#")
402 alpha_tyvar [stateAndAddrPrimDataCon]
403 stateAndAddrPrimDataCon
404 = pcDataCon stateAndAddrPrimDataConKey sT_BASE SLIT("StateAndAddr#")
405 alpha_tyvar [] [mkStatePrimTy alphaTy, addrPrimTy]
406 stateAndAddrPrimTyCon nullSpecEnv
408 stateAndStablePtrPrimTyCon
409 = pcDataTyCon stateAndStablePtrPrimTyConKey fOREIGN SLIT("StateAndStablePtr#")
410 alpha_beta_tyvars [stateAndStablePtrPrimDataCon]
411 stateAndStablePtrPrimDataCon
412 = pcDataCon stateAndStablePtrPrimDataConKey fOREIGN SLIT("StateAndStablePtr#")
414 [mkStatePrimTy alphaTy, applyTyCon stablePtrPrimTyCon [betaTy]]
415 stateAndStablePtrPrimTyCon nullSpecEnv
417 stateAndForeignObjPrimTyCon
418 = pcDataTyCon stateAndForeignObjPrimTyConKey fOREIGN SLIT("StateAndForeignObj#")
419 alpha_tyvar [stateAndForeignObjPrimDataCon]
420 stateAndForeignObjPrimDataCon
421 = pcDataCon stateAndForeignObjPrimDataConKey fOREIGN SLIT("StateAndForeignObj#")
423 [mkStatePrimTy alphaTy, applyTyCon foreignObjPrimTyCon []]
424 stateAndForeignObjPrimTyCon nullSpecEnv
426 stateAndFloatPrimTyCon
427 = pcDataTyCon stateAndFloatPrimTyConKey sT_BASE SLIT("StateAndFloat#")
428 alpha_tyvar [stateAndFloatPrimDataCon]
429 stateAndFloatPrimDataCon
430 = pcDataCon stateAndFloatPrimDataConKey sT_BASE SLIT("StateAndFloat#")
431 alpha_tyvar [] [mkStatePrimTy alphaTy, floatPrimTy]
432 stateAndFloatPrimTyCon nullSpecEnv
434 stateAndDoublePrimTyCon
435 = pcDataTyCon stateAndDoublePrimTyConKey sT_BASE SLIT("StateAndDouble#")
436 alpha_tyvar [stateAndDoublePrimDataCon]
437 stateAndDoublePrimDataCon
438 = pcDataCon stateAndDoublePrimDataConKey sT_BASE SLIT("StateAndDouble#")
439 alpha_tyvar [] [mkStatePrimTy alphaTy, doublePrimTy]
440 stateAndDoublePrimTyCon nullSpecEnv
444 stateAndArrayPrimTyCon
445 = pcDataTyCon stateAndArrayPrimTyConKey aRR_BASE SLIT("StateAndArray#")
446 alpha_beta_tyvars [stateAndArrayPrimDataCon]
447 stateAndArrayPrimDataCon
448 = pcDataCon stateAndArrayPrimDataConKey aRR_BASE SLIT("StateAndArray#")
449 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
450 stateAndArrayPrimTyCon nullSpecEnv
452 stateAndMutableArrayPrimTyCon
453 = pcDataTyCon stateAndMutableArrayPrimTyConKey aRR_BASE SLIT("StateAndMutableArray#")
454 alpha_beta_tyvars [stateAndMutableArrayPrimDataCon]
455 stateAndMutableArrayPrimDataCon
456 = pcDataCon stateAndMutableArrayPrimDataConKey aRR_BASE SLIT("StateAndMutableArray#")
457 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
458 stateAndMutableArrayPrimTyCon nullSpecEnv
460 stateAndByteArrayPrimTyCon
461 = pcDataTyCon stateAndByteArrayPrimTyConKey aRR_BASE SLIT("StateAndByteArray#")
462 alpha_tyvar [stateAndByteArrayPrimDataCon]
463 stateAndByteArrayPrimDataCon
464 = pcDataCon stateAndByteArrayPrimDataConKey aRR_BASE SLIT("StateAndByteArray#")
465 alpha_tyvar [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
466 stateAndByteArrayPrimTyCon nullSpecEnv
468 stateAndMutableByteArrayPrimTyCon
469 = pcDataTyCon stateAndMutableByteArrayPrimTyConKey aRR_BASE SLIT("StateAndMutableByteArray#")
470 alpha_tyvar [stateAndMutableByteArrayPrimDataCon]
471 stateAndMutableByteArrayPrimDataCon
472 = pcDataCon stateAndMutableByteArrayPrimDataConKey aRR_BASE SLIT("StateAndMutableByteArray#")
473 alpha_tyvar [] [mkStatePrimTy alphaTy, applyTyCon mutableByteArrayPrimTyCon alpha_ty]
474 stateAndMutableByteArrayPrimTyCon nullSpecEnv
476 stateAndSynchVarPrimTyCon
477 = pcDataTyCon stateAndSynchVarPrimTyConKey cONC_BASE SLIT("StateAndSynchVar#")
478 alpha_beta_tyvars [stateAndSynchVarPrimDataCon]
479 stateAndSynchVarPrimDataCon
480 = pcDataCon stateAndSynchVarPrimDataConKey cONC_BASE SLIT("StateAndSynchVar#")
481 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
482 stateAndSynchVarPrimTyCon nullSpecEnv
485 The ccall-desugaring mechanism uses this function to figure out how to
486 rebox the result. It's really a HACK, especially the part about
487 how many types to drop from \tr{tys_applied}.
490 getStatePairingConInfo
491 :: Type -- primitive type
492 -> (Id, -- state pair constructor for prim type
493 Type) -- type of state pair
495 getStatePairingConInfo prim_ty
496 = case (maybeAppTyCon prim_ty) of
497 Nothing -> panic "getStatePairingConInfo:1"
498 Just (prim_tycon, tys_applied) ->
500 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
501 pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied)
506 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
507 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
508 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
509 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
510 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
511 (foreignObjPrimTyCon, (stateAndForeignObjPrimDataCon, stateAndForeignObjPrimTyCon, 0)),
512 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
513 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
514 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
515 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
516 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
517 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
518 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
519 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
523 %************************************************************************
525 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
527 %************************************************************************
529 The only reason this is wired in is because we have to represent the
533 mkStateTransformerTy s a = applyTyCon stTyCon [s, a]
535 stTyCon = pcNewTyCon stTyConKey sT_BASE SLIT("ST") alpha_beta_tyvars [stDataCon]
537 stDataCon = pcDataCon stDataConKey sT_BASE SLIT("ST")
538 alpha_beta_tyvars [] [ty] stTyCon nullSpecEnv
540 ty = mkFunTy (mkStatePrimTy alphaTy) (mkSTretTy alphaTy betaTy)
542 mkSTretTy alpha beta = applyTyCon stRetTyCon [alpha,beta]
545 = pcDataTyCon stRetTyConKey sT_BASE SLIT("STret")
546 alpha_beta_tyvars [stRetDataCon]
548 = pcDataCon stRetDataConKey sT_BASE SLIT("STret")
549 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
550 stRetTyCon nullSpecEnv
553 %************************************************************************
555 \subsection[TysWiredIn-Bool]{The @Bool@ type}
557 %************************************************************************
559 An ordinary enumeration type, but deeply wired in. There are no
560 magical operations on @Bool@ (just the regular Prelude code).
562 {\em BEGIN IDLE SPECULATION BY SIMON}
564 This is not the only way to encode @Bool@. A more obvious coding makes
565 @Bool@ just a boxed up version of @Bool#@, like this:
568 data Bool = MkBool Bool#
571 Unfortunately, this doesn't correspond to what the Report says @Bool@
572 looks like! Furthermore, we get slightly less efficient code (I
573 think) with this coding. @gtInt@ would look like this:
576 gtInt :: Int -> Int -> Bool
577 gtInt x y = case x of I# x# ->
579 case (gtIntPrim x# y#) of
583 Notice that the result of the @gtIntPrim@ comparison has to be turned
584 into an integer (here called @b#@), and returned in a @MkBool@ box.
586 The @if@ expression would compile to this:
589 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
592 I think this code is a little less efficient than the previous code,
593 but I'm not certain. At all events, corresponding with the Report is
594 important. The interesting thing is that the language is expressive
595 enough to describe more than one alternative; and that a type doesn't
596 necessarily need to be a straightforwardly boxed version of its
597 primitive counterpart.
599 {\em END IDLE SPECULATION BY SIMON}
602 boolTy = mkTyConTy boolTyCon
604 boolTyCon = pcDataTyCon boolTyConKey pREL_BASE SLIT("Bool") [] [falseDataCon, trueDataCon]
606 falseDataCon = pcDataCon falseDataConKey pREL_BASE SLIT("False") [] [] [] boolTyCon nullSpecEnv
607 trueDataCon = pcDataCon trueDataConKey pREL_BASE SLIT("True") [] [] [] boolTyCon nullSpecEnv
610 %************************************************************************
612 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
614 %************************************************************************
616 Special syntax, deeply wired in, but otherwise an ordinary algebraic
619 data [] a = [] | a : (List a)
621 data (,) a b = (,,) a b
626 mkListTy :: GenType t u -> GenType t u
627 mkListTy ty = applyTyCon listTyCon [ty]
629 alphaListTy = mkSigmaTy alpha_tyvar [] (applyTyCon listTyCon alpha_ty)
631 listTyCon = pcDataTyCon listTyConKey pREL_BASE SLIT("[]")
632 alpha_tyvar [nilDataCon, consDataCon]
634 nilDataCon = pcDataCon nilDataConKey pREL_BASE SLIT("[]") alpha_tyvar [] [] listTyCon
635 (pcGenerateDataSpecs alphaListTy)
636 consDataCon = pcDataCon consDataConKey pREL_BASE SLIT(":")
637 alpha_tyvar [] [alphaTy, applyTyCon listTyCon alpha_ty] listTyCon
638 (pcGenerateDataSpecs alphaListTy)
639 -- Interesting: polymorphic recursion would help here.
640 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
641 -- gets the over-specific type (Type -> Type)
644 %************************************************************************
646 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
648 %************************************************************************
650 The tuple types are definitely magic, because they form an infinite
655 They have a special family of type constructors, of type @TyCon@
656 These contain the tycon arity, but don't require a Unique.
659 They have a special family of constructors, of type
660 @Id@. Again these contain their arity but don't need a Unique.
663 There should be a magic way of generating the info tables and
664 entry code for all tuples.
666 But at the moment we just compile a Haskell source
667 file\srcloc{lib/prelude/...} containing declarations like:
670 data Tuple2 a b = Tup2 a b
671 data Tuple3 a b c = Tup3 a b c
672 data Tuple4 a b c d = Tup4 a b c d
675 The print-names associated with the magic @Id@s for tuple constructors
676 ``just happen'' to be the same as those generated by these
680 The instance environment should have a magic way to know
681 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
682 so on. \ToDo{Not implemented yet.}
685 There should also be a way to generate the appropriate code for each
686 of these instances, but (like the info tables and entry code) it is
687 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
691 mkTupleTy :: Int -> [GenType t u] -> GenType t u
693 mkTupleTy arity tys = applyTyCon (tupleTyCon arity) tys
695 unitTy = mkTupleTy 0 []
698 %************************************************************************
700 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
702 %************************************************************************
704 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
707 mkLiftTy ty = applyTyCon liftTyCon [ty]
711 = mkSigmaTy tvs theta (applyTyCon liftTyCon [tau])
713 (tvs, theta, tau) = splitSigmaTy ty
716 = case (maybeAppDataTyConExpandingDicts tau) of
717 Just (tycon, tys, _) -> tycon == liftTyCon
720 (tvs, theta, tau) = splitSigmaTy ty
724 alphaLiftTy = mkSigmaTy alpha_tyvar [] (applyTyCon liftTyCon alpha_ty)
727 = pcDataTyCon liftTyConKey pREL_BASE SLIT("Lift") alpha_tyvar [liftDataCon]
730 = pcDataCon liftDataConKey pREL_BASE SLIT("Lift")
731 alpha_tyvar [] alpha_ty liftTyCon
732 ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv`
733 (mkSpecInfo [Just realWorldStatePrimTy] 0 bottom))
735 bottom = panic "liftDataCon:State# _RealWorld"