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"
33 getStatePairingConInfo,
64 stateAndAddrPrimTyCon,
65 stateAndArrayPrimTyCon,
66 stateAndByteArrayPrimTyCon,
67 stateAndCharPrimTyCon,
68 stateAndDoublePrimTyCon,
69 stateAndFloatPrimTyCon,
71 stateAndMallocPtrPrimTyCon,
72 stateAndMutableArrayPrimTyCon,
73 stateAndMutableByteArrayPrimTyCon,
75 stateAndStablePtrPrimTyCon,
76 stateAndSynchVarPrimTyCon,
77 stateAndWordPrimTyCon,
98 import TyLoop ( mkDataCon, StrictnessMark(..) )
105 import SpecEnv ( SpecEnv(..) )
106 import Kind ( mkBoxedTypeKind, mkArrowKind )
107 import Name ( mkBuiltinName )
108 import SrcLoc ( mkBuiltinSrcLoc )
109 import TyCon ( mkDataTyCon, mkTupleTyCon, mkSynTyCon,
112 import Type ( mkTyConTy, applyTyCon, mkSynTy, mkSigmaTy,
113 mkFunTys, maybeAppDataTyCon,
114 GenType(..), ThetaType(..), TauType(..) )
115 import TyVar ( tyVarKind, alphaTyVar, betaTyVar )
117 import Util ( assoc, panic )
119 nullSpecEnv = error "TysWiredIn:nullSpecEnv = "
120 addOneToSpecEnv = error "TysWiredIn:addOneToSpecEnv = "
121 pc_gen_specs = error "TysWiredIn:pc_gen_specs "
122 mkSpecInfo = error "TysWiredIn:SpecInfo"
124 pcDataTyCon :: Unique{-TyConKey-} -> Module -> FAST_STRING
125 -> [TyVar] -> [Id] -> TyCon
126 pcDataTyCon 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 charTy = mkTyConTy charTyCon
158 charTyCon = pcDataTyCon charTyConKey pRELUDE_BUILTIN SLIT("Char") [] [charDataCon]
159 charDataCon = pcDataCon charDataConKey pRELUDE_BUILTIN SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv
163 intTy = mkTyConTy intTyCon
165 intTyCon = pcDataTyCon intTyConKey pRELUDE_BUILTIN SLIT("Int") [] [intDataCon]
166 intDataCon = pcDataCon intDataConKey pRELUDE_BUILTIN SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv
170 wordTy = mkTyConTy wordTyCon
172 wordTyCon = pcDataTyCon wordTyConKey pRELUDE_BUILTIN SLIT("_Word") [] [wordDataCon]
173 wordDataCon = pcDataCon wordDataConKey pRELUDE_BUILTIN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv
177 addrTy = mkTyConTy addrTyCon
179 addrTyCon = pcDataTyCon addrTyConKey pRELUDE_BUILTIN SLIT("_Addr") [] [addrDataCon]
180 addrDataCon = pcDataCon addrDataConKey pRELUDE_BUILTIN SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv
184 floatTy = mkTyConTy floatTyCon
186 floatTyCon = pcDataTyCon floatTyConKey pRELUDE_BUILTIN SLIT("Float") [] [floatDataCon]
187 floatDataCon = pcDataCon floatDataConKey pRELUDE_BUILTIN SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv
191 doubleTy = mkTyConTy doubleTyCon
193 doubleTyCon = pcDataTyCon doubleTyConKey pRELUDE_BUILTIN SLIT("Double") [] [doubleDataCon]
194 doubleDataCon = pcDataCon doubleDataConKey pRELUDE_BUILTIN SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv
198 mkStateTy ty = applyTyCon stateTyCon [ty]
199 realWorldStateTy = mkStateTy realWorldTy -- a common use
201 stateTyCon = pcDataTyCon stateTyConKey pRELUDE_BUILTIN SLIT("_State") [alphaTyVar] [stateDataCon]
203 = pcDataCon stateDataConKey pRELUDE_BUILTIN SLIT("S#")
204 [alphaTyVar] [] [mkStatePrimTy alphaTy] stateTyCon nullSpecEnv
209 = pcDataTyCon stablePtrTyConKey gLASGOW_MISC SLIT("_StablePtr")
210 [alphaTyVar] [stablePtrDataCon]
213 = pcDataCon stablePtrDataConKey gLASGOW_MISC SLIT("_StablePtr")
214 [alphaTyVar] [] [applyTyCon stablePtrPrimTyCon [alphaTy]] stablePtrTyCon nullSpecEnv
219 = pcDataTyCon mallocPtrTyConKey gLASGOW_MISC SLIT("_MallocPtr")
220 [] [mallocPtrDataCon]
223 = pcDataCon mallocPtrDataConKey gLASGOW_MISC SLIT("_MallocPtr")
224 [] [] [applyTyCon mallocPtrPrimTyCon []] mallocPtrTyCon nullSpecEnv
227 %************************************************************************
229 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
231 %************************************************************************
233 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
235 integerTy :: GenType t u
236 integerTy = mkTyConTy integerTyCon
238 integerTyCon = pcDataTyCon integerTyConKey pRELUDE_BUILTIN SLIT("Integer") [] [integerDataCon]
240 integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#")
241 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv
244 And the other pairing types:
246 return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey
247 pRELUDE_BUILTIN SLIT("_Return2GMPs") [] [return2GMPsDataCon]
250 = pcDataCon return2GMPsDataConKey pRELUDE_BUILTIN SLIT("_Return2GMPs") [] []
251 [intPrimTy, intPrimTy, byteArrayPrimTy,
252 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv
254 returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey
255 pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
257 returnIntAndGMPDataCon
258 = pcDataCon returnIntAndGMPDataConKey pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] []
259 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv
262 %************************************************************************
264 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
266 %************************************************************************
268 These boring types pair a \tr{State#} with another primitive type.
269 They are not really primitive, so they are given here, not in
272 We fish one of these \tr{StateAnd<blah>#} things with
273 @getStatePairingConInfo@ (given a little way down).
277 = pcDataTyCon stateAndPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
278 [alphaTyVar, betaTyVar] [stateAndPtrPrimDataCon]
279 stateAndPtrPrimDataCon
280 = pcDataCon stateAndPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
281 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, betaTy]
282 stateAndPtrPrimTyCon nullSpecEnv
284 stateAndCharPrimTyCon
285 = pcDataTyCon stateAndCharPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
286 [alphaTyVar] [stateAndCharPrimDataCon]
287 stateAndCharPrimDataCon
288 = pcDataCon stateAndCharPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
289 [alphaTyVar] [] [mkStatePrimTy alphaTy, charPrimTy]
290 stateAndCharPrimTyCon nullSpecEnv
293 = pcDataTyCon stateAndIntPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
294 [alphaTyVar] [stateAndIntPrimDataCon]
295 stateAndIntPrimDataCon
296 = pcDataCon stateAndIntPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
297 [alphaTyVar] [] [mkStatePrimTy alphaTy, intPrimTy]
298 stateAndIntPrimTyCon nullSpecEnv
300 stateAndWordPrimTyCon
301 = pcDataTyCon stateAndWordPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
302 [alphaTyVar] [stateAndWordPrimDataCon]
303 stateAndWordPrimDataCon
304 = pcDataCon stateAndWordPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
305 [alphaTyVar] [] [mkStatePrimTy alphaTy, wordPrimTy]
306 stateAndWordPrimTyCon nullSpecEnv
308 stateAndAddrPrimTyCon
309 = pcDataTyCon stateAndAddrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
310 [alphaTyVar] [stateAndAddrPrimDataCon]
311 stateAndAddrPrimDataCon
312 = pcDataCon stateAndAddrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
313 [alphaTyVar] [] [mkStatePrimTy alphaTy, addrPrimTy]
314 stateAndAddrPrimTyCon nullSpecEnv
316 stateAndStablePtrPrimTyCon
317 = pcDataTyCon stateAndStablePtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
318 [alphaTyVar, betaTyVar] [stateAndStablePtrPrimDataCon]
319 stateAndStablePtrPrimDataCon
320 = pcDataCon stateAndStablePtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
321 [alphaTyVar, betaTyVar] []
322 [mkStatePrimTy alphaTy, applyTyCon stablePtrPrimTyCon [betaTy]]
323 stateAndStablePtrPrimTyCon nullSpecEnv
325 stateAndMallocPtrPrimTyCon
326 = pcDataTyCon stateAndMallocPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
327 [alphaTyVar] [stateAndMallocPtrPrimDataCon]
328 stateAndMallocPtrPrimDataCon
329 = pcDataCon stateAndMallocPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
331 [mkStatePrimTy alphaTy, applyTyCon mallocPtrPrimTyCon []]
332 stateAndMallocPtrPrimTyCon nullSpecEnv
334 stateAndFloatPrimTyCon
335 = pcDataTyCon stateAndFloatPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
336 [alphaTyVar] [stateAndFloatPrimDataCon]
337 stateAndFloatPrimDataCon
338 = pcDataCon stateAndFloatPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
339 [alphaTyVar] [] [mkStatePrimTy alphaTy, floatPrimTy]
340 stateAndFloatPrimTyCon nullSpecEnv
342 stateAndDoublePrimTyCon
343 = pcDataTyCon stateAndDoublePrimTyConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
344 [alphaTyVar] [stateAndDoublePrimDataCon]
345 stateAndDoublePrimDataCon
346 = pcDataCon stateAndDoublePrimDataConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
347 [alphaTyVar] [] [mkStatePrimTy alphaTy, doublePrimTy]
348 stateAndDoublePrimTyCon nullSpecEnv
352 stateAndArrayPrimTyCon
353 = pcDataTyCon stateAndArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
354 [alphaTyVar, betaTyVar] [stateAndArrayPrimDataCon]
355 stateAndArrayPrimDataCon
356 = pcDataCon stateAndArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
357 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
358 stateAndArrayPrimTyCon nullSpecEnv
360 stateAndMutableArrayPrimTyCon
361 = pcDataTyCon stateAndMutableArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
362 [alphaTyVar, betaTyVar] [stateAndMutableArrayPrimDataCon]
363 stateAndMutableArrayPrimDataCon
364 = pcDataCon stateAndMutableArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
365 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
366 stateAndMutableArrayPrimTyCon nullSpecEnv
368 stateAndByteArrayPrimTyCon
369 = pcDataTyCon stateAndByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
370 [alphaTyVar] [stateAndByteArrayPrimDataCon]
371 stateAndByteArrayPrimDataCon
372 = pcDataCon stateAndByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
373 [alphaTyVar] [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
374 stateAndByteArrayPrimTyCon nullSpecEnv
376 stateAndMutableByteArrayPrimTyCon
377 = pcDataTyCon stateAndMutableByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
378 [alphaTyVar] [stateAndMutableByteArrayPrimDataCon]
379 stateAndMutableByteArrayPrimDataCon
380 = pcDataCon stateAndMutableByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
381 [alphaTyVar] [] [mkStatePrimTy alphaTy, applyTyCon mutableByteArrayPrimTyCon [alphaTy]]
382 stateAndMutableByteArrayPrimTyCon nullSpecEnv
384 stateAndSynchVarPrimTyCon
385 = pcDataTyCon stateAndSynchVarPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
386 [alphaTyVar, betaTyVar] [stateAndSynchVarPrimDataCon]
387 stateAndSynchVarPrimDataCon
388 = pcDataCon stateAndSynchVarPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
389 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
390 stateAndSynchVarPrimTyCon nullSpecEnv
393 The ccall-desugaring mechanism uses this function to figure out how to
394 rebox the result. It's really a HACK, especially the part about
395 how many types to drop from \tr{tys_applied}.
398 getStatePairingConInfo
399 :: Type -- primitive type
400 -> (Id, -- state pair constructor for prim type
401 Type) -- type of state pair
403 getStatePairingConInfo prim_ty
404 = case (maybeAppDataTyCon prim_ty) of
405 Nothing -> panic "getStatePairingConInfo:1"
406 Just (prim_tycon, tys_applied, _) ->
408 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
409 pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied)
414 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
415 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
416 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
417 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
418 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
419 (mallocPtrPrimTyCon, (stateAndMallocPtrPrimDataCon, stateAndMallocPtrPrimTyCon, 0)),
420 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
421 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
422 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
423 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
424 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
425 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
426 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
427 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
431 %************************************************************************
433 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
435 %************************************************************************
437 This is really just an ordinary synonym, except it is ABSTRACT.
440 mkStateTransformerTy s a = mkSynTy stTyCon [s, a]
444 ty = mkFunTys [mkStateTy alphaTy] (mkTupleTy 2 [betaTy, mkStateTy alphaTy])
447 (mkBuiltinName stTyConKey gLASGOW_ST SLIT("_ST"))
448 (mkBoxedTypeKind `mkArrowKind` (mkBoxedTypeKind `mkArrowKind` mkBoxedTypeKind))
449 2 [alphaTyVar, betaTyVar]
453 %************************************************************************
455 \subsection[TysWiredIn-IO]{The @PrimIO@ and @IO@ monadic-I/O types}
457 %************************************************************************
459 @PrimIO@ and @IO@ really are just plain synonyms.
462 mkPrimIoTy a = mkSynTy primIoTyCon [a]
466 ty = mkStateTransformerTy realWorldTy alphaTy
468 -- pprTrace "primIOTyCon:" (ppCat [pprType PprDebug ty, ppr PprDebug (typeKind ty)]) $
470 (mkBuiltinName primIoTyConKey pRELUDE_PRIMIO SLIT("PrimIO"))
471 (mkBoxedTypeKind `mkArrowKind` mkBoxedTypeKind)
475 %************************************************************************
477 \subsection[TysWiredIn-Bool]{The @Bool@ type}
479 %************************************************************************
481 An ordinary enumeration type, but deeply wired in. There are no
482 magical operations on @Bool@ (just the regular Prelude code).
484 {\em BEGIN IDLE SPECULATION BY SIMON}
486 This is not the only way to encode @Bool@. A more obvious coding makes
487 @Bool@ just a boxed up version of @Bool#@, like this:
490 data Bool = MkBool Bool#
493 Unfortunately, this doesn't correspond to what the Report says @Bool@
494 looks like! Furthermore, we get slightly less efficient code (I
495 think) with this coding. @gtInt@ would look like this:
498 gtInt :: Int -> Int -> Bool
499 gtInt x y = case x of I# x# ->
501 case (gtIntPrim x# y#) of
505 Notice that the result of the @gtIntPrim@ comparison has to be turned
506 into an integer (here called @b#@), and returned in a @MkBool@ box.
508 The @if@ expression would compile to this:
511 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
514 I think this code is a little less efficient than the previous code,
515 but I'm not certain. At all events, corresponding with the Report is
516 important. The interesting thing is that the language is expressive
517 enough to describe more than one alternative; and that a type doesn't
518 necessarily need to be a straightforwardly boxed version of its
519 primitive counterpart.
521 {\em END IDLE SPECULATION BY SIMON}
524 boolTy = mkTyConTy boolTyCon
526 boolTyCon = pcDataTyCon boolTyConKey pRELUDE_CORE SLIT("Bool") [] [falseDataCon, trueDataCon]
528 falseDataCon = pcDataCon falseDataConKey pRELUDE_CORE SLIT("False") [] [] [] boolTyCon nullSpecEnv
529 trueDataCon = pcDataCon trueDataConKey pRELUDE_CORE SLIT("True") [] [] [] boolTyCon nullSpecEnv
532 %************************************************************************
534 \subsection[TysWiredIn-Ordering]{The @Ordering@ type}
536 %************************************************************************
539 ---------------------------------------------
540 -- data Ordering = LT | EQ | GT deriving ()
541 ---------------------------------------------
543 orderingTy = mkTyConTy orderingTyCon
545 orderingTyCon = pcDataTyCon orderingTyConKey pRELUDE_BUILTIN SLIT("Ordering") []
546 [ltDataCon, eqDataCon, gtDataCon]
548 ltDataCon = pcDataCon ltDataConKey pRELUDE_BUILTIN SLIT("LT") [] [] [] orderingTyCon nullSpecEnv
549 eqDataCon = pcDataCon eqDataConKey pRELUDE_BUILTIN SLIT("EQ") [] [] [] orderingTyCon nullSpecEnv
550 gtDataCon = pcDataCon gtDataConKey pRELUDE_BUILTIN SLIT("GT") [] [] [] orderingTyCon nullSpecEnv
553 %************************************************************************
555 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
557 %************************************************************************
559 Special syntax, deeply wired in, but otherwise an ordinary algebraic
562 data List a = Nil | a : (List a)
563 ToDo: data [] a = [] | a : (List a)
565 data (,,) a b c = (,,) a b c
569 mkListTy :: GenType t u -> GenType t u
570 mkListTy ty = applyTyCon listTyCon [ty]
572 alphaListTy = mkSigmaTy [alphaTyVar] [] (applyTyCon listTyCon [alphaTy])
574 listTyCon = pcDataTyCon listTyConKey pRELUDE_BUILTIN SLIT("[]")
575 [alphaTyVar] [nilDataCon, consDataCon]
577 nilDataCon = pcDataCon nilDataConKey pRELUDE_BUILTIN SLIT("[]") [alphaTyVar] [] [] listTyCon
578 (pcGenerateDataSpecs alphaListTy)
579 consDataCon = pcDataCon consDataConKey pRELUDE_BUILTIN SLIT(":")
580 [alphaTyVar] [] [alphaTy, applyTyCon listTyCon [alphaTy]] listTyCon
581 (pcGenerateDataSpecs alphaListTy)
582 -- Interesting: polymorphic recursion would help here.
583 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
584 -- gets the over-specific type (Type -> Type)
587 %************************************************************************
589 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
591 %************************************************************************
593 The tuple types are definitely magic, because they form an infinite
598 They have a special family of type constructors, of type @TyCon@
599 These contain the tycon arity, but don't require a Unique.
602 They have a special family of constructors, of type
603 @Id@. Again these contain their arity but don't need a Unique.
606 There should be a magic way of generating the info tables and
607 entry code for all tuples.
609 But at the moment we just compile a Haskell source
610 file\srcloc{lib/prelude/...} containing declarations like:
613 data Tuple2 a b = Tup2 a b
614 data Tuple3 a b c = Tup3 a b c
615 data Tuple4 a b c d = Tup4 a b c d
618 The print-names associated with the magic @Id@s for tuple constructors
619 ``just happen'' to be the same as those generated by these
623 The instance environment should have a magic way to know
624 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
625 so on. \ToDo{Not implemented yet.}
628 There should also be a way to generate the appropriate code for each
629 of these instances, but (like the info tables and entry code) it is
630 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
634 mkTupleTy :: Int -> [GenType t u] -> GenType t u
636 mkTupleTy arity tys = applyTyCon (mkTupleTyCon arity) tys
638 unitTy = mkTupleTy 0 []
641 %************************************************************************
643 \subsection[TysWiredIn-Ratios]{@Ratio@ and @Rational@}
645 %************************************************************************
647 ToDo: make this (mostly) go away.
650 rationalTy :: GenType t u
652 mkRatioTy ty = applyTyCon ratioTyCon [ty]
653 rationalTy = mkRatioTy integerTy
655 ratioTyCon = pcDataTyCon ratioTyConKey pRELUDE_RATIO SLIT("Ratio") [alphaTyVar] [ratioDataCon]
657 ratioDataCon = pcDataCon ratioDataConKey pRELUDE_RATIO SLIT(":%")
658 [alphaTyVar] [{-(integralClass,alphaTy)-}] [alphaTy, alphaTy] ratioTyCon nullSpecEnv
659 -- context omitted to match lib/prelude/ defn of "data Ratio ..."
663 (mkBuiltinName rationalTyConKey pRELUDE_RATIO SLIT("Rational"))
665 0 [] rationalTy -- == mkRatioTy integerTy
668 %************************************************************************
670 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
672 %************************************************************************
674 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
677 mkLiftTy ty = applyTyCon liftTyCon [ty]
681 = mkSigmaTy tvs theta (applyTyCon liftTyCon [tau])
683 (tvs, theta, tau) = splitSigmaTy ty
686 = case maybeAppDataTyCon tau of
687 Just (tycon, tys, _) -> tycon == liftTyCon
690 (tvs, theta, tau) = splitSigmaTy ty
694 alphaLiftTy = mkSigmaTy [alphaTyVar] [] (applyTyCon liftTyCon [alphaTy])
697 = pcDataTyCon liftTyConKey pRELUDE_BUILTIN SLIT("_Lift") [alphaTyVar] [liftDataCon]
700 = pcDataCon liftDataConKey pRELUDE_BUILTIN SLIT("_Lift")
701 [alphaTyVar] [] [alphaTy] liftTyCon
702 ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv`
703 (mkSpecInfo [Just realWorldStatePrimTy] 0 bottom))
705 bottom = panic "liftDataCon:State# _RealWorld"
709 %************************************************************************
711 \subsection[TysWiredIn-for-convenience]{Types wired in for convenience (e.g., @String@)}
713 %************************************************************************
716 stringTy = mkListTy charTy
720 (mkBuiltinName stringTyConKey pRELUDE_CORE SLIT("String"))