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,
103 ConsVisible(..), NewOrData(..), TyCon )
104 import Type ( mkTyConTy, applyTyCon, mkSynTy, mkSigmaTy,
105 mkFunTys, maybeAppDataTyCon,
106 GenType(..), ThetaType(..), TauType(..) )
107 import TyVar ( getTyVarKind, alphaTyVar, betaTyVar )
109 import Util ( assoc, panic )
111 nullSpecEnv = error "TysWiredIn:nullSpecEnv = "
112 addOneToSpecEnv = error "TysWiredIn:addOneToSpecEnv = "
113 pc_gen_specs = error "TysWiredIn:pc_gen_specs "
114 mkSpecInfo = error "TysWiredIn:SpecInfo"
116 pcDataTyCon :: Unique{-TyConKey-} -> FAST_STRING -> FAST_STRING -> [TyVar] -> [Id] -> TyCon
117 pcDataTyCon key mod name tyvars cons
118 = mkDataTyCon key tycon_kind full_name tyvars
119 [{-no context-}] cons [{-no derivings-}]
122 full_name = mkPreludeCoreName mod name
123 tycon_kind = foldr (mkArrowKind . getTyVarKind) mkBoxedTypeKind tyvars
125 pcDataCon :: Unique{-DataConKey-} -> FAST_STRING -> FAST_STRING -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> SpecEnv -> Id
126 pcDataCon key mod name tyvars context arg_tys tycon specenv
127 = mkDataCon key (mkPreludeCoreName mod name)
128 [ NotMarkedStrict | a <- arg_tys ]
129 tyvars context arg_tys tycon
132 pcGenerateDataSpecs :: Type -> SpecEnv
133 pcGenerateDataSpecs ty
134 = pc_gen_specs False err err err ty
136 err = panic "PrelUtils:GenerateDataSpecs"
139 %************************************************************************
141 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
143 %************************************************************************
146 charTy = mkTyConTy charTyCon
148 charTyCon = pcDataTyCon charTyConKey pRELUDE_BUILTIN SLIT("Char") [] [charDataCon]
149 charDataCon = pcDataCon charDataConKey pRELUDE_BUILTIN SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv
153 intTy = mkTyConTy intTyCon
155 intTyCon = pcDataTyCon intTyConKey pRELUDE_BUILTIN SLIT("Int") [] [intDataCon]
156 intDataCon = pcDataCon intDataConKey pRELUDE_BUILTIN SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv
160 wordTy = mkTyConTy wordTyCon
162 wordTyCon = pcDataTyCon wordTyConKey pRELUDE_BUILTIN SLIT("_Word") [] [wordDataCon]
163 wordDataCon = pcDataCon wordDataConKey pRELUDE_BUILTIN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv
167 addrTy = mkTyConTy addrTyCon
169 addrTyCon = pcDataTyCon addrTyConKey pRELUDE_BUILTIN SLIT("_Addr") [] [addrDataCon]
170 addrDataCon = pcDataCon addrDataConKey pRELUDE_BUILTIN SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv
174 floatTy = mkTyConTy floatTyCon
176 floatTyCon = pcDataTyCon floatTyConKey pRELUDE_BUILTIN SLIT("Float") [] [floatDataCon]
177 floatDataCon = pcDataCon floatDataConKey pRELUDE_BUILTIN SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv
181 doubleTy = mkTyConTy doubleTyCon
183 doubleTyCon = pcDataTyCon doubleTyConKey pRELUDE_BUILTIN SLIT("Double") [] [doubleDataCon]
184 doubleDataCon = pcDataCon doubleDataConKey pRELUDE_BUILTIN SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv
188 mkStateTy ty = applyTyCon stateTyCon [ty]
189 realWorldStateTy = mkStateTy realWorldTy -- a common use
191 stateTyCon = pcDataTyCon stateTyConKey pRELUDE_BUILTIN SLIT("_State") [alphaTyVar] [stateDataCon]
193 = pcDataCon stateDataConKey pRELUDE_BUILTIN SLIT("S#")
194 [alphaTyVar] [] [mkStatePrimTy alphaTy] stateTyCon nullSpecEnv
199 = pcDataTyCon stablePtrTyConKey gLASGOW_MISC SLIT("_StablePtr")
200 [alphaTyVar] [stablePtrDataCon]
203 = pcDataCon stablePtrDataConKey gLASGOW_MISC SLIT("_StablePtr")
204 [alphaTyVar] [] [applyTyCon stablePtrPrimTyCon [alphaTy]] stablePtrTyCon nullSpecEnv
209 = pcDataTyCon mallocPtrTyConKey gLASGOW_MISC SLIT("_MallocPtr")
210 [] [mallocPtrDataCon]
213 = pcDataCon mallocPtrDataConKey gLASGOW_MISC SLIT("_MallocPtr")
214 [] [] [applyTyCon mallocPtrPrimTyCon []] mallocPtrTyCon nullSpecEnv
217 %************************************************************************
219 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
221 %************************************************************************
223 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
225 integerTy :: GenType t u
226 integerTy = mkTyConTy integerTyCon
228 integerTyCon = pcDataTyCon integerTyConKey pRELUDE_BUILTIN SLIT("Integer") [] [integerDataCon]
230 integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#")
231 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv
234 And the other pairing types:
236 return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey
237 pRELUDE_BUILTIN SLIT("_Return2GMPs") [] [return2GMPsDataCon]
240 = pcDataCon return2GMPsDataConKey pRELUDE_BUILTIN SLIT("_Return2GMPs") [] []
241 [intPrimTy, intPrimTy, byteArrayPrimTy,
242 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv
244 returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey
245 pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
247 returnIntAndGMPDataCon
248 = pcDataCon returnIntAndGMPDataConKey pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] []
249 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv
252 %************************************************************************
254 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
256 %************************************************************************
258 These boring types pair a \tr{State#} with another primitive type.
259 They are not really primitive, so they are given here, not in
262 We fish one of these \tr{StateAnd<blah>#} things with
263 @getStatePairingConInfo@ (given a little way down).
267 = pcDataTyCon stateAndPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
268 [alphaTyVar, betaTyVar] [stateAndPtrPrimDataCon]
269 stateAndPtrPrimDataCon
270 = pcDataCon stateAndPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
271 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, betaTy]
272 stateAndPtrPrimTyCon nullSpecEnv
274 stateAndCharPrimTyCon
275 = pcDataTyCon stateAndCharPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
276 [alphaTyVar] [stateAndCharPrimDataCon]
277 stateAndCharPrimDataCon
278 = pcDataCon stateAndCharPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
279 [alphaTyVar] [] [mkStatePrimTy alphaTy, charPrimTy]
280 stateAndCharPrimTyCon nullSpecEnv
283 = pcDataTyCon stateAndIntPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
284 [alphaTyVar] [stateAndIntPrimDataCon]
285 stateAndIntPrimDataCon
286 = pcDataCon stateAndIntPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
287 [alphaTyVar] [] [mkStatePrimTy alphaTy, intPrimTy]
288 stateAndIntPrimTyCon nullSpecEnv
290 stateAndWordPrimTyCon
291 = pcDataTyCon stateAndWordPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
292 [alphaTyVar] [stateAndWordPrimDataCon]
293 stateAndWordPrimDataCon
294 = pcDataCon stateAndWordPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
295 [alphaTyVar] [] [mkStatePrimTy alphaTy, wordPrimTy]
296 stateAndWordPrimTyCon nullSpecEnv
298 stateAndAddrPrimTyCon
299 = pcDataTyCon stateAndAddrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
300 [alphaTyVar] [stateAndAddrPrimDataCon]
301 stateAndAddrPrimDataCon
302 = pcDataCon stateAndAddrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
303 [alphaTyVar] [] [mkStatePrimTy alphaTy, addrPrimTy]
304 stateAndAddrPrimTyCon nullSpecEnv
306 stateAndStablePtrPrimTyCon
307 = pcDataTyCon stateAndStablePtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
308 [alphaTyVar, betaTyVar] [stateAndStablePtrPrimDataCon]
309 stateAndStablePtrPrimDataCon
310 = pcDataCon stateAndStablePtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
311 [alphaTyVar, betaTyVar] []
312 [mkStatePrimTy alphaTy, applyTyCon stablePtrPrimTyCon [betaTy]]
313 stateAndStablePtrPrimTyCon nullSpecEnv
315 stateAndMallocPtrPrimTyCon
316 = pcDataTyCon stateAndMallocPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
317 [alphaTyVar] [stateAndMallocPtrPrimDataCon]
318 stateAndMallocPtrPrimDataCon
319 = pcDataCon stateAndMallocPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
321 [mkStatePrimTy alphaTy, applyTyCon mallocPtrPrimTyCon []]
322 stateAndMallocPtrPrimTyCon nullSpecEnv
324 stateAndFloatPrimTyCon
325 = pcDataTyCon stateAndFloatPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
326 [alphaTyVar] [stateAndFloatPrimDataCon]
327 stateAndFloatPrimDataCon
328 = pcDataCon stateAndFloatPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
329 [alphaTyVar] [] [mkStatePrimTy alphaTy, floatPrimTy]
330 stateAndFloatPrimTyCon nullSpecEnv
332 stateAndDoublePrimTyCon
333 = pcDataTyCon stateAndDoublePrimTyConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
334 [alphaTyVar] [stateAndDoublePrimDataCon]
335 stateAndDoublePrimDataCon
336 = pcDataCon stateAndDoublePrimDataConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
337 [alphaTyVar] [] [mkStatePrimTy alphaTy, doublePrimTy]
338 stateAndDoublePrimTyCon nullSpecEnv
342 stateAndArrayPrimTyCon
343 = pcDataTyCon stateAndArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
344 [alphaTyVar, betaTyVar] [stateAndArrayPrimDataCon]
345 stateAndArrayPrimDataCon
346 = pcDataCon stateAndArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
347 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
348 stateAndArrayPrimTyCon nullSpecEnv
350 stateAndMutableArrayPrimTyCon
351 = pcDataTyCon stateAndMutableArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
352 [alphaTyVar, betaTyVar] [stateAndMutableArrayPrimDataCon]
353 stateAndMutableArrayPrimDataCon
354 = pcDataCon stateAndMutableArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
355 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
356 stateAndMutableArrayPrimTyCon nullSpecEnv
358 stateAndByteArrayPrimTyCon
359 = pcDataTyCon stateAndByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
360 [alphaTyVar] [stateAndByteArrayPrimDataCon]
361 stateAndByteArrayPrimDataCon
362 = pcDataCon stateAndByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
363 [alphaTyVar] [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
364 stateAndByteArrayPrimTyCon nullSpecEnv
366 stateAndMutableByteArrayPrimTyCon
367 = pcDataTyCon stateAndMutableByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
368 [alphaTyVar] [stateAndMutableByteArrayPrimDataCon]
369 stateAndMutableByteArrayPrimDataCon
370 = pcDataCon stateAndMutableByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
371 [alphaTyVar] [] [mkStatePrimTy alphaTy, applyTyCon mutableByteArrayPrimTyCon [alphaTy]]
372 stateAndMutableByteArrayPrimTyCon nullSpecEnv
374 stateAndSynchVarPrimTyCon
375 = pcDataTyCon stateAndSynchVarPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
376 [alphaTyVar, betaTyVar] [stateAndSynchVarPrimDataCon]
377 stateAndSynchVarPrimDataCon
378 = pcDataCon stateAndSynchVarPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
379 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
380 stateAndSynchVarPrimTyCon nullSpecEnv
383 The ccall-desugaring mechanism uses this function to figure out how to
384 rebox the result. It's really a HACK, especially the part about
385 how many types to drop from \tr{tys_applied}.
388 getStatePairingConInfo
389 :: Type -- primitive type
390 -> (Id, -- state pair constructor for prim type
391 Type) -- type of state pair
393 getStatePairingConInfo prim_ty
394 = case (maybeAppDataTyCon prim_ty) of
395 Nothing -> panic "getStatePairingConInfo:1"
396 Just (prim_tycon, tys_applied, _) ->
398 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
399 pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied)
404 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
405 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
406 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
407 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
408 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
409 (mallocPtrPrimTyCon, (stateAndMallocPtrPrimDataCon, stateAndMallocPtrPrimTyCon, 0)),
410 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
411 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
412 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
413 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
414 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
415 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
416 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
417 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
421 %************************************************************************
423 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
425 %************************************************************************
427 This is really just an ordinary synonym, except it is ABSTRACT.
430 mkStateTransformerTy s a = mkSynTy stTyCon [s, a]
435 (mkPreludeCoreName gLASGOW_ST SLIT("_ST"))
436 (panic "TysWiredIn.stTyCon:Kind")
438 [alphaTyVar, betaTyVar]
439 (mkFunTys [mkStateTy alphaTy] (mkTupleTy 2 [betaTy, mkStateTy alphaTy]))
442 %************************************************************************
444 \subsection[TysWiredIn-IO]{The @PrimIO@ and @IO@ monadic-I/O types}
446 %************************************************************************
448 @PrimIO@ and @IO@ really are just plain synonyms.
451 mkPrimIoTy a = mkSynTy primIoTyCon [a]
456 (mkPreludeCoreName pRELUDE_PRIMIO SLIT("PrimIO"))
457 (panic "TysWiredIn.primIoTyCon:Kind")
460 (mkStateTransformerTy realWorldTy alphaTy)
463 %************************************************************************
465 \subsection[TysWiredIn-Bool]{The @Bool@ type}
467 %************************************************************************
469 An ordinary enumeration type, but deeply wired in. There are no
470 magical operations on @Bool@ (just the regular Prelude code).
472 {\em BEGIN IDLE SPECULATION BY SIMON}
474 This is not the only way to encode @Bool@. A more obvious coding makes
475 @Bool@ just a boxed up version of @Bool#@, like this:
478 data Bool = MkBool Bool#
481 Unfortunately, this doesn't correspond to what the Report says @Bool@
482 looks like! Furthermore, we get slightly less efficient code (I
483 think) with this coding. @gtInt@ would look like this:
486 gtInt :: Int -> Int -> Bool
487 gtInt x y = case x of I# x# ->
489 case (gtIntPrim x# y#) of
493 Notice that the result of the @gtIntPrim@ comparison has to be turned
494 into an integer (here called @b#@), and returned in a @MkBool@ box.
496 The @if@ expression would compile to this:
499 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
502 I think this code is a little less efficient than the previous code,
503 but I'm not certain. At all events, corresponding with the Report is
504 important. The interesting thing is that the language is expressive
505 enough to describe more than one alternative; and that a type doesn't
506 necessarily need to be a straightforwardly boxed version of its
507 primitive counterpart.
509 {\em END IDLE SPECULATION BY SIMON}
512 boolTy = mkTyConTy boolTyCon
514 boolTyCon = pcDataTyCon boolTyConKey pRELUDE_CORE SLIT("Bool") [] [falseDataCon, trueDataCon]
516 falseDataCon = pcDataCon falseDataConKey pRELUDE_CORE SLIT("False") [] [] [] boolTyCon nullSpecEnv
517 trueDataCon = pcDataCon trueDataConKey pRELUDE_CORE SLIT("True") [] [] [] boolTyCon nullSpecEnv
520 %************************************************************************
522 \subsection[TysWiredIn-Ordering]{The @Ordering@ type}
524 %************************************************************************
527 ---------------------------------------------
528 -- data Ordering = LT | EQ | GT deriving ()
529 ---------------------------------------------
531 orderingTy = mkTyConTy orderingTyCon
533 orderingTyCon = pcDataTyCon orderingTyConKey pRELUDE_BUILTIN SLIT("Ordering") []
534 [ltDataCon, eqDataCon, gtDataCon]
536 ltDataCon = pcDataCon ltDataConKey pRELUDE_BUILTIN SLIT("LT") [] [] [] orderingTyCon nullSpecEnv
537 eqDataCon = pcDataCon eqDataConKey pRELUDE_BUILTIN SLIT("EQ") [] [] [] orderingTyCon nullSpecEnv
538 gtDataCon = pcDataCon gtDataConKey pRELUDE_BUILTIN SLIT("GT") [] [] [] orderingTyCon nullSpecEnv
541 %************************************************************************
543 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
545 %************************************************************************
547 Special syntax, deeply wired in, but otherwise an ordinary algebraic
550 data List a = Nil | a : (List a)
551 ToDo: data [] a = [] | a : (List a)
553 data (,,) a b c = (,,) a b c
557 mkListTy :: GenType t u -> GenType t u
558 mkListTy ty = applyTyCon listTyCon [ty]
560 alphaListTy = mkSigmaTy [alphaTyVar] [] (applyTyCon listTyCon [alphaTy])
562 listTyCon = pcDataTyCon listTyConKey pRELUDE_BUILTIN SLIT("[]")
563 [alphaTyVar] [nilDataCon, consDataCon]
565 nilDataCon = pcDataCon nilDataConKey pRELUDE_BUILTIN SLIT("[]") [alphaTyVar] [] [] listTyCon
566 (pcGenerateDataSpecs alphaListTy)
567 consDataCon = pcDataCon consDataConKey pRELUDE_BUILTIN SLIT(":")
568 [alphaTyVar] [] [alphaTy, applyTyCon listTyCon [alphaTy]] listTyCon
569 (pcGenerateDataSpecs alphaListTy)
570 -- Interesting: polymorphic recursion would help here.
571 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
572 -- gets the over-specific type (Type -> Type)
575 %************************************************************************
577 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
579 %************************************************************************
581 The tuple types are definitely magic, because they form an infinite
586 They have a special family of type constructors, of type @TyCon@
587 These contain the tycon arity, but don't require a Unique.
590 They have a special family of constructors, of type
591 @Id@. Again these contain their arity but don't need a Unique.
594 There should be a magic way of generating the info tables and
595 entry code for all tuples.
597 But at the moment we just compile a Haskell source
598 file\srcloc{lib/prelude/...} containing declarations like:
601 data Tuple2 a b = Tup2 a b
602 data Tuple3 a b c = Tup3 a b c
603 data Tuple4 a b c d = Tup4 a b c d
606 The print-names associated with the magic @Id@s for tuple constructors
607 ``just happen'' to be the same as those generated by these
611 The instance environment should have a magic way to know
612 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
613 so on. \ToDo{Not implemented yet.}
616 There should also be a way to generate the appropriate code for each
617 of these instances, but (like the info tables and entry code) it is
618 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
622 mkTupleTy :: Int -> [GenType t u] -> GenType t u
624 mkTupleTy arity tys = applyTyCon (mkTupleTyCon arity) tys
626 unitTy = mkTupleTy 0 []
629 %************************************************************************
631 \subsection[TysWiredIn-Ratios]{@Ratio@ and @Rational@}
633 %************************************************************************
635 ToDo: make this (mostly) go away.
638 rationalTy :: GenType t u
640 mkRatioTy ty = applyTyCon ratioTyCon [ty]
641 rationalTy = mkRatioTy integerTy
643 ratioTyCon = pcDataTyCon ratioTyConKey pRELUDE_RATIO SLIT("Ratio") [alphaTyVar] [ratioDataCon]
645 ratioDataCon = pcDataCon ratioDataConKey pRELUDE_RATIO SLIT(":%")
646 [alphaTyVar] [{-(integralClass,alphaTy)-}] [alphaTy, alphaTy] ratioTyCon nullSpecEnv
647 -- context omitted to match lib/prelude/ defn of "data Ratio ..."
652 (mkPreludeCoreName pRELUDE_RATIO SLIT("Rational"))
656 rationalTy -- == mkRatioTy integerTy
659 %************************************************************************
661 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
663 %************************************************************************
665 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
668 mkLiftTy ty = applyTyCon liftTyCon [ty]
672 = mkSigmaTy tvs theta (applyTyCon liftTyCon [tau])
674 (tvs, theta, tau) = splitSigmaTy ty
677 = case maybeAppDataTyCon tau of
678 Just (tycon, tys, _) -> tycon == liftTyCon
681 (tvs, theta, tau) = splitSigmaTy ty
685 alphaLiftTy = mkSigmaTy [alphaTyVar] [] (applyTyCon liftTyCon [alphaTy])
688 = pcDataTyCon liftTyConKey pRELUDE_BUILTIN SLIT("_Lift") [alphaTyVar] [liftDataCon]
691 = pcDataCon liftDataConKey pRELUDE_BUILTIN SLIT("_Lift")
692 [alphaTyVar] [] [alphaTy] liftTyCon
693 ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv`
694 (mkSpecInfo [Just realWorldStatePrimTy] 0 bottom))
696 bottom = panic "liftDataCon:State# _RealWorld"
700 %************************************************************************
702 \subsection[TysWiredIn-for-convenience]{Types wired in for convenience (e.g., @String@)}
704 %************************************************************************
707 stringTy = mkListTy charTy
712 (mkPreludeCoreName pRELUDE_CORE SLIT("String"))