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 Kind ( mkBoxedTypeKind, mkArrowKind )
100 import Name ( mkBuiltinName )
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-} -> Module -> FAST_STRING
118 -> [TyVar] -> [Id] -> TyCon
119 pcDataTyCon key mod str tyvars cons
120 = mkDataTyCon (mkBuiltinName key mod str) tycon_kind
121 tyvars [{-no context-}] cons [{-no derivings-}]
124 tycon_kind = foldr (mkArrowKind . getTyVarKind) mkBoxedTypeKind tyvars
126 pcDataCon :: Unique{-DataConKey-} -> Module -> FAST_STRING
127 -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> SpecEnv -> Id
128 pcDataCon key mod str tyvars context arg_tys tycon specenv
129 = mkDataCon (mkBuiltinName key mod str)
130 [ NotMarkedStrict | a <- arg_tys ]
131 [ {- no labelled fields -} ]
132 tyvars context arg_tys tycon
135 pcGenerateDataSpecs :: Type -> SpecEnv
136 pcGenerateDataSpecs ty
137 = pc_gen_specs False err err err ty
139 err = panic "PrelUtils:GenerateDataSpecs"
142 %************************************************************************
144 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
146 %************************************************************************
149 charTy = mkTyConTy charTyCon
151 charTyCon = pcDataTyCon charTyConKey pRELUDE_BUILTIN SLIT("Char") [] [charDataCon]
152 charDataCon = pcDataCon charDataConKey pRELUDE_BUILTIN SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv
156 intTy = mkTyConTy intTyCon
158 intTyCon = pcDataTyCon intTyConKey pRELUDE_BUILTIN SLIT("Int") [] [intDataCon]
159 intDataCon = pcDataCon intDataConKey pRELUDE_BUILTIN SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv
163 wordTy = mkTyConTy wordTyCon
165 wordTyCon = pcDataTyCon wordTyConKey pRELUDE_BUILTIN SLIT("_Word") [] [wordDataCon]
166 wordDataCon = pcDataCon wordDataConKey pRELUDE_BUILTIN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv
170 addrTy = mkTyConTy addrTyCon
172 addrTyCon = pcDataTyCon addrTyConKey pRELUDE_BUILTIN SLIT("_Addr") [] [addrDataCon]
173 addrDataCon = pcDataCon addrDataConKey pRELUDE_BUILTIN SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv
177 floatTy = mkTyConTy floatTyCon
179 floatTyCon = pcDataTyCon floatTyConKey pRELUDE_BUILTIN SLIT("Float") [] [floatDataCon]
180 floatDataCon = pcDataCon floatDataConKey pRELUDE_BUILTIN SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv
184 doubleTy = mkTyConTy doubleTyCon
186 doubleTyCon = pcDataTyCon doubleTyConKey pRELUDE_BUILTIN SLIT("Double") [] [doubleDataCon]
187 doubleDataCon = pcDataCon doubleDataConKey pRELUDE_BUILTIN SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv
191 mkStateTy ty = applyTyCon stateTyCon [ty]
192 realWorldStateTy = mkStateTy realWorldTy -- a common use
194 stateTyCon = pcDataTyCon stateTyConKey pRELUDE_BUILTIN SLIT("_State") [alphaTyVar] [stateDataCon]
196 = pcDataCon stateDataConKey pRELUDE_BUILTIN SLIT("S#")
197 [alphaTyVar] [] [mkStatePrimTy alphaTy] stateTyCon nullSpecEnv
202 = pcDataTyCon stablePtrTyConKey gLASGOW_MISC SLIT("_StablePtr")
203 [alphaTyVar] [stablePtrDataCon]
206 = pcDataCon stablePtrDataConKey gLASGOW_MISC SLIT("_StablePtr")
207 [alphaTyVar] [] [applyTyCon stablePtrPrimTyCon [alphaTy]] stablePtrTyCon nullSpecEnv
212 = pcDataTyCon mallocPtrTyConKey gLASGOW_MISC SLIT("_MallocPtr")
213 [] [mallocPtrDataCon]
216 = pcDataCon mallocPtrDataConKey gLASGOW_MISC SLIT("_MallocPtr")
217 [] [] [applyTyCon mallocPtrPrimTyCon []] mallocPtrTyCon nullSpecEnv
220 %************************************************************************
222 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
224 %************************************************************************
226 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
228 integerTy :: GenType t u
229 integerTy = mkTyConTy integerTyCon
231 integerTyCon = pcDataTyCon integerTyConKey pRELUDE_BUILTIN SLIT("Integer") [] [integerDataCon]
233 integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#")
234 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv
237 And the other pairing types:
239 return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey
240 pRELUDE_BUILTIN SLIT("_Return2GMPs") [] [return2GMPsDataCon]
243 = pcDataCon return2GMPsDataConKey pRELUDE_BUILTIN SLIT("_Return2GMPs") [] []
244 [intPrimTy, intPrimTy, byteArrayPrimTy,
245 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv
247 returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey
248 pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
250 returnIntAndGMPDataCon
251 = pcDataCon returnIntAndGMPDataConKey pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] []
252 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv
255 %************************************************************************
257 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
259 %************************************************************************
261 These boring types pair a \tr{State#} with another primitive type.
262 They are not really primitive, so they are given here, not in
265 We fish one of these \tr{StateAnd<blah>#} things with
266 @getStatePairingConInfo@ (given a little way down).
270 = pcDataTyCon stateAndPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
271 [alphaTyVar, betaTyVar] [stateAndPtrPrimDataCon]
272 stateAndPtrPrimDataCon
273 = pcDataCon stateAndPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
274 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, betaTy]
275 stateAndPtrPrimTyCon nullSpecEnv
277 stateAndCharPrimTyCon
278 = pcDataTyCon stateAndCharPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
279 [alphaTyVar] [stateAndCharPrimDataCon]
280 stateAndCharPrimDataCon
281 = pcDataCon stateAndCharPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
282 [alphaTyVar] [] [mkStatePrimTy alphaTy, charPrimTy]
283 stateAndCharPrimTyCon nullSpecEnv
286 = pcDataTyCon stateAndIntPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
287 [alphaTyVar] [stateAndIntPrimDataCon]
288 stateAndIntPrimDataCon
289 = pcDataCon stateAndIntPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
290 [alphaTyVar] [] [mkStatePrimTy alphaTy, intPrimTy]
291 stateAndIntPrimTyCon nullSpecEnv
293 stateAndWordPrimTyCon
294 = pcDataTyCon stateAndWordPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
295 [alphaTyVar] [stateAndWordPrimDataCon]
296 stateAndWordPrimDataCon
297 = pcDataCon stateAndWordPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
298 [alphaTyVar] [] [mkStatePrimTy alphaTy, wordPrimTy]
299 stateAndWordPrimTyCon nullSpecEnv
301 stateAndAddrPrimTyCon
302 = pcDataTyCon stateAndAddrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
303 [alphaTyVar] [stateAndAddrPrimDataCon]
304 stateAndAddrPrimDataCon
305 = pcDataCon stateAndAddrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
306 [alphaTyVar] [] [mkStatePrimTy alphaTy, addrPrimTy]
307 stateAndAddrPrimTyCon nullSpecEnv
309 stateAndStablePtrPrimTyCon
310 = pcDataTyCon stateAndStablePtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
311 [alphaTyVar, betaTyVar] [stateAndStablePtrPrimDataCon]
312 stateAndStablePtrPrimDataCon
313 = pcDataCon stateAndStablePtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
314 [alphaTyVar, betaTyVar] []
315 [mkStatePrimTy alphaTy, applyTyCon stablePtrPrimTyCon [betaTy]]
316 stateAndStablePtrPrimTyCon nullSpecEnv
318 stateAndMallocPtrPrimTyCon
319 = pcDataTyCon stateAndMallocPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
320 [alphaTyVar] [stateAndMallocPtrPrimDataCon]
321 stateAndMallocPtrPrimDataCon
322 = pcDataCon stateAndMallocPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
324 [mkStatePrimTy alphaTy, applyTyCon mallocPtrPrimTyCon []]
325 stateAndMallocPtrPrimTyCon nullSpecEnv
327 stateAndFloatPrimTyCon
328 = pcDataTyCon stateAndFloatPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
329 [alphaTyVar] [stateAndFloatPrimDataCon]
330 stateAndFloatPrimDataCon
331 = pcDataCon stateAndFloatPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
332 [alphaTyVar] [] [mkStatePrimTy alphaTy, floatPrimTy]
333 stateAndFloatPrimTyCon nullSpecEnv
335 stateAndDoublePrimTyCon
336 = pcDataTyCon stateAndDoublePrimTyConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
337 [alphaTyVar] [stateAndDoublePrimDataCon]
338 stateAndDoublePrimDataCon
339 = pcDataCon stateAndDoublePrimDataConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
340 [alphaTyVar] [] [mkStatePrimTy alphaTy, doublePrimTy]
341 stateAndDoublePrimTyCon nullSpecEnv
345 stateAndArrayPrimTyCon
346 = pcDataTyCon stateAndArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
347 [alphaTyVar, betaTyVar] [stateAndArrayPrimDataCon]
348 stateAndArrayPrimDataCon
349 = pcDataCon stateAndArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
350 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
351 stateAndArrayPrimTyCon nullSpecEnv
353 stateAndMutableArrayPrimTyCon
354 = pcDataTyCon stateAndMutableArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
355 [alphaTyVar, betaTyVar] [stateAndMutableArrayPrimDataCon]
356 stateAndMutableArrayPrimDataCon
357 = pcDataCon stateAndMutableArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
358 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
359 stateAndMutableArrayPrimTyCon nullSpecEnv
361 stateAndByteArrayPrimTyCon
362 = pcDataTyCon stateAndByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
363 [alphaTyVar] [stateAndByteArrayPrimDataCon]
364 stateAndByteArrayPrimDataCon
365 = pcDataCon stateAndByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
366 [alphaTyVar] [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
367 stateAndByteArrayPrimTyCon nullSpecEnv
369 stateAndMutableByteArrayPrimTyCon
370 = pcDataTyCon stateAndMutableByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
371 [alphaTyVar] [stateAndMutableByteArrayPrimDataCon]
372 stateAndMutableByteArrayPrimDataCon
373 = pcDataCon stateAndMutableByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
374 [alphaTyVar] [] [mkStatePrimTy alphaTy, applyTyCon mutableByteArrayPrimTyCon [alphaTy]]
375 stateAndMutableByteArrayPrimTyCon nullSpecEnv
377 stateAndSynchVarPrimTyCon
378 = pcDataTyCon stateAndSynchVarPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
379 [alphaTyVar, betaTyVar] [stateAndSynchVarPrimDataCon]
380 stateAndSynchVarPrimDataCon
381 = pcDataCon stateAndSynchVarPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
382 [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
383 stateAndSynchVarPrimTyCon nullSpecEnv
386 The ccall-desugaring mechanism uses this function to figure out how to
387 rebox the result. It's really a HACK, especially the part about
388 how many types to drop from \tr{tys_applied}.
391 getStatePairingConInfo
392 :: Type -- primitive type
393 -> (Id, -- state pair constructor for prim type
394 Type) -- type of state pair
396 getStatePairingConInfo prim_ty
397 = case (maybeAppDataTyCon prim_ty) of
398 Nothing -> panic "getStatePairingConInfo:1"
399 Just (prim_tycon, tys_applied, _) ->
401 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
402 pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied)
407 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
408 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
409 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
410 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
411 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
412 (mallocPtrPrimTyCon, (stateAndMallocPtrPrimDataCon, stateAndMallocPtrPrimTyCon, 0)),
413 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
414 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
415 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
416 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
417 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
418 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
419 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
420 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
424 %************************************************************************
426 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
428 %************************************************************************
430 This is really just an ordinary synonym, except it is ABSTRACT.
433 mkStateTransformerTy s a = mkSynTy stTyCon [s, a]
437 (mkBuiltinName stTyConKey gLASGOW_ST SLIT("_ST"))
438 (panic "TysWiredIn.stTyCon:Kind")
439 2 [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]
456 (mkBuiltinName primIoTyConKey pRELUDE_PRIMIO SLIT("PrimIO"))
457 (panic "TysWiredIn.primIoTyCon:Kind")
458 1 [alphaTyVar] (mkStateTransformerTy realWorldTy alphaTy)
461 %************************************************************************
463 \subsection[TysWiredIn-Bool]{The @Bool@ type}
465 %************************************************************************
467 An ordinary enumeration type, but deeply wired in. There are no
468 magical operations on @Bool@ (just the regular Prelude code).
470 {\em BEGIN IDLE SPECULATION BY SIMON}
472 This is not the only way to encode @Bool@. A more obvious coding makes
473 @Bool@ just a boxed up version of @Bool#@, like this:
476 data Bool = MkBool Bool#
479 Unfortunately, this doesn't correspond to what the Report says @Bool@
480 looks like! Furthermore, we get slightly less efficient code (I
481 think) with this coding. @gtInt@ would look like this:
484 gtInt :: Int -> Int -> Bool
485 gtInt x y = case x of I# x# ->
487 case (gtIntPrim x# y#) of
491 Notice that the result of the @gtIntPrim@ comparison has to be turned
492 into an integer (here called @b#@), and returned in a @MkBool@ box.
494 The @if@ expression would compile to this:
497 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
500 I think this code is a little less efficient than the previous code,
501 but I'm not certain. At all events, corresponding with the Report is
502 important. The interesting thing is that the language is expressive
503 enough to describe more than one alternative; and that a type doesn't
504 necessarily need to be a straightforwardly boxed version of its
505 primitive counterpart.
507 {\em END IDLE SPECULATION BY SIMON}
510 boolTy = mkTyConTy boolTyCon
512 boolTyCon = pcDataTyCon boolTyConKey pRELUDE_CORE SLIT("Bool") [] [falseDataCon, trueDataCon]
514 falseDataCon = pcDataCon falseDataConKey pRELUDE_CORE SLIT("False") [] [] [] boolTyCon nullSpecEnv
515 trueDataCon = pcDataCon trueDataConKey pRELUDE_CORE SLIT("True") [] [] [] boolTyCon nullSpecEnv
518 %************************************************************************
520 \subsection[TysWiredIn-Ordering]{The @Ordering@ type}
522 %************************************************************************
525 ---------------------------------------------
526 -- data Ordering = LT | EQ | GT deriving ()
527 ---------------------------------------------
529 orderingTy = mkTyConTy orderingTyCon
531 orderingTyCon = pcDataTyCon orderingTyConKey pRELUDE_BUILTIN SLIT("Ordering") []
532 [ltDataCon, eqDataCon, gtDataCon]
534 ltDataCon = pcDataCon ltDataConKey pRELUDE_BUILTIN SLIT("LT") [] [] [] orderingTyCon nullSpecEnv
535 eqDataCon = pcDataCon eqDataConKey pRELUDE_BUILTIN SLIT("EQ") [] [] [] orderingTyCon nullSpecEnv
536 gtDataCon = pcDataCon gtDataConKey pRELUDE_BUILTIN SLIT("GT") [] [] [] orderingTyCon nullSpecEnv
539 %************************************************************************
541 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
543 %************************************************************************
545 Special syntax, deeply wired in, but otherwise an ordinary algebraic
548 data List a = Nil | a : (List a)
549 ToDo: data [] a = [] | a : (List a)
551 data (,,) a b c = (,,) a b c
555 mkListTy :: GenType t u -> GenType t u
556 mkListTy ty = applyTyCon listTyCon [ty]
558 alphaListTy = mkSigmaTy [alphaTyVar] [] (applyTyCon listTyCon [alphaTy])
560 listTyCon = pcDataTyCon listTyConKey pRELUDE_BUILTIN SLIT("[]")
561 [alphaTyVar] [nilDataCon, consDataCon]
563 nilDataCon = pcDataCon nilDataConKey pRELUDE_BUILTIN SLIT("[]") [alphaTyVar] [] [] listTyCon
564 (pcGenerateDataSpecs alphaListTy)
565 consDataCon = pcDataCon consDataConKey pRELUDE_BUILTIN SLIT(":")
566 [alphaTyVar] [] [alphaTy, applyTyCon listTyCon [alphaTy]] listTyCon
567 (pcGenerateDataSpecs alphaListTy)
568 -- Interesting: polymorphic recursion would help here.
569 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
570 -- gets the over-specific type (Type -> Type)
573 %************************************************************************
575 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
577 %************************************************************************
579 The tuple types are definitely magic, because they form an infinite
584 They have a special family of type constructors, of type @TyCon@
585 These contain the tycon arity, but don't require a Unique.
588 They have a special family of constructors, of type
589 @Id@. Again these contain their arity but don't need a Unique.
592 There should be a magic way of generating the info tables and
593 entry code for all tuples.
595 But at the moment we just compile a Haskell source
596 file\srcloc{lib/prelude/...} containing declarations like:
599 data Tuple2 a b = Tup2 a b
600 data Tuple3 a b c = Tup3 a b c
601 data Tuple4 a b c d = Tup4 a b c d
604 The print-names associated with the magic @Id@s for tuple constructors
605 ``just happen'' to be the same as those generated by these
609 The instance environment should have a magic way to know
610 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
611 so on. \ToDo{Not implemented yet.}
614 There should also be a way to generate the appropriate code for each
615 of these instances, but (like the info tables and entry code) it is
616 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
620 mkTupleTy :: Int -> [GenType t u] -> GenType t u
622 mkTupleTy arity tys = applyTyCon (mkTupleTyCon arity) tys
624 unitTy = mkTupleTy 0 []
627 %************************************************************************
629 \subsection[TysWiredIn-Ratios]{@Ratio@ and @Rational@}
631 %************************************************************************
633 ToDo: make this (mostly) go away.
636 rationalTy :: GenType t u
638 mkRatioTy ty = applyTyCon ratioTyCon [ty]
639 rationalTy = mkRatioTy integerTy
641 ratioTyCon = pcDataTyCon ratioTyConKey pRELUDE_RATIO SLIT("Ratio") [alphaTyVar] [ratioDataCon]
643 ratioDataCon = pcDataCon ratioDataConKey pRELUDE_RATIO SLIT(":%")
644 [alphaTyVar] [{-(integralClass,alphaTy)-}] [alphaTy, alphaTy] ratioTyCon nullSpecEnv
645 -- context omitted to match lib/prelude/ defn of "data Ratio ..."
649 (mkBuiltinName rationalTyConKey pRELUDE_RATIO SLIT("Rational"))
651 0 [] rationalTy -- == mkRatioTy integerTy
654 %************************************************************************
656 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
658 %************************************************************************
660 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
663 mkLiftTy ty = applyTyCon liftTyCon [ty]
667 = mkSigmaTy tvs theta (applyTyCon liftTyCon [tau])
669 (tvs, theta, tau) = splitSigmaTy ty
672 = case maybeAppDataTyCon tau of
673 Just (tycon, tys, _) -> tycon == liftTyCon
676 (tvs, theta, tau) = splitSigmaTy ty
680 alphaLiftTy = mkSigmaTy [alphaTyVar] [] (applyTyCon liftTyCon [alphaTy])
683 = pcDataTyCon liftTyConKey pRELUDE_BUILTIN SLIT("_Lift") [alphaTyVar] [liftDataCon]
686 = pcDataCon liftDataConKey pRELUDE_BUILTIN SLIT("_Lift")
687 [alphaTyVar] [] [alphaTy] liftTyCon
688 ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv`
689 (mkSpecInfo [Just realWorldStatePrimTy] 0 bottom))
691 bottom = panic "liftDataCon:State# _RealWorld"
695 %************************************************************************
697 \subsection[TysWiredIn-for-convenience]{Types wired in for convenience (e.g., @String@)}
699 %************************************************************************
702 stringTy = mkListTy charTy
706 (mkBuiltinName stringTyConKey pRELUDE_CORE SLIT("String"))