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,
91 import TyLoop ( mkDataCon, StrictnessMark(..) )
98 import SpecEnv ( SpecEnv(..) )
99 import NameTypes ( mkPreludeCoreName, mkShortName )
100 import Kind ( mkBoxedTypeKind, mkArrowKind )
101 import SrcLoc ( mkBuiltinSrcLoc )
102 import TyCon ( mkDataTyCon, mkTupleTyCon, mkSynTyCon,
105 import Type ( mkTyConTy, applyTyCon, mkSynTy, mkSigmaTy,
106 mkFunTys, maybeAppDataTyCon,
107 GenType(..), ThetaType(..), TauType(..) )
108 import TyVar ( getTyVarKind, alphaTyVar, betaTyVar )
110 import Util ( assoc, panic )
112 nullSpecEnv = error "TysWiredIn:nullSpecEnv = "
113 addOneToSpecEnv = error "TysWiredIn:addOneToSpecEnv = "
114 pc_gen_specs = error "TysWiredIn:pc_gen_specs "
115 mkSpecInfo = error "TysWiredIn:SpecInfo"
117 pcDataTyCon :: Unique{-TyConKey-} -> FAST_STRING -> FAST_STRING -> [TyVar] -> [Id] -> TyCon
118 pcDataTyCon key mod name tyvars cons
119 = mkDataTyCon key tycon_kind full_name tyvars
120 [{-no context-}] cons [{-no derivings-}]
123 full_name = mkPreludeCoreName mod name
124 tycon_kind = foldr (mkArrowKind . getTyVarKind) mkBoxedTypeKind tyvars
126 pcDataCon :: Unique{-DataConKey-} -> FAST_STRING -> FAST_STRING -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> SpecEnv -> Id
127 pcDataCon key mod name tyvars context arg_tys tycon specenv
128 = mkDataCon key (mkPreludeCoreName mod name)
129 [ NotMarkedStrict | a <- arg_tys ]
130 tyvars context arg_tys tycon
133 pcGenerateDataSpecs :: Type -> SpecEnv
134 pcGenerateDataSpecs ty
135 = pc_gen_specs False err err err ty
137 err = panic "PrelUtils:GenerateDataSpecs"
140 %************************************************************************
142 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
144 %************************************************************************
147 charTy = mkTyConTy charTyCon
149 charTyCon = pcDataTyCon charTyConKey pRELUDE_BUILTIN SLIT("Char") [] [charDataCon]
150 charDataCon = pcDataCon charDataConKey pRELUDE_BUILTIN SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv
154 intTy = mkTyConTy intTyCon
156 intTyCon = pcDataTyCon intTyConKey pRELUDE_BUILTIN SLIT("Int") [] [intDataCon]
157 intDataCon = pcDataCon intDataConKey pRELUDE_BUILTIN SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv
161 wordTy = mkTyConTy wordTyCon
163 wordTyCon = pcDataTyCon wordTyConKey pRELUDE_BUILTIN SLIT("_Word") [] [wordDataCon]
164 wordDataCon = pcDataCon wordDataConKey pRELUDE_BUILTIN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv
168 addrTy = mkTyConTy addrTyCon
170 addrTyCon = pcDataTyCon addrTyConKey pRELUDE_BUILTIN SLIT("_Addr") [] [addrDataCon]
171 addrDataCon = pcDataCon addrDataConKey pRELUDE_BUILTIN SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv
175 floatTy = mkTyConTy floatTyCon
177 floatTyCon = pcDataTyCon floatTyConKey pRELUDE_BUILTIN SLIT("Float") [] [floatDataCon]
178 floatDataCon = pcDataCon floatDataConKey pRELUDE_BUILTIN SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv
182 doubleTy = mkTyConTy doubleTyCon
184 doubleTyCon = pcDataTyCon doubleTyConKey pRELUDE_BUILTIN SLIT("Double") [] [doubleDataCon]
185 doubleDataCon = pcDataCon doubleDataConKey pRELUDE_BUILTIN SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv
189 mkStateTy ty = applyTyCon stateTyCon [ty]
190 realWorldStateTy = mkStateTy realWorldTy -- a common use
192 stateTyCon = pcDataTyCon stateTyConKey pRELUDE_BUILTIN SLIT("_State") [alphaTyVar] [stateDataCon]
194 = pcDataCon stateDataConKey pRELUDE_BUILTIN SLIT("S#")
195 [alphaTyVar] [] [mkStatePrimTy alphaTy] stateTyCon nullSpecEnv
200 = pcDataTyCon stablePtrTyConKey gLASGOW_MISC SLIT("_StablePtr")
201 [alphaTyVar] [stablePtrDataCon]
204 = pcDataCon stablePtrDataConKey gLASGOW_MISC SLIT("_StablePtr")
205 [alphaTyVar] [] [applyTyCon stablePtrPrimTyCon [alphaTy]] stablePtrTyCon nullSpecEnv
210 = pcDataTyCon mallocPtrTyConKey gLASGOW_MISC SLIT("_MallocPtr")
211 [] [mallocPtrDataCon]
214 = pcDataCon mallocPtrDataConKey gLASGOW_MISC SLIT("_MallocPtr")
215 [] [] [applyTyCon mallocPtrPrimTyCon []] mallocPtrTyCon nullSpecEnv
218 %************************************************************************
220 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
222 %************************************************************************
224 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
226 integerTy :: GenType t u
227 integerTy = mkTyConTy integerTyCon
229 integerTyCon = pcDataTyCon integerTyConKey pRELUDE_BUILTIN SLIT("Integer") [] [integerDataCon]
231 integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#")
232 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv
235 And the other pairing types:
237 return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey
238 pRELUDE_BUILTIN SLIT("_Return2GMPs") [] [return2GMPsDataCon]
241 = pcDataCon return2GMPsDataConKey pRELUDE_BUILTIN SLIT("_Return2GMPs") [] []
242 [intPrimTy, intPrimTy, byteArrayPrimTy,
243 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv
245 returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey
246 pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
248 returnIntAndGMPDataCon
249 = pcDataCon returnIntAndGMPDataConKey pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] []
250 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv
253 %************************************************************************
255 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
257 %************************************************************************
259 These boring types pair a \tr{State#} with another primitive type.
260 They are not really primitive, so they are given here, not in
263 We fish one of these \tr{StateAnd<blah>#} things with
264 @getStatePairingConInfo@ (given a little way down).
268 = pcDataTyCon stateAndPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
269 [alphaTyVar, betaTyVar] [stateAndPtrPrimDataCon]
270 stateAndPtrPrimDataCon
271 = pcDataCon stateAndPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
272 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, betaTy]
273 stateAndPtrPrimTyCon nullSpecEnv
275 stateAndCharPrimTyCon
276 = pcDataTyCon stateAndCharPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
277 [alphaTyVar] [stateAndCharPrimDataCon]
278 stateAndCharPrimDataCon
279 = pcDataCon stateAndCharPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
280 [alphaTyVar] [] [mkStatePrimTy alphaTy, charPrimTy]
281 stateAndCharPrimTyCon nullSpecEnv
284 = pcDataTyCon stateAndIntPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
285 [alphaTyVar] [stateAndIntPrimDataCon]
286 stateAndIntPrimDataCon
287 = pcDataCon stateAndIntPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
288 [alphaTyVar] [] [mkStatePrimTy alphaTy, intPrimTy]
289 stateAndIntPrimTyCon nullSpecEnv
291 stateAndWordPrimTyCon
292 = pcDataTyCon stateAndWordPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
293 [alphaTyVar] [stateAndWordPrimDataCon]
294 stateAndWordPrimDataCon
295 = pcDataCon stateAndWordPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
296 [alphaTyVar] [] [mkStatePrimTy alphaTy, wordPrimTy]
297 stateAndWordPrimTyCon nullSpecEnv
299 stateAndAddrPrimTyCon
300 = pcDataTyCon stateAndAddrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
301 [alphaTyVar] [stateAndAddrPrimDataCon]
302 stateAndAddrPrimDataCon
303 = pcDataCon stateAndAddrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
304 [alphaTyVar] [] [mkStatePrimTy alphaTy, addrPrimTy]
305 stateAndAddrPrimTyCon nullSpecEnv
307 stateAndStablePtrPrimTyCon
308 = pcDataTyCon stateAndStablePtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
309 [alphaTyVar, betaTyVar] [stateAndStablePtrPrimDataCon]
310 stateAndStablePtrPrimDataCon
311 = pcDataCon stateAndStablePtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
312 [alphaTyVar, betaTyVar] []
313 [mkStatePrimTy alphaTy, applyTyCon stablePtrPrimTyCon [betaTy]]
314 stateAndStablePtrPrimTyCon nullSpecEnv
316 stateAndMallocPtrPrimTyCon
317 = pcDataTyCon stateAndMallocPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
318 [alphaTyVar] [stateAndMallocPtrPrimDataCon]
319 stateAndMallocPtrPrimDataCon
320 = pcDataCon stateAndMallocPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
322 [mkStatePrimTy alphaTy, applyTyCon mallocPtrPrimTyCon []]
323 stateAndMallocPtrPrimTyCon nullSpecEnv
325 stateAndFloatPrimTyCon
326 = pcDataTyCon stateAndFloatPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
327 [alphaTyVar] [stateAndFloatPrimDataCon]
328 stateAndFloatPrimDataCon
329 = pcDataCon stateAndFloatPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
330 [alphaTyVar] [] [mkStatePrimTy alphaTy, floatPrimTy]
331 stateAndFloatPrimTyCon nullSpecEnv
333 stateAndDoublePrimTyCon
334 = pcDataTyCon stateAndDoublePrimTyConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
335 [alphaTyVar] [stateAndDoublePrimDataCon]
336 stateAndDoublePrimDataCon
337 = pcDataCon stateAndDoublePrimDataConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
338 [alphaTyVar] [] [mkStatePrimTy alphaTy, doublePrimTy]
339 stateAndDoublePrimTyCon nullSpecEnv
343 stateAndArrayPrimTyCon
344 = pcDataTyCon stateAndArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
345 [alphaTyVar, betaTyVar] [stateAndArrayPrimDataCon]
346 stateAndArrayPrimDataCon
347 = pcDataCon stateAndArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
348 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
349 stateAndArrayPrimTyCon nullSpecEnv
351 stateAndMutableArrayPrimTyCon
352 = pcDataTyCon stateAndMutableArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
353 [alphaTyVar, betaTyVar] [stateAndMutableArrayPrimDataCon]
354 stateAndMutableArrayPrimDataCon
355 = pcDataCon stateAndMutableArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
356 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
357 stateAndMutableArrayPrimTyCon nullSpecEnv
359 stateAndByteArrayPrimTyCon
360 = pcDataTyCon stateAndByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
361 [alphaTyVar] [stateAndByteArrayPrimDataCon]
362 stateAndByteArrayPrimDataCon
363 = pcDataCon stateAndByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
364 [alphaTyVar] [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
365 stateAndByteArrayPrimTyCon nullSpecEnv
367 stateAndMutableByteArrayPrimTyCon
368 = pcDataTyCon stateAndMutableByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
369 [alphaTyVar] [stateAndMutableByteArrayPrimDataCon]
370 stateAndMutableByteArrayPrimDataCon
371 = pcDataCon stateAndMutableByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
372 [alphaTyVar] [] [mkStatePrimTy alphaTy, applyTyCon mutableByteArrayPrimTyCon [alphaTy]]
373 stateAndMutableByteArrayPrimTyCon nullSpecEnv
375 stateAndSynchVarPrimTyCon
376 = pcDataTyCon stateAndSynchVarPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
377 [alphaTyVar, betaTyVar] [stateAndSynchVarPrimDataCon]
378 stateAndSynchVarPrimDataCon
379 = pcDataCon stateAndSynchVarPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
380 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
381 stateAndSynchVarPrimTyCon nullSpecEnv
384 The ccall-desugaring mechanism uses this function to figure out how to
385 rebox the result. It's really a HACK, especially the part about
386 how many types to drop from \tr{tys_applied}.
389 getStatePairingConInfo
390 :: Type -- primitive type
391 -> (Id, -- state pair constructor for prim type
392 Type) -- type of state pair
394 getStatePairingConInfo prim_ty
395 = case (maybeAppDataTyCon prim_ty) of
396 Nothing -> panic "getStatePairingConInfo:1"
397 Just (prim_tycon, tys_applied, _) ->
399 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
400 pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied)
405 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
406 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
407 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
408 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
409 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
410 (mallocPtrPrimTyCon, (stateAndMallocPtrPrimDataCon, stateAndMallocPtrPrimTyCon, 0)),
411 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
412 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
413 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
414 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
415 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
416 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
417 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
418 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
422 %************************************************************************
424 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
426 %************************************************************************
428 This is really just an ordinary synonym, except it is ABSTRACT.
431 mkStateTransformerTy s a = mkSynTy stTyCon [s, a]
436 (mkPreludeCoreName gLASGOW_ST SLIT("_ST"))
437 (panic "TysWiredIn.stTyCon:Kind")
439 [alphaTyVar, betaTyVar]
440 (mkFunTys [mkStateTy alphaTy] (mkTupleTy 2 [betaTy, mkStateTy alphaTy]))
443 %************************************************************************
445 \subsection[TysWiredIn-IO]{The @PrimIO@ and @IO@ monadic-I/O types}
447 %************************************************************************
449 @PrimIO@ and @IO@ really are just plain synonyms.
452 mkPrimIoTy a = mkSynTy primIoTyCon [a]
457 (mkPreludeCoreName pRELUDE_PRIMIO SLIT("PrimIO"))
458 (panic "TysWiredIn.primIoTyCon:Kind")
461 (mkStateTransformerTy realWorldTy alphaTy)
464 %************************************************************************
466 \subsection[TysWiredIn-Bool]{The @Bool@ type}
468 %************************************************************************
470 An ordinary enumeration type, but deeply wired in. There are no
471 magical operations on @Bool@ (just the regular Prelude code).
473 {\em BEGIN IDLE SPECULATION BY SIMON}
475 This is not the only way to encode @Bool@. A more obvious coding makes
476 @Bool@ just a boxed up version of @Bool#@, like this:
479 data Bool = MkBool Bool#
482 Unfortunately, this doesn't correspond to what the Report says @Bool@
483 looks like! Furthermore, we get slightly less efficient code (I
484 think) with this coding. @gtInt@ would look like this:
487 gtInt :: Int -> Int -> Bool
488 gtInt x y = case x of I# x# ->
490 case (gtIntPrim x# y#) of
494 Notice that the result of the @gtIntPrim@ comparison has to be turned
495 into an integer (here called @b#@), and returned in a @MkBool@ box.
497 The @if@ expression would compile to this:
500 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
503 I think this code is a little less efficient than the previous code,
504 but I'm not certain. At all events, corresponding with the Report is
505 important. The interesting thing is that the language is expressive
506 enough to describe more than one alternative; and that a type doesn't
507 necessarily need to be a straightforwardly boxed version of its
508 primitive counterpart.
510 {\em END IDLE SPECULATION BY SIMON}
513 boolTy = mkTyConTy boolTyCon
515 boolTyCon = pcDataTyCon boolTyConKey pRELUDE_CORE SLIT("Bool") [] [falseDataCon, trueDataCon]
517 falseDataCon = pcDataCon falseDataConKey pRELUDE_CORE SLIT("False") [] [] [] boolTyCon nullSpecEnv
518 trueDataCon = pcDataCon trueDataConKey pRELUDE_CORE SLIT("True") [] [] [] boolTyCon nullSpecEnv
521 %************************************************************************
523 \subsection[TysWiredIn-Ordering]{The @Ordering@ type}
525 %************************************************************************
528 ---------------------------------------------
529 -- data Ordering = LT | EQ | GT deriving ()
530 ---------------------------------------------
532 orderingTy = mkTyConTy orderingTyCon
534 orderingTyCon = pcDataTyCon orderingTyConKey pRELUDE_BUILTIN SLIT("Ordering") []
535 [ltDataCon, eqDataCon, gtDataCon]
537 ltDataCon = pcDataCon ltDataConKey pRELUDE_BUILTIN SLIT("LT") [] [] [] orderingTyCon nullSpecEnv
538 eqDataCon = pcDataCon eqDataConKey pRELUDE_BUILTIN SLIT("EQ") [] [] [] orderingTyCon nullSpecEnv
539 gtDataCon = pcDataCon gtDataConKey pRELUDE_BUILTIN SLIT("GT") [] [] [] orderingTyCon nullSpecEnv
542 %************************************************************************
544 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
546 %************************************************************************
548 Special syntax, deeply wired in, but otherwise an ordinary algebraic
551 data List a = Nil | a : (List a)
552 ToDo: data [] a = [] | a : (List a)
554 data (,,) a b c = (,,) a b c
558 mkListTy :: GenType t u -> GenType t u
559 mkListTy ty = applyTyCon listTyCon [ty]
561 alphaListTy = mkSigmaTy [alphaTyVar] [] (applyTyCon listTyCon [alphaTy])
563 listTyCon = pcDataTyCon listTyConKey pRELUDE_BUILTIN SLIT("[]")
564 [alphaTyVar] [nilDataCon, consDataCon]
566 nilDataCon = pcDataCon nilDataConKey pRELUDE_BUILTIN SLIT("[]") [alphaTyVar] [] [] listTyCon
567 (pcGenerateDataSpecs alphaListTy)
568 consDataCon = pcDataCon consDataConKey pRELUDE_BUILTIN SLIT(":")
569 [alphaTyVar] [] [alphaTy, applyTyCon listTyCon [alphaTy]] listTyCon
570 (pcGenerateDataSpecs alphaListTy)
571 -- Interesting: polymorphic recursion would help here.
572 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
573 -- gets the over-specific type (Type -> Type)
576 %************************************************************************
578 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
580 %************************************************************************
582 The tuple types are definitely magic, because they form an infinite
587 They have a special family of type constructors, of type @TyCon@
588 These contain the tycon arity, but don't require a Unique.
591 They have a special family of constructors, of type
592 @Id@. Again these contain their arity but don't need a Unique.
595 There should be a magic way of generating the info tables and
596 entry code for all tuples.
598 But at the moment we just compile a Haskell source
599 file\srcloc{lib/prelude/...} containing declarations like:
602 data Tuple2 a b = Tup2 a b
603 data Tuple3 a b c = Tup3 a b c
604 data Tuple4 a b c d = Tup4 a b c d
607 The print-names associated with the magic @Id@s for tuple constructors
608 ``just happen'' to be the same as those generated by these
612 The instance environment should have a magic way to know
613 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
614 so on. \ToDo{Not implemented yet.}
617 There should also be a way to generate the appropriate code for each
618 of these instances, but (like the info tables and entry code) it is
619 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
623 mkTupleTy :: Int -> [GenType t u] -> GenType t u
625 mkTupleTy arity tys = applyTyCon (mkTupleTyCon arity) tys
627 unitTy = mkTupleTy 0 []
630 %************************************************************************
632 \subsection[TysWiredIn-Ratios]{@Ratio@ and @Rational@}
634 %************************************************************************
636 ToDo: make this (mostly) go away.
639 rationalTy :: GenType t u
641 mkRatioTy ty = applyTyCon ratioTyCon [ty]
642 rationalTy = mkRatioTy integerTy
644 ratioTyCon = pcDataTyCon ratioTyConKey pRELUDE_RATIO SLIT("Ratio") [alphaTyVar] [ratioDataCon]
646 ratioDataCon = pcDataCon ratioDataConKey pRELUDE_RATIO SLIT(":%")
647 [alphaTyVar] [{-(integralClass,alphaTy)-}] [alphaTy, alphaTy] ratioTyCon nullSpecEnv
648 -- context omitted to match lib/prelude/ defn of "data Ratio ..."
653 (mkPreludeCoreName pRELUDE_RATIO SLIT("Rational"))
657 rationalTy -- == mkRatioTy integerTy
660 %************************************************************************
662 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
664 %************************************************************************
666 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
669 mkLiftTy ty = applyTyCon liftTyCon [ty]
673 = mkSigmaTy tvs theta (applyTyCon liftTyCon [tau])
675 (tvs, theta, tau) = splitSigmaTy ty
678 = case maybeAppDataTyCon tau of
679 Just (tycon, tys, _) -> tycon == liftTyCon
682 (tvs, theta, tau) = splitSigmaTy ty
686 alphaLiftTy = mkSigmaTy [alphaTyVar] [] (applyTyCon liftTyCon [alphaTy])
689 = pcDataTyCon liftTyConKey pRELUDE_BUILTIN SLIT("_Lift") [alphaTyVar] [liftDataCon]
692 = pcDataCon liftDataConKey pRELUDE_BUILTIN SLIT("_Lift")
693 [alphaTyVar] [] [alphaTy] liftTyCon
694 ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv`
695 (mkSpecInfo [Just realWorldStatePrimTy] 0 bottom))
697 bottom = panic "liftDataCon:State# _RealWorld"
701 %************************************************************************
703 \subsection[TysWiredIn-for-convenience]{Types wired in for convenience (e.g., @String@)}
705 %************************************************************************
708 stringTy = mkListTy charTy
713 (mkPreludeCoreName pRELUDE_CORE SLIT("String"))