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,
55 stateAndAddrPrimTyCon,
56 stateAndArrayPrimTyCon,
57 stateAndByteArrayPrimTyCon,
58 stateAndCharPrimTyCon,
59 stateAndDoublePrimTyCon,
60 stateAndFloatPrimTyCon,
62 stateAndForeignObjPrimTyCon,
63 stateAndMutableArrayPrimTyCon,
64 stateAndMutableByteArrayPrimTyCon,
66 stateAndStablePtrPrimTyCon,
67 stateAndSynchVarPrimTyCon,
68 stateAndWordPrimTyCon,
89 IMPORT_DELOOPER(TyLoop) ( mkDataCon, StrictnessMark(..) )
96 import SpecEnv ( SpecEnv(..) )
97 import Kind ( mkBoxedTypeKind, mkArrowKind )
98 import Name ( mkBuiltinName )
99 import SrcLoc ( mkBuiltinSrcLoc )
100 import TyCon ( mkDataTyCon, mkTupleTyCon, mkSynTyCon,
103 import Type ( mkTyConTy, applyTyCon, mkSigmaTy,
104 mkFunTys, maybeAppTyCon,
105 GenType(..), ThetaType(..), TauType(..) )
106 import TyVar ( tyVarKind, alphaTyVar, betaTyVar )
108 import Util ( assoc, panic )
110 nullSpecEnv = error "TysWiredIn:nullSpecEnv = "
111 addOneToSpecEnv = error "TysWiredIn:addOneToSpecEnv = "
112 pc_gen_specs = error "TysWiredIn:pc_gen_specs "
113 mkSpecInfo = error "TysWiredIn:SpecInfo"
115 alpha_tyvar = [alphaTyVar]
117 alpha_beta_tyvars = [alphaTyVar, betaTyVar]
119 pcDataTyCon, pcNewTyCon
120 :: Unique{-TyConKey-} -> Module -> FAST_STRING
121 -> [TyVar] -> [Id] -> TyCon
123 pcDataTyCon = pc_tycon DataType
124 pcNewTyCon = pc_tycon NewType
126 pc_tycon new_or_data key mod str tyvars cons
127 = mkDataTyCon (mkBuiltinName key mod str) tycon_kind
128 tyvars [{-no context-}] cons [{-no derivings-}]
131 tycon_kind = foldr (mkArrowKind . tyVarKind) mkBoxedTypeKind tyvars
133 pcDataCon :: Unique{-DataConKey-} -> Module -> FAST_STRING
134 -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> SpecEnv -> Id
135 pcDataCon key mod str tyvars context arg_tys tycon specenv
136 = mkDataCon (mkBuiltinName key mod str)
137 [ NotMarkedStrict | a <- arg_tys ]
138 [ {- no labelled fields -} ]
139 tyvars context arg_tys tycon
142 pcGenerateDataSpecs :: Type -> SpecEnv
143 pcGenerateDataSpecs ty
144 = pc_gen_specs False err err err ty
146 err = panic "PrelUtils:GenerateDataSpecs"
149 %************************************************************************
151 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
153 %************************************************************************
156 -- The Void type is represented as a data type with no constructors
157 -- It's a built in type (i.e. there's no way to define it in Haskell
158 -- the nearest would be
160 -- data Void = -- No constructors!
162 -- It's boxed; there is only one value of this
163 -- type, namely "void", whose semantics is just bottom.
164 voidTy = mkTyConTy voidTyCon
166 voidTyCon = pcDataTyCon voidTyConKey pRELUDE_BUILTIN SLIT("Void") [] []
170 charTy = mkTyConTy charTyCon
172 charTyCon = pcDataTyCon charTyConKey pRELUDE_BUILTIN SLIT("Char") [] [charDataCon]
173 charDataCon = pcDataCon charDataConKey pRELUDE_BUILTIN SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv
177 intTy = mkTyConTy intTyCon
179 intTyCon = pcDataTyCon intTyConKey pRELUDE_BUILTIN SLIT("Int") [] [intDataCon]
180 intDataCon = pcDataCon intDataConKey pRELUDE_BUILTIN SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv
184 wordTy = mkTyConTy wordTyCon
186 wordTyCon = pcDataTyCon wordTyConKey pRELUDE_BUILTIN SLIT("_Word") [] [wordDataCon]
187 wordDataCon = pcDataCon wordDataConKey pRELUDE_BUILTIN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv
191 addrTy = mkTyConTy addrTyCon
193 addrTyCon = pcDataTyCon addrTyConKey pRELUDE_BUILTIN SLIT("_Addr") [] [addrDataCon]
194 addrDataCon = pcDataCon addrDataConKey pRELUDE_BUILTIN SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv
198 floatTy = mkTyConTy floatTyCon
200 floatTyCon = pcDataTyCon floatTyConKey pRELUDE_BUILTIN SLIT("Float") [] [floatDataCon]
201 floatDataCon = pcDataCon floatDataConKey pRELUDE_BUILTIN SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv
205 doubleTy = mkTyConTy doubleTyCon
207 doubleTyCon = pcDataTyCon doubleTyConKey pRELUDE_BUILTIN SLIT("Double") [] [doubleDataCon]
208 doubleDataCon = pcDataCon doubleDataConKey pRELUDE_BUILTIN SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv
212 mkStateTy ty = applyTyCon stateTyCon [ty]
213 realWorldStateTy = mkStateTy realWorldTy -- a common use
215 stateTyCon = pcDataTyCon stateTyConKey pRELUDE_BUILTIN SLIT("_State") alpha_tyvar [stateDataCon]
217 = pcDataCon stateDataConKey pRELUDE_BUILTIN SLIT("S#")
218 alpha_tyvar [] [mkStatePrimTy alphaTy] stateTyCon nullSpecEnv
223 = pcDataTyCon stablePtrTyConKey gLASGOW_MISC SLIT("_StablePtr")
224 alpha_tyvar [stablePtrDataCon]
227 = pcDataCon stablePtrDataConKey gLASGOW_MISC SLIT("_StablePtr")
228 alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon nullSpecEnv
233 = pcDataTyCon foreignObjTyConKey gLASGOW_MISC SLIT("_ForeignObj")
234 [] [foreignObjDataCon]
237 = pcDataCon foreignObjDataConKey gLASGOW_MISC SLIT("_ForeignObj")
238 [] [] [foreignObjPrimTy] foreignObjTyCon nullSpecEnv
241 %************************************************************************
243 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
245 %************************************************************************
247 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
249 integerTy :: GenType t u
250 integerTy = mkTyConTy integerTyCon
252 integerTyCon = pcDataTyCon integerTyConKey pRELUDE_BUILTIN SLIT("Integer") [] [integerDataCon]
254 integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#")
255 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv
258 And the other pairing types:
260 return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey
261 pRELUDE_BUILTIN SLIT("_Return2GMPs") [] [return2GMPsDataCon]
264 = pcDataCon return2GMPsDataConKey pRELUDE_BUILTIN SLIT("_Return2GMPs") [] []
265 [intPrimTy, intPrimTy, byteArrayPrimTy,
266 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv
268 returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey
269 pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
271 returnIntAndGMPDataCon
272 = pcDataCon returnIntAndGMPDataConKey pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] []
273 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv
276 %************************************************************************
278 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
280 %************************************************************************
282 These boring types pair a \tr{State#} with another primitive type.
283 They are not really primitive, so they are given here, not in
286 We fish one of these \tr{StateAnd<blah>#} things with
287 @getStatePairingConInfo@ (given a little way down).
291 = pcDataTyCon stateAndPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
292 alpha_beta_tyvars [stateAndPtrPrimDataCon]
293 stateAndPtrPrimDataCon
294 = pcDataCon stateAndPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
295 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
296 stateAndPtrPrimTyCon nullSpecEnv
298 stateAndCharPrimTyCon
299 = pcDataTyCon stateAndCharPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
300 alpha_tyvar [stateAndCharPrimDataCon]
301 stateAndCharPrimDataCon
302 = pcDataCon stateAndCharPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
303 alpha_tyvar [] [mkStatePrimTy alphaTy, charPrimTy]
304 stateAndCharPrimTyCon nullSpecEnv
307 = pcDataTyCon stateAndIntPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
308 alpha_tyvar [stateAndIntPrimDataCon]
309 stateAndIntPrimDataCon
310 = pcDataCon stateAndIntPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
311 alpha_tyvar [] [mkStatePrimTy alphaTy, intPrimTy]
312 stateAndIntPrimTyCon nullSpecEnv
314 stateAndWordPrimTyCon
315 = pcDataTyCon stateAndWordPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
316 alpha_tyvar [stateAndWordPrimDataCon]
317 stateAndWordPrimDataCon
318 = pcDataCon stateAndWordPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
319 alpha_tyvar [] [mkStatePrimTy alphaTy, wordPrimTy]
320 stateAndWordPrimTyCon nullSpecEnv
322 stateAndAddrPrimTyCon
323 = pcDataTyCon stateAndAddrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
324 alpha_tyvar [stateAndAddrPrimDataCon]
325 stateAndAddrPrimDataCon
326 = pcDataCon stateAndAddrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
327 alpha_tyvar [] [mkStatePrimTy alphaTy, addrPrimTy]
328 stateAndAddrPrimTyCon nullSpecEnv
330 stateAndStablePtrPrimTyCon
331 = pcDataTyCon stateAndStablePtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
332 alpha_beta_tyvars [stateAndStablePtrPrimDataCon]
333 stateAndStablePtrPrimDataCon
334 = pcDataCon stateAndStablePtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
336 [mkStatePrimTy alphaTy, applyTyCon stablePtrPrimTyCon [betaTy]]
337 stateAndStablePtrPrimTyCon nullSpecEnv
339 stateAndForeignObjPrimTyCon
340 = pcDataTyCon stateAndForeignObjPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndForeignObj#")
341 alpha_tyvar [stateAndForeignObjPrimDataCon]
342 stateAndForeignObjPrimDataCon
343 = pcDataCon stateAndForeignObjPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndForeignObj#")
345 [mkStatePrimTy alphaTy, applyTyCon foreignObjPrimTyCon []]
346 stateAndForeignObjPrimTyCon nullSpecEnv
348 stateAndFloatPrimTyCon
349 = pcDataTyCon stateAndFloatPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
350 alpha_tyvar [stateAndFloatPrimDataCon]
351 stateAndFloatPrimDataCon
352 = pcDataCon stateAndFloatPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
353 alpha_tyvar [] [mkStatePrimTy alphaTy, floatPrimTy]
354 stateAndFloatPrimTyCon nullSpecEnv
356 stateAndDoublePrimTyCon
357 = pcDataTyCon stateAndDoublePrimTyConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
358 alpha_tyvar [stateAndDoublePrimDataCon]
359 stateAndDoublePrimDataCon
360 = pcDataCon stateAndDoublePrimDataConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
361 alpha_tyvar [] [mkStatePrimTy alphaTy, doublePrimTy]
362 stateAndDoublePrimTyCon nullSpecEnv
366 stateAndArrayPrimTyCon
367 = pcDataTyCon stateAndArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
368 alpha_beta_tyvars [stateAndArrayPrimDataCon]
369 stateAndArrayPrimDataCon
370 = pcDataCon stateAndArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
371 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
372 stateAndArrayPrimTyCon nullSpecEnv
374 stateAndMutableArrayPrimTyCon
375 = pcDataTyCon stateAndMutableArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
376 alpha_beta_tyvars [stateAndMutableArrayPrimDataCon]
377 stateAndMutableArrayPrimDataCon
378 = pcDataCon stateAndMutableArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
379 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
380 stateAndMutableArrayPrimTyCon nullSpecEnv
382 stateAndByteArrayPrimTyCon
383 = pcDataTyCon stateAndByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
384 alpha_tyvar [stateAndByteArrayPrimDataCon]
385 stateAndByteArrayPrimDataCon
386 = pcDataCon stateAndByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
387 alpha_tyvar [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
388 stateAndByteArrayPrimTyCon nullSpecEnv
390 stateAndMutableByteArrayPrimTyCon
391 = pcDataTyCon stateAndMutableByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
392 alpha_tyvar [stateAndMutableByteArrayPrimDataCon]
393 stateAndMutableByteArrayPrimDataCon
394 = pcDataCon stateAndMutableByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
395 alpha_tyvar [] [mkStatePrimTy alphaTy, applyTyCon mutableByteArrayPrimTyCon alpha_ty]
396 stateAndMutableByteArrayPrimTyCon nullSpecEnv
398 stateAndSynchVarPrimTyCon
399 = pcDataTyCon stateAndSynchVarPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
400 alpha_beta_tyvars [stateAndSynchVarPrimDataCon]
401 stateAndSynchVarPrimDataCon
402 = pcDataCon stateAndSynchVarPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
403 alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
404 stateAndSynchVarPrimTyCon nullSpecEnv
407 The ccall-desugaring mechanism uses this function to figure out how to
408 rebox the result. It's really a HACK, especially the part about
409 how many types to drop from \tr{tys_applied}.
412 getStatePairingConInfo
413 :: Type -- primitive type
414 -> (Id, -- state pair constructor for prim type
415 Type) -- type of state pair
417 getStatePairingConInfo prim_ty
418 = case (maybeAppTyCon prim_ty) of
419 Nothing -> panic "getStatePairingConInfo:1"
420 Just (prim_tycon, tys_applied) ->
422 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
423 pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied)
428 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
429 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
430 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
431 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
432 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
433 (foreignObjPrimTyCon, (stateAndForeignObjPrimDataCon, stateAndForeignObjPrimTyCon, 0)),
434 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
435 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
436 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
437 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
438 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
439 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
440 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
441 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
445 %************************************************************************
447 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
449 %************************************************************************
451 This is really just an ordinary synonym, except it is ABSTRACT.
454 mkStateTransformerTy s a = applyTyCon stTyCon [s, a]
456 stTyCon = pcNewTyCon stTyConKey pRELUDE SLIT("_ST") alpha_beta_tyvars [stDataCon]
458 ty = mkFunTys [mkStateTy alphaTy] (mkTupleTy 2 [betaTy, mkStateTy alphaTy])
460 stDataCon = pcDataCon stDataConKey pRELUDE SLIT("_ST")
461 alpha_beta_tyvars [] [ty] stTyCon nullSpecEnv
464 %************************************************************************
466 \subsection[TysWiredIn-IO]{The @PrimIO@ and @IO@ monadic-I/O types}
468 %************************************************************************
470 @PrimIO@ and @IO@ really are just plain synonyms.
473 mkPrimIoTy a = applyTyCon primIoTyCon [a]
475 primIoTyCon = pcNewTyCon primIoTyConKey pRELUDE SLIT("_PrimIO") alpha_tyvar [primIoDataCon]
477 ty = mkFunTys [mkStateTy realWorldTy] (mkTupleTy 2 [alphaTy, mkStateTy realWorldTy])
479 primIoDataCon = pcDataCon primIoDataConKey pRELUDE SLIT("_PrimIO")
480 alpha_tyvar [] [ty] primIoTyCon nullSpecEnv
483 %************************************************************************
485 \subsection[TysWiredIn-Bool]{The @Bool@ type}
487 %************************************************************************
489 An ordinary enumeration type, but deeply wired in. There are no
490 magical operations on @Bool@ (just the regular Prelude code).
492 {\em BEGIN IDLE SPECULATION BY SIMON}
494 This is not the only way to encode @Bool@. A more obvious coding makes
495 @Bool@ just a boxed up version of @Bool#@, like this:
498 data Bool = MkBool Bool#
501 Unfortunately, this doesn't correspond to what the Report says @Bool@
502 looks like! Furthermore, we get slightly less efficient code (I
503 think) with this coding. @gtInt@ would look like this:
506 gtInt :: Int -> Int -> Bool
507 gtInt x y = case x of I# x# ->
509 case (gtIntPrim x# y#) of
513 Notice that the result of the @gtIntPrim@ comparison has to be turned
514 into an integer (here called @b#@), and returned in a @MkBool@ box.
516 The @if@ expression would compile to this:
519 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
522 I think this code is a little less efficient than the previous code,
523 but I'm not certain. At all events, corresponding with the Report is
524 important. The interesting thing is that the language is expressive
525 enough to describe more than one alternative; and that a type doesn't
526 necessarily need to be a straightforwardly boxed version of its
527 primitive counterpart.
529 {\em END IDLE SPECULATION BY SIMON}
532 boolTy = mkTyConTy boolTyCon
534 boolTyCon = pcDataTyCon boolTyConKey pRELUDE SLIT("Bool") [] [falseDataCon, trueDataCon]
536 falseDataCon = pcDataCon falseDataConKey pRELUDE SLIT("False") [] [] [] boolTyCon nullSpecEnv
537 trueDataCon = pcDataCon trueDataConKey pRELUDE SLIT("True") [] [] [] boolTyCon nullSpecEnv
540 %************************************************************************
542 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
544 %************************************************************************
546 Special syntax, deeply wired in, but otherwise an ordinary algebraic
549 data List a = Nil | a : (List a)
550 ToDo: data [] a = [] | a : (List a)
552 data (,,) a b c = (,,) a b c
556 mkListTy :: GenType t u -> GenType t u
557 mkListTy ty = applyTyCon listTyCon [ty]
559 alphaListTy = mkSigmaTy alpha_tyvar [] (applyTyCon listTyCon alpha_ty)
561 listTyCon = pcDataTyCon listTyConKey pRELUDE_BUILTIN SLIT("[]")
562 alpha_tyvar [nilDataCon, consDataCon]
564 nilDataCon = pcDataCon nilDataConKey pRELUDE_BUILTIN SLIT("[]") alpha_tyvar [] [] listTyCon
565 (pcGenerateDataSpecs alphaListTy)
566 consDataCon = pcDataCon consDataConKey pRELUDE_BUILTIN SLIT(":")
567 alpha_tyvar [] [alphaTy, applyTyCon listTyCon alpha_ty] listTyCon
568 (pcGenerateDataSpecs alphaListTy)
569 -- Interesting: polymorphic recursion would help here.
570 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
571 -- gets the over-specific type (Type -> Type)
574 %************************************************************************
576 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
578 %************************************************************************
580 The tuple types are definitely magic, because they form an infinite
585 They have a special family of type constructors, of type @TyCon@
586 These contain the tycon arity, but don't require a Unique.
589 They have a special family of constructors, of type
590 @Id@. Again these contain their arity but don't need a Unique.
593 There should be a magic way of generating the info tables and
594 entry code for all tuples.
596 But at the moment we just compile a Haskell source
597 file\srcloc{lib/prelude/...} containing declarations like:
600 data Tuple2 a b = Tup2 a b
601 data Tuple3 a b c = Tup3 a b c
602 data Tuple4 a b c d = Tup4 a b c d
605 The print-names associated with the magic @Id@s for tuple constructors
606 ``just happen'' to be the same as those generated by these
610 The instance environment should have a magic way to know
611 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
612 so on. \ToDo{Not implemented yet.}
615 There should also be a way to generate the appropriate code for each
616 of these instances, but (like the info tables and entry code) it is
617 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
621 mkTupleTy :: Int -> [GenType t u] -> GenType t u
623 mkTupleTy arity tys = applyTyCon (mkTupleTyCon arity) tys
625 unitTy = mkTupleTy 0 []
628 %************************************************************************
630 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
632 %************************************************************************
634 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
637 mkLiftTy ty = applyTyCon liftTyCon [ty]
641 = mkSigmaTy tvs theta (applyTyCon liftTyCon [tau])
643 (tvs, theta, tau) = splitSigmaTy ty
646 = case (maybeAppDataTyConExpandingDicts tau) of
647 Just (tycon, tys, _) -> tycon == liftTyCon
650 (tvs, theta, tau) = splitSigmaTy ty
654 alphaLiftTy = mkSigmaTy alpha_tyvar [] (applyTyCon liftTyCon alpha_ty)
657 = pcDataTyCon liftTyConKey pRELUDE_BUILTIN SLIT("_Lift") alpha_tyvar [liftDataCon]
660 = pcDataCon liftDataConKey pRELUDE_BUILTIN SLIT("_Lift")
661 alpha_tyvar [] alpha_ty liftTyCon
662 ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv`
663 (mkSpecInfo [Just realWorldStatePrimTy] 0 bottom))
665 bottom = panic "liftDataCon:State# _RealWorld"
669 %************************************************************************
671 \subsection[TysWiredIn-for-convenience]{Types wired in for convenience (e.g., @String@)}
673 %************************************************************************
676 stringTy = mkListTy charTy