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,
54 tupleTyCon, tupleCon, unitTyCon, unitDataCon, pairTyCon, pairDataCon,
64 stateAndAddrPrimTyCon,
65 stateAndArrayPrimTyCon,
66 stateAndByteArrayPrimTyCon,
67 stateAndCharPrimTyCon,
68 stateAndDoublePrimTyCon,
69 stateAndFloatPrimTyCon,
71 stateAndForeignObjPrimTyCon,
72 stateAndMutableArrayPrimTyCon,
73 stateAndMutableByteArrayPrimTyCon,
75 stateAndStablePtrPrimTyCon,
76 stateAndSynchVarPrimTyCon,
77 stateAndWordPrimTyCon,
95 #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ <= 201
96 IMPORT_DELOOPER(TyLoop) ( mkDataCon, mkTupleCon, StrictnessMark(..) )
97 IMPORT_DELOOPER(IdLoop) ( SpecEnv, nullSpecEnv,
98 mkTupleCon, mkDataCon,
101 import {-# SOURCE #-} Id ( Id, mkDataCon, mkTupleCon, StrictnessMark(..) )
102 import {-# SOURCE #-} SpecEnv ( SpecEnv, nullSpecEnv )
110 import FieldLabel () --
111 import Kind ( mkBoxedTypeKind, mkArrowKind )
112 import Name ( mkWiredInTyConName, mkWiredInIdName )
113 import TyCon ( mkDataTyCon, mkTupleTyCon, mkSynTyCon,
116 import BasicTypes ( SYN_IE(Module), NewOrData(..) )
117 import Type ( SYN_IE(Type), mkTyConTy, applyTyCon, mkSigmaTy, mkTyVarTys,
118 mkFunTy, mkFunTys, maybeAppTyCon, maybeAppDataTyCon,
119 GenType(..), SYN_IE(ThetaType), SYN_IE(TauType) )
120 import TyVar ( GenTyVar, SYN_IE(TyVar), tyVarKind, alphaTyVars, alphaTyVar, betaTyVar )
121 import Lex ( mkTupNameStr )
123 import Util ( assoc, panic )
125 --nullSpecEnv = error "TysWiredIn:nullSpecEnv = "
126 addOneToSpecEnv = error "TysWiredIn:addOneToSpecEnv = "
127 pc_gen_specs = error "TysWiredIn:pc_gen_specs "
128 mkSpecInfo = error "TysWiredIn:SpecInfo"
130 alpha_tyvar = [alphaTyVar]
132 alpha_beta_tyvars = [alphaTyVar, betaTyVar]
134 pcDataTyCon, pcNewTyCon
135 :: Unique{-TyConKey-} -> Module -> FAST_STRING
136 -> [TyVar] -> [Id] -> TyCon
138 pcDataTyCon = pc_tycon DataType
139 pcNewTyCon = pc_tycon NewType
141 pc_tycon new_or_data key mod str tyvars cons
144 tycon = mkDataTyCon name tycon_kind
145 tyvars [{-no context-}] cons [{-no derivings-}]
147 name = mkWiredInTyConName key mod str tycon
148 tycon_kind = foldr (mkArrowKind . tyVarKind) mkBoxedTypeKind tyvars
150 pcSynTyCon key mod str kind arity tyvars expansion
153 tycon = mkSynTyCon name kind arity tyvars expansion
154 name = mkWiredInTyConName key mod str tycon
156 pcDataCon :: Unique{-DataConKey-} -> Module -> FAST_STRING
157 -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> SpecEnv -> Id
158 pcDataCon key mod str tyvars context arg_tys tycon specenv
161 data_con = mkDataCon name
162 [ NotMarkedStrict | a <- arg_tys ]
163 [ {- no labelled fields -} ]
164 tyvars context [] [] arg_tys tycon
165 name = mkWiredInIdName key mod str data_con
167 pcGenerateDataSpecs :: Type -> SpecEnv
168 pcGenerateDataSpecs ty
169 = pc_gen_specs --False err err err ty
171 err = panic "PrelUtils:GenerateDataSpecs"
174 %************************************************************************
176 \subsection[TysWiredIn-tuples]{The tuple types}
178 %************************************************************************
181 tupleTyCon :: Arity -> TyCon
185 tycon = mkTupleTyCon uniq name arity
186 uniq = mkTupleTyConUnique arity
187 name = mkWiredInTyConName uniq mod_name (mkTupNameStr arity) tycon
188 mod_name | arity == 0 = pREL_BASE
189 | otherwise = pREL_TUP
191 tupleCon :: Arity -> Id
195 tuple_con = mkTupleCon arity name ty
196 uniq = mkTupleDataConUnique arity
197 name = mkWiredInIdName uniq mod_name (mkTupNameStr arity) tuple_con
198 mod_name | arity == 0 = pREL_BASE
199 | otherwise = pREL_TUP
200 ty = mkSigmaTy tyvars [] (mkFunTys tyvar_tys (applyTyCon tycon tyvar_tys))
201 tyvars = take arity alphaTyVars
202 tyvar_tys = mkTyVarTys tyvars
203 tycon = tupleTyCon arity
205 unitTyCon = tupleTyCon 0
206 pairTyCon = tupleTyCon 2
208 unitDataCon = tupleCon 0
209 pairDataCon = tupleCon 2
213 %************************************************************************
215 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
217 %************************************************************************
220 charTy = mkTyConTy charTyCon
222 charTyCon = pcDataTyCon charTyConKey pREL_BASE SLIT("Char") [] [charDataCon]
223 charDataCon = pcDataCon charDataConKey pREL_BASE SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv
225 stringTy = mkListTy charTy -- convenience only
229 intTy = mkTyConTy intTyCon
231 intTyCon = pcDataTyCon intTyConKey pREL_BASE SLIT("Int") [] [intDataCon]
232 intDataCon = pcDataCon intDataConKey pREL_BASE SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv
234 isIntTy :: GenType (GenTyVar flexi) uvar -> Bool
236 = case (maybeAppDataTyCon ty) of
237 Just (tycon, [], _) -> uniqueOf tycon == intTyConKey
240 inIntRange :: Integer -> Bool -- Tells if an integer lies in the legal range of Ints
241 inIntRange i = (min_int <= i) && (i <= max_int)
243 max_int, min_int :: Integer
244 max_int = toInteger maxInt
245 min_int = toInteger minInt
249 wordTy = mkTyConTy wordTyCon
251 wordTyCon = pcDataTyCon wordTyConKey fOREIGN SLIT("Word") [] [wordDataCon]
252 wordDataCon = pcDataCon wordDataConKey fOREIGN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv
256 addrTy = mkTyConTy addrTyCon
258 addrTyCon = pcDataTyCon addrTyConKey fOREIGN SLIT("Addr") [] [addrDataCon]
259 addrDataCon = pcDataCon addrDataConKey fOREIGN SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv
263 floatTy = mkTyConTy floatTyCon
265 floatTyCon = pcDataTyCon floatTyConKey pREL_BASE SLIT("Float") [] [floatDataCon]
266 floatDataCon = pcDataCon floatDataConKey pREL_BASE SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv
270 doubleTy = mkTyConTy doubleTyCon
272 doubleTyCon = pcDataTyCon doubleTyConKey pREL_BASE SLIT("Double") [] [doubleDataCon]
273 doubleDataCon = pcDataCon doubleDataConKey pREL_BASE SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv
277 mkStateTy ty = applyTyCon stateTyCon [ty]
278 realWorldStateTy = mkStateTy realWorldTy -- a common use
280 stateTyCon = pcDataTyCon stateTyConKey sT_BASE SLIT("State") alpha_tyvar [stateDataCon]
282 = pcDataCon stateDataConKey sT_BASE SLIT("S#")
283 alpha_tyvar [] [mkStatePrimTy alphaTy] stateTyCon nullSpecEnv
288 = pcDataTyCon stablePtrTyConKey fOREIGN SLIT("StablePtr")
289 alpha_tyvar [stablePtrDataCon]
292 = pcDataCon stablePtrDataConKey fOREIGN SLIT("StablePtr")
293 alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon nullSpecEnv
298 = pcDataTyCon foreignObjTyConKey fOREIGN SLIT("ForeignObj")
299 [] [foreignObjDataCon]
302 = pcDataCon foreignObjDataConKey fOREIGN SLIT("ForeignObj")
303 [] [] [foreignObjPrimTy] foreignObjTyCon nullSpecEnv
306 %************************************************************************
308 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
310 %************************************************************************
312 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
314 integerTy :: GenType t u
315 integerTy = mkTyConTy integerTyCon
317 integerTyCon = pcDataTyCon integerTyConKey pREL_BASE SLIT("Integer") [] [integerDataCon]
319 integerDataCon = pcDataCon integerDataConKey pREL_BASE SLIT("J#")
320 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv
322 isIntegerTy :: GenType (GenTyVar flexi) uvar -> Bool
324 = case (maybeAppDataTyCon ty) of
325 Just (tycon, [], _) -> uniqueOf tycon == integerTyConKey
329 And the other pairing types:
331 return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey
332 pREL_NUM SLIT("Return2GMPs") [] [return2GMPsDataCon]
335 = pcDataCon return2GMPsDataConKey pREL_NUM SLIT("Return2GMPs") [] []
336 [intPrimTy, intPrimTy, byteArrayPrimTy,
337 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv
339 returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey
340 pREL_NUM SLIT("ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
342 returnIntAndGMPDataCon
343 = pcDataCon returnIntAndGMPDataConKey pREL_NUM SLIT("ReturnIntAndGMP") [] []
344 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv
347 %************************************************************************
349 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
351 %************************************************************************
353 These boring types pair a \tr{State#} with another primitive type.
354 They are not really primitive, so they are given here, not in
357 We fish one of these \tr{StateAnd<blah>#} things with
358 @getStatePairingConInfo@ (given a little way down).
362 = pcDataTyCon stateAndPtrPrimTyConKey sT_BASE SLIT("StateAndPtr#")
363 alpha_beta_tyvars [stateAndPtrPrimDataCon]
364 stateAndPtrPrimDataCon
365 = pcDataCon stateAndPtrPrimDataConKey sT_BASE SLIT("StateAndPtr#")
366 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
367 stateAndPtrPrimTyCon nullSpecEnv
369 stateAndCharPrimTyCon
370 = pcDataTyCon stateAndCharPrimTyConKey sT_BASE SLIT("StateAndChar#")
371 alpha_tyvar [stateAndCharPrimDataCon]
372 stateAndCharPrimDataCon
373 = pcDataCon stateAndCharPrimDataConKey sT_BASE SLIT("StateAndChar#")
374 alpha_tyvar [] [mkStatePrimTy alphaTy, charPrimTy]
375 stateAndCharPrimTyCon nullSpecEnv
378 = pcDataTyCon stateAndIntPrimTyConKey sT_BASE SLIT("StateAndInt#")
379 alpha_tyvar [stateAndIntPrimDataCon]
380 stateAndIntPrimDataCon
381 = pcDataCon stateAndIntPrimDataConKey sT_BASE SLIT("StateAndInt#")
382 alpha_tyvar [] [mkStatePrimTy alphaTy, intPrimTy]
383 stateAndIntPrimTyCon nullSpecEnv
385 stateAndWordPrimTyCon
386 = pcDataTyCon stateAndWordPrimTyConKey sT_BASE SLIT("StateAndWord#")
387 alpha_tyvar [stateAndWordPrimDataCon]
388 stateAndWordPrimDataCon
389 = pcDataCon stateAndWordPrimDataConKey sT_BASE SLIT("StateAndWord#")
390 alpha_tyvar [] [mkStatePrimTy alphaTy, wordPrimTy]
391 stateAndWordPrimTyCon nullSpecEnv
393 stateAndAddrPrimTyCon
394 = pcDataTyCon stateAndAddrPrimTyConKey sT_BASE SLIT("StateAndAddr#")
395 alpha_tyvar [stateAndAddrPrimDataCon]
396 stateAndAddrPrimDataCon
397 = pcDataCon stateAndAddrPrimDataConKey sT_BASE SLIT("StateAndAddr#")
398 alpha_tyvar [] [mkStatePrimTy alphaTy, addrPrimTy]
399 stateAndAddrPrimTyCon nullSpecEnv
401 stateAndStablePtrPrimTyCon
402 = pcDataTyCon stateAndStablePtrPrimTyConKey fOREIGN SLIT("StateAndStablePtr#")
403 alpha_beta_tyvars [stateAndStablePtrPrimDataCon]
404 stateAndStablePtrPrimDataCon
405 = pcDataCon stateAndStablePtrPrimDataConKey fOREIGN SLIT("StateAndStablePtr#")
407 [mkStatePrimTy alphaTy, applyTyCon stablePtrPrimTyCon [betaTy]]
408 stateAndStablePtrPrimTyCon nullSpecEnv
410 stateAndForeignObjPrimTyCon
411 = pcDataTyCon stateAndForeignObjPrimTyConKey fOREIGN SLIT("StateAndForeignObj#")
412 alpha_tyvar [stateAndForeignObjPrimDataCon]
413 stateAndForeignObjPrimDataCon
414 = pcDataCon stateAndForeignObjPrimDataConKey fOREIGN SLIT("StateAndForeignObj#")
416 [mkStatePrimTy alphaTy, applyTyCon foreignObjPrimTyCon []]
417 stateAndForeignObjPrimTyCon nullSpecEnv
419 stateAndFloatPrimTyCon
420 = pcDataTyCon stateAndFloatPrimTyConKey sT_BASE SLIT("StateAndFloat#")
421 alpha_tyvar [stateAndFloatPrimDataCon]
422 stateAndFloatPrimDataCon
423 = pcDataCon stateAndFloatPrimDataConKey sT_BASE SLIT("StateAndFloat#")
424 alpha_tyvar [] [mkStatePrimTy alphaTy, floatPrimTy]
425 stateAndFloatPrimTyCon nullSpecEnv
427 stateAndDoublePrimTyCon
428 = pcDataTyCon stateAndDoublePrimTyConKey sT_BASE SLIT("StateAndDouble#")
429 alpha_tyvar [stateAndDoublePrimDataCon]
430 stateAndDoublePrimDataCon
431 = pcDataCon stateAndDoublePrimDataConKey sT_BASE SLIT("StateAndDouble#")
432 alpha_tyvar [] [mkStatePrimTy alphaTy, doublePrimTy]
433 stateAndDoublePrimTyCon nullSpecEnv
437 stateAndArrayPrimTyCon
438 = pcDataTyCon stateAndArrayPrimTyConKey aRR_BASE SLIT("StateAndArray#")
439 alpha_beta_tyvars [stateAndArrayPrimDataCon]
440 stateAndArrayPrimDataCon
441 = pcDataCon stateAndArrayPrimDataConKey aRR_BASE SLIT("StateAndArray#")
442 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
443 stateAndArrayPrimTyCon nullSpecEnv
445 stateAndMutableArrayPrimTyCon
446 = pcDataTyCon stateAndMutableArrayPrimTyConKey aRR_BASE SLIT("StateAndMutableArray#")
447 alpha_beta_tyvars [stateAndMutableArrayPrimDataCon]
448 stateAndMutableArrayPrimDataCon
449 = pcDataCon stateAndMutableArrayPrimDataConKey aRR_BASE SLIT("StateAndMutableArray#")
450 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
451 stateAndMutableArrayPrimTyCon nullSpecEnv
453 stateAndByteArrayPrimTyCon
454 = pcDataTyCon stateAndByteArrayPrimTyConKey aRR_BASE SLIT("StateAndByteArray#")
455 alpha_tyvar [stateAndByteArrayPrimDataCon]
456 stateAndByteArrayPrimDataCon
457 = pcDataCon stateAndByteArrayPrimDataConKey aRR_BASE SLIT("StateAndByteArray#")
458 alpha_tyvar [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
459 stateAndByteArrayPrimTyCon nullSpecEnv
461 stateAndMutableByteArrayPrimTyCon
462 = pcDataTyCon stateAndMutableByteArrayPrimTyConKey aRR_BASE SLIT("StateAndMutableByteArray#")
463 alpha_tyvar [stateAndMutableByteArrayPrimDataCon]
464 stateAndMutableByteArrayPrimDataCon
465 = pcDataCon stateAndMutableByteArrayPrimDataConKey aRR_BASE SLIT("StateAndMutableByteArray#")
466 alpha_tyvar [] [mkStatePrimTy alphaTy, applyTyCon mutableByteArrayPrimTyCon alpha_ty]
467 stateAndMutableByteArrayPrimTyCon nullSpecEnv
469 stateAndSynchVarPrimTyCon
470 = pcDataTyCon stateAndSynchVarPrimTyConKey cONC_BASE SLIT("StateAndSynchVar#")
471 alpha_beta_tyvars [stateAndSynchVarPrimDataCon]
472 stateAndSynchVarPrimDataCon
473 = pcDataCon stateAndSynchVarPrimDataConKey cONC_BASE SLIT("StateAndSynchVar#")
474 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
475 stateAndSynchVarPrimTyCon nullSpecEnv
478 The ccall-desugaring mechanism uses this function to figure out how to
479 rebox the result. It's really a HACK, especially the part about
480 how many types to drop from \tr{tys_applied}.
483 getStatePairingConInfo
484 :: Type -- primitive type
485 -> (Id, -- state pair constructor for prim type
486 Type) -- type of state pair
488 getStatePairingConInfo prim_ty
489 = case (maybeAppTyCon prim_ty) of
490 Nothing -> panic "getStatePairingConInfo:1"
491 Just (prim_tycon, tys_applied) ->
493 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
494 pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied)
499 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
500 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
501 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
502 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
503 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
504 (foreignObjPrimTyCon, (stateAndForeignObjPrimDataCon, stateAndForeignObjPrimTyCon, 0)),
505 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
506 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
507 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
508 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
509 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
510 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
511 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
512 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
516 %************************************************************************
518 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
520 %************************************************************************
522 This is really just an ordinary synonym, except it is ABSTRACT.
525 mkStateTransformerTy s a = applyTyCon stTyCon [s, a]
527 stTyCon = pcNewTyCon stTyConKey sT_BASE SLIT("ST") alpha_beta_tyvars [stDataCon]
529 stDataCon = pcDataCon stDataConKey sT_BASE SLIT("ST")
530 alpha_beta_tyvars [] [ty] stTyCon nullSpecEnv
532 ty = mkFunTy (mkStateTy alphaTy) (mkTupleTy 2 [betaTy, mkStateTy alphaTy])
535 %************************************************************************
537 \subsection[TysWiredIn-IO]{The @PrimIO@ monadic-I/O type}
539 %************************************************************************
542 mkPrimIoTy a = mkStateTransformerTy realWorldTy a
546 primIoTyConKey sT_BASE SLIT("PrimIO")
547 (mkBoxedTypeKind `mkArrowKind` mkBoxedTypeKind)
548 1 alpha_tyvar (mkPrimIoTy alphaTy)
551 %************************************************************************
553 \subsection[TysWiredIn-Bool]{The @Bool@ type}
555 %************************************************************************
557 An ordinary enumeration type, but deeply wired in. There are no
558 magical operations on @Bool@ (just the regular Prelude code).
560 {\em BEGIN IDLE SPECULATION BY SIMON}
562 This is not the only way to encode @Bool@. A more obvious coding makes
563 @Bool@ just a boxed up version of @Bool#@, like this:
566 data Bool = MkBool Bool#
569 Unfortunately, this doesn't correspond to what the Report says @Bool@
570 looks like! Furthermore, we get slightly less efficient code (I
571 think) with this coding. @gtInt@ would look like this:
574 gtInt :: Int -> Int -> Bool
575 gtInt x y = case x of I# x# ->
577 case (gtIntPrim x# y#) of
581 Notice that the result of the @gtIntPrim@ comparison has to be turned
582 into an integer (here called @b#@), and returned in a @MkBool@ box.
584 The @if@ expression would compile to this:
587 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
590 I think this code is a little less efficient than the previous code,
591 but I'm not certain. At all events, corresponding with the Report is
592 important. The interesting thing is that the language is expressive
593 enough to describe more than one alternative; and that a type doesn't
594 necessarily need to be a straightforwardly boxed version of its
595 primitive counterpart.
597 {\em END IDLE SPECULATION BY SIMON}
600 boolTy = mkTyConTy boolTyCon
602 boolTyCon = pcDataTyCon boolTyConKey pREL_BASE SLIT("Bool") [] [falseDataCon, trueDataCon]
604 falseDataCon = pcDataCon falseDataConKey pREL_BASE SLIT("False") [] [] [] boolTyCon nullSpecEnv
605 trueDataCon = pcDataCon trueDataConKey pREL_BASE SLIT("True") [] [] [] boolTyCon nullSpecEnv
608 %************************************************************************
610 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
612 %************************************************************************
614 Special syntax, deeply wired in, but otherwise an ordinary algebraic
617 data [] a = [] | a : (List a)
619 data (,) a b = (,,) a b
624 mkListTy :: GenType t u -> GenType t u
625 mkListTy ty = applyTyCon listTyCon [ty]
627 alphaListTy = mkSigmaTy alpha_tyvar [] (applyTyCon listTyCon alpha_ty)
629 listTyCon = pcDataTyCon listTyConKey pREL_BASE SLIT("[]")
630 alpha_tyvar [nilDataCon, consDataCon]
632 nilDataCon = pcDataCon nilDataConKey pREL_BASE SLIT("[]") alpha_tyvar [] [] listTyCon
633 (pcGenerateDataSpecs alphaListTy)
634 consDataCon = pcDataCon consDataConKey pREL_BASE SLIT(":")
635 alpha_tyvar [] [alphaTy, applyTyCon listTyCon alpha_ty] listTyCon
636 (pcGenerateDataSpecs alphaListTy)
637 -- Interesting: polymorphic recursion would help here.
638 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
639 -- gets the over-specific type (Type -> Type)
642 %************************************************************************
644 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
646 %************************************************************************
648 The tuple types are definitely magic, because they form an infinite
653 They have a special family of type constructors, of type @TyCon@
654 These contain the tycon arity, but don't require a Unique.
657 They have a special family of constructors, of type
658 @Id@. Again these contain their arity but don't need a Unique.
661 There should be a magic way of generating the info tables and
662 entry code for all tuples.
664 But at the moment we just compile a Haskell source
665 file\srcloc{lib/prelude/...} containing declarations like:
668 data Tuple2 a b = Tup2 a b
669 data Tuple3 a b c = Tup3 a b c
670 data Tuple4 a b c d = Tup4 a b c d
673 The print-names associated with the magic @Id@s for tuple constructors
674 ``just happen'' to be the same as those generated by these
678 The instance environment should have a magic way to know
679 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
680 so on. \ToDo{Not implemented yet.}
683 There should also be a way to generate the appropriate code for each
684 of these instances, but (like the info tables and entry code) it is
685 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
689 mkTupleTy :: Int -> [GenType t u] -> GenType t u
691 mkTupleTy arity tys = applyTyCon (tupleTyCon arity) tys
693 unitTy = mkTupleTy 0 []
696 %************************************************************************
698 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
700 %************************************************************************
702 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
705 mkLiftTy ty = applyTyCon liftTyCon [ty]
709 = mkSigmaTy tvs theta (applyTyCon liftTyCon [tau])
711 (tvs, theta, tau) = splitSigmaTy ty
714 = case (maybeAppDataTyConExpandingDicts tau) of
715 Just (tycon, tys, _) -> tycon == liftTyCon
718 (tvs, theta, tau) = splitSigmaTy ty
722 alphaLiftTy = mkSigmaTy alpha_tyvar [] (applyTyCon liftTyCon alpha_ty)
725 = pcDataTyCon liftTyConKey pREL_BASE SLIT("Lift") alpha_tyvar [liftDataCon]
728 = pcDataCon liftDataConKey pREL_BASE SLIT("Lift")
729 alpha_tyvar [] alpha_ty liftTyCon
730 ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv`
731 (mkSpecInfo [Just realWorldStatePrimTy] 0 bottom))
733 bottom = panic "liftDataCon:State# _RealWorld"