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"
35 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,
89 import Pretty --ToDo:rm debugging only
91 import PrelFuns -- help functions, types and things
94 import AbsUniType ( applyTyCon, mkTupleTyCon, mkSynonymTyCon,
95 getUniDataTyCon_maybe, mkSigmaTy, TyCon
96 , pprUniType --ToDo: rm debugging only
97 IF_ATTACK_PRAGMAS(COMMA cmpTyCon)
100 import Maybes ( Maybe(..) )
105 %************************************************************************
107 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
109 %************************************************************************
112 charTy = UniData charTyCon []
114 charTyCon = pcDataTyCon charTyConKey pRELUDE_BUILTIN SLIT("Char") [] [charDataCon]
115 charDataCon = pcDataCon charDataConKey pRELUDE_BUILTIN SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv
119 intTy = UniData intTyCon []
121 intTyCon = pcDataTyCon intTyConKey pRELUDE_BUILTIN SLIT("Int") [] [intDataCon]
122 intDataCon = pcDataCon intDataConKey pRELUDE_BUILTIN SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv
126 wordTy = UniData wordTyCon []
128 wordTyCon = pcDataTyCon wordTyConKey pRELUDE_BUILTIN SLIT("_Word") [] [wordDataCon]
129 wordDataCon = pcDataCon wordDataConKey pRELUDE_BUILTIN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv
133 addrTy = UniData addrTyCon []
135 addrTyCon = pcDataTyCon addrTyConKey pRELUDE_BUILTIN SLIT("_Addr") [] [addrDataCon]
136 addrDataCon = pcDataCon addrDataConKey pRELUDE_BUILTIN SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv
140 floatTy = UniData floatTyCon []
142 floatTyCon = pcDataTyCon floatTyConKey pRELUDE_BUILTIN SLIT("Float") [] [floatDataCon]
143 floatDataCon = pcDataCon floatDataConKey pRELUDE_BUILTIN SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv
147 doubleTy = UniData doubleTyCon []
149 doubleTyCon = pcDataTyCon doubleTyConKey pRELUDE_BUILTIN SLIT("Double") [] [doubleDataCon]
150 doubleDataCon = pcDataCon doubleDataConKey pRELUDE_BUILTIN SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv
154 mkStateTy ty = applyTyCon stateTyCon [ty]
155 realWorldStateTy = mkStateTy realWorldTy -- a common use
157 stateTyCon = pcDataTyCon stateTyConKey pRELUDE_BUILTIN SLIT("_State") [alpha_tv] [stateDataCon]
159 = pcDataCon stateDataConKey pRELUDE_BUILTIN SLIT("S#")
160 [alpha_tv] [] [mkStatePrimTy alpha] stateTyCon nullSpecEnv
166 = pcDataTyCon byteArrayTyConKey pRELUDE_ARRAY SLIT("_ByteArray")
167 [alpha_tv] [byteArrayDataCon]
170 = pcDataCon byteArrayDataConKey pRELUDE_ARRAY SLIT("_ByteArray")
172 [mkTupleTy 2 [alpha, alpha], byteArrayPrimTy]
173 byteArrayTyCon nullSpecEnv
180 = pcDataTyCon mutableArrayTyConKey gLASGOW_ST SLIT("_MutableArray")
181 [alpha_tv, beta_tv, gamma_tv] [mutableArrayDataCon]
184 = pcDataCon mutableArrayDataConKey gLASGOW_ST SLIT("_MutableArray")
185 [alpha_tv, beta_tv, gamma_tv] []
186 [mkTupleTy 2 [beta, beta], applyTyCon mutableArrayPrimTyCon [alpha, gamma]]
187 mutableArrayTyCon nullSpecEnv
193 mutableByteArrayTyCon
194 = pcDataTyCon mutableByteArrayTyConKey gLASGOW_ST SLIT("_MutableByteArray")
195 [alpha_tv, beta_tv] [mutableByteArrayDataCon]
197 mutableByteArrayDataCon
198 = pcDataCon mutableByteArrayDataConKey gLASGOW_ST SLIT("_MutableByteArray")
199 [alpha_tv, beta_tv] []
200 [mkTupleTy 2 [beta, beta], mkMutableByteArrayPrimTy alpha]
201 mutableByteArrayTyCon nullSpecEnv
207 = pcDataTyCon stablePtrTyConKey gLASGOW_MISC SLIT("_StablePtr")
208 [alpha_tv] [stablePtrDataCon]
211 = pcDataCon stablePtrDataConKey gLASGOW_MISC SLIT("_StablePtr")
212 [alpha_tv] [] [applyTyCon stablePtrPrimTyCon [alpha]] stablePtrTyCon nullSpecEnv
217 = pcDataTyCon mallocPtrTyConKey gLASGOW_MISC SLIT("_MallocPtr")
218 [] [mallocPtrDataCon]
221 = pcDataCon mallocPtrDataConKey gLASGOW_MISC SLIT("_MallocPtr")
222 [] [] [applyTyCon mallocPtrPrimTyCon []] mallocPtrTyCon nullSpecEnv
225 %************************************************************************
227 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
229 %************************************************************************
231 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
234 integerTy = UniData integerTyCon []
236 integerTyCon = pcDataTyCon integerTyConKey pRELUDE_BUILTIN SLIT("Integer") [] [integerDataCon]
239 integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#")
240 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv
242 -- DPH: For the time being we implement Integers in the same way as Ints.
243 integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#")
244 [] [] [intPrimTy] integerTyCon nullSpecEnv
245 #endif {- Data Parallel Haskell -}
248 And the other pairing types:
250 return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey
251 pRELUDE_BUILTIN SLIT("_Return2GMPs") [] [return2GMPsDataCon]
254 = pcDataCon return2GMPsDataConKey pRELUDE_BUILTIN SLIT("_Return2GMPs") [] []
255 [intPrimTy, intPrimTy, byteArrayPrimTy,
256 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv
258 returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey
259 pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
261 returnIntAndGMPDataCon
262 = pcDataCon returnIntAndGMPDataConKey pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] []
263 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv
266 %************************************************************************
268 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
270 %************************************************************************
272 These boring types pair a \tr{State#} with another primitive type.
273 They are not really primitive, so they are given here, not in
276 We fish one of these \tr{StateAnd<blah>#} things with
277 @getStatePairingConInfo@ (given a little way down).
281 = pcDataTyCon stateAndPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
282 [alpha_tv, beta_tv] [stateAndPtrPrimDataCon]
283 stateAndPtrPrimDataCon
284 = pcDataCon stateAndPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
285 [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, beta]
286 stateAndPtrPrimTyCon nullSpecEnv
288 stateAndCharPrimTyCon
289 = pcDataTyCon stateAndCharPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
290 [alpha_tv] [stateAndCharPrimDataCon]
291 stateAndCharPrimDataCon
292 = pcDataCon stateAndCharPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
293 [alpha_tv] [] [mkStatePrimTy alpha, charPrimTy]
294 stateAndCharPrimTyCon nullSpecEnv
297 = pcDataTyCon stateAndIntPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
298 [alpha_tv] [stateAndIntPrimDataCon]
299 stateAndIntPrimDataCon
300 = pcDataCon stateAndIntPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
301 [alpha_tv] [] [mkStatePrimTy alpha, intPrimTy]
302 stateAndIntPrimTyCon nullSpecEnv
304 stateAndWordPrimTyCon
305 = pcDataTyCon stateAndWordPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
306 [alpha_tv] [stateAndWordPrimDataCon]
307 stateAndWordPrimDataCon
308 = pcDataCon stateAndWordPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
309 [alpha_tv] [] [mkStatePrimTy alpha, wordPrimTy]
310 stateAndWordPrimTyCon nullSpecEnv
312 stateAndAddrPrimTyCon
313 = pcDataTyCon stateAndAddrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
314 [alpha_tv] [stateAndAddrPrimDataCon]
315 stateAndAddrPrimDataCon
316 = pcDataCon stateAndAddrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
317 [alpha_tv] [] [mkStatePrimTy alpha, addrPrimTy]
318 stateAndAddrPrimTyCon nullSpecEnv
320 stateAndStablePtrPrimTyCon
321 = pcDataTyCon stateAndStablePtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
322 [alpha_tv, beta_tv] [stateAndStablePtrPrimDataCon]
323 stateAndStablePtrPrimDataCon
324 = pcDataCon stateAndStablePtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
325 [alpha_tv, beta_tv] []
326 [mkStatePrimTy alpha, applyTyCon stablePtrPrimTyCon [beta]]
327 stateAndStablePtrPrimTyCon nullSpecEnv
329 stateAndMallocPtrPrimTyCon
330 = pcDataTyCon stateAndMallocPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
331 [alpha_tv] [stateAndMallocPtrPrimDataCon]
332 stateAndMallocPtrPrimDataCon
333 = pcDataCon stateAndMallocPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
335 [mkStatePrimTy alpha, applyTyCon mallocPtrPrimTyCon []]
336 stateAndMallocPtrPrimTyCon nullSpecEnv
338 stateAndFloatPrimTyCon
339 = pcDataTyCon stateAndFloatPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
340 [alpha_tv] [stateAndFloatPrimDataCon]
341 stateAndFloatPrimDataCon
342 = pcDataCon stateAndFloatPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
343 [alpha_tv] [] [mkStatePrimTy alpha, floatPrimTy]
344 stateAndFloatPrimTyCon nullSpecEnv
346 stateAndDoublePrimTyCon
347 = pcDataTyCon stateAndDoublePrimTyConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
348 [alpha_tv] [stateAndDoublePrimDataCon]
349 stateAndDoublePrimDataCon
350 = pcDataCon stateAndDoublePrimDataConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
351 [alpha_tv] [] [mkStatePrimTy alpha, doublePrimTy]
352 stateAndDoublePrimTyCon nullSpecEnv
356 stateAndArrayPrimTyCon
357 = pcDataTyCon stateAndArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
358 [alpha_tv, beta_tv] [stateAndArrayPrimDataCon]
359 stateAndArrayPrimDataCon
360 = pcDataCon stateAndArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
361 [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkArrayPrimTy beta]
362 stateAndArrayPrimTyCon nullSpecEnv
364 stateAndMutableArrayPrimTyCon
365 = pcDataTyCon stateAndMutableArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
366 [alpha_tv, beta_tv] [stateAndMutableArrayPrimDataCon]
367 stateAndMutableArrayPrimDataCon
368 = pcDataCon stateAndMutableArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
369 [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkMutableArrayPrimTy alpha beta]
370 stateAndMutableArrayPrimTyCon nullSpecEnv
372 stateAndByteArrayPrimTyCon
373 = pcDataTyCon stateAndByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
374 [alpha_tv] [stateAndByteArrayPrimDataCon]
375 stateAndByteArrayPrimDataCon
376 = pcDataCon stateAndByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
377 [alpha_tv] [] [mkStatePrimTy alpha, byteArrayPrimTy]
378 stateAndByteArrayPrimTyCon nullSpecEnv
380 stateAndMutableByteArrayPrimTyCon
381 = pcDataTyCon stateAndMutableByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
382 [alpha_tv] [stateAndMutableByteArrayPrimDataCon]
383 stateAndMutableByteArrayPrimDataCon
384 = pcDataCon stateAndMutableByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
385 [alpha_tv] [] [mkStatePrimTy alpha, applyTyCon mutableByteArrayPrimTyCon [alpha]]
386 stateAndMutableByteArrayPrimTyCon nullSpecEnv
388 stateAndSynchVarPrimTyCon
389 = pcDataTyCon stateAndSynchVarPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
390 [alpha_tv, beta_tv] [stateAndSynchVarPrimDataCon]
391 stateAndSynchVarPrimDataCon
392 = pcDataCon stateAndSynchVarPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
393 [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkSynchVarPrimTy alpha beta]
394 stateAndSynchVarPrimTyCon nullSpecEnv
397 The ccall-desugaring mechanism uses this function to figure out how to
398 rebox the result. It's really a HACK, especially the part about
399 how many types to drop from \tr{tys_applied}.
402 getStatePairingConInfo
403 :: UniType -- primitive type
404 -> (Id, -- state pair constructor for prim type
405 UniType) -- type of state pair
407 getStatePairingConInfo prim_ty
408 = case (getUniDataTyCon_maybe prim_ty) of
409 Nothing -> panic "getStatePairingConInfo:1"
410 Just (prim_tycon, tys_applied, _) ->
412 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
413 pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied)
418 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
419 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
420 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
421 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
422 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
423 (mallocPtrPrimTyCon, (stateAndMallocPtrPrimDataCon, stateAndMallocPtrPrimTyCon, 0)),
424 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
425 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
426 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
427 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
428 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
429 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
430 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
431 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
435 %************************************************************************
437 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
439 %************************************************************************
441 This is really just an ordinary synonym, except it is ABSTRACT.
444 mkStateTransformerTy s a = applyTyCon stTyCon [s, a]
449 (mkPreludeCoreName gLASGOW_ST SLIT("_ST"))
452 (mkStateTy alpha `UniFun` mkTupleTy 2 [beta, mkStateTy alpha])
453 True -- ToDo: make... *** ABSTRACT ***
456 %************************************************************************
458 \subsection[TysWiredIn-IO]{The @PrimIO@ and @IO@ monadic-I/O types}
460 %************************************************************************
462 @PrimIO@ and @IO@ really are just a plain synonyms.
465 mkPrimIoTy a = applyTyCon primIoTyCon [a]
470 (mkPreludeCoreName pRELUDE_PRIMIO SLIT("PrimIO"))
473 (mkStateTransformerTy realWorldTy alpha)
474 True -- need not be abstract
477 %************************************************************************
479 \subsection[TysWiredIn-Bool]{The @Bool@ type}
481 %************************************************************************
483 An ordinary enumeration type, but deeply wired in. There are no
484 magical operations on @Bool@ (just the regular Prelude code).
486 {\em BEGIN IDLE SPECULATION BY SIMON}
488 This is not the only way to encode @Bool@. A more obvious coding makes
489 @Bool@ just a boxed up version of @Bool#@, like this:
492 data Bool = MkBool Bool#
495 Unfortunately, this doesn't correspond to what the Report says @Bool@
496 looks like! Furthermore, we get slightly less efficient code (I
497 think) with this coding. @gtInt@ would look like this:
500 gtInt :: Int -> Int -> Bool
501 gtInt x y = case x of I# x# ->
503 case (gtIntPrim x# y#) of
507 Notice that the result of the @gtIntPrim@ comparison has to be turned
508 into an integer (here called @b#@), and returned in a @MkBool@ box.
510 The @if@ expression would compile to this:
513 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
516 I think this code is a little less efficient than the previous code,
517 but I'm not certain. At all events, corresponding with the Report is
518 important. The interesting thing is that the language is expressive
519 enough to describe more than one alternative; and that a type doesn't
520 necessarily need to be a straightforwardly boxed version of its
521 primitive counterpart.
523 {\em END IDLE SPECULATION BY SIMON}
526 boolTy = UniData boolTyCon []
528 boolTyCon = pcDataTyCon boolTyConKey pRELUDE_CORE SLIT("Bool") [] [falseDataCon, trueDataCon]
530 falseDataCon = pcDataCon falseDataConKey pRELUDE_CORE SLIT("False") [] [] [] boolTyCon nullSpecEnv
531 trueDataCon = pcDataCon trueDataConKey pRELUDE_CORE SLIT("True") [] [] [] boolTyCon nullSpecEnv
534 %************************************************************************
536 \subsection[TysWiredIn-CMP-TAG]{The @CMP_TAG#@ type (for fast `derived' comparisons)}
538 %************************************************************************
541 ---------------------------------------------
542 -- data _CMP_TAG = _LT | _EQ | _GT deriving ()
543 ---------------------------------------------
545 cmpTagTy = UniData cmpTagTyCon []
547 cmpTagTyCon = pcDataTyCon cmpTagTyConKey pRELUDE_BUILTIN SLIT("_CMP_TAG") []
548 [ltPrimDataCon, eqPrimDataCon, gtPrimDataCon]
550 ltPrimDataCon = pcDataCon ltTagDataConKey pRELUDE_BUILTIN SLIT("_LT") [] [] [] cmpTagTyCon nullSpecEnv
551 eqPrimDataCon = pcDataCon eqTagDataConKey pRELUDE_BUILTIN SLIT("_EQ") [] [] [] cmpTagTyCon nullSpecEnv
552 gtPrimDataCon = pcDataCon gtTagDataConKey pRELUDE_BUILTIN SLIT("_GT") [] [] [] cmpTagTyCon nullSpecEnv
555 %************************************************************************
557 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
559 %************************************************************************
561 Special syntax, deeply wired in, but otherwise an ordinary algebraic
564 data List a = Nil | a : (List a)
568 mkListTy :: UniType -> UniType
569 mkListTy ty = UniData listTyCon [ty]
571 alphaListTy = mkSigmaTy [alpha_tv] [] (mkListTy alpha)
573 listTyCon = pcDataTyCon listTyConKey pRELUDE_BUILTIN SLIT("List") [alpha_tv] [nilDataCon, consDataCon]
575 nilDataCon = pcDataCon nilDataConKey pRELUDE_BUILTIN SLIT("Nil") [alpha_tv] [] [] listTyCon
576 (pcGenerateDataSpecs alphaListTy)
577 consDataCon = pcDataCon consDataConKey pRELUDE_BUILTIN SLIT(":")
578 [alpha_tv] [] [alpha, mkListTy alpha] listTyCon
579 (pcGenerateDataSpecs alphaListTy)
582 This is the @_Build@ data constructor, it does {\em not} appear inside
583 listTyCon. It has this type: \tr{((a -> b -> b) -> b -> b) -> [a]}.
587 = pcDataCon buildDataConKey pRELUDE_BUILTIN "Build"
589 mkSigmaTy [beta_tv] []
590 ((alpha `UniFun` (beta `UniFun` beta))
592 `UniFun` beta))] listTyCon nullSpecEnv
596 %************************************************************************
598 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
600 %************************************************************************
602 The tuple types are definitely magic, because they form an infinite
607 They have a special family of type constructors, of type
608 @TyCon@\srcloc{uniType/TyCon.lhs}.
609 These contain the tycon arity, but don't require a Unique.
612 They have a special family of constructors, of type
613 @Id@\srcloc{basicTypes/Id.lhs}. Again these contain their arity but
617 There should be a magic way of generating the info tables and
618 entry code for all tuples.
620 But at the moment we just compile a Haskell source
621 file\srcloc{lib/prelude/...} containing declarations like:
624 data Tuple2 a b = Tup2 a b
625 data Tuple3 a b c = Tup3 a b c
626 data Tuple4 a b c d = Tup4 a b c d
629 The print-names associated with the magic @Id@s for tuple constructors
630 ``just happen'' to be the same as those generated by these
634 The instance environment should have a magic way to know
635 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
636 so on. \ToDo{Not implemented yet.}
639 There should also be a way to generate the appropriate code for each
640 of these instances, but (like the info tables and entry code) it is
641 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
645 mkTupleTy :: Int -> [UniType] -> UniType
647 mkTupleTy arity tys = applyTyCon (mkTupleTyCon arity) tys
649 unitTy = mkTupleTy 0 []
652 %************************************************************************
654 \subsection[TysWiredIn-Ratios]{@Ratio@ and @Rational@}
656 %************************************************************************
658 ToDo: make this (mostly) go away.
661 rationalTy :: UniType
663 mkRatioTy ty = UniData ratioTyCon [ty]
664 rationalTy = mkRatioTy integerTy
666 ratioTyCon = pcDataTyCon ratioTyConKey pRELUDE_RATIO SLIT("Ratio") [alpha_tv] [ratioDataCon]
668 ratioDataCon = pcDataCon ratioDataConKey pRELUDE_RATIO SLIT(":%")
669 [alpha_tv] [{-(integralClass,alpha)-}] [alpha, alpha] ratioTyCon nullSpecEnv
670 -- context omitted to match lib/prelude/ defn of "data Ratio ..."
675 (mkPreludeCoreName pRELUDE_RATIO SLIT("Rational"))
678 rationalTy -- == mkRatioTy integerTy
682 %************************************************************************
684 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
686 %************************************************************************
688 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
691 mkLiftTy ty = applyTyCon liftTyCon [ty]
695 = mkSigmaTy tvs theta (UniData liftTyCon [tau])
697 (tvs, theta, tau) = splitType ty
700 = case getUniDataTyCon_maybe tau of
701 Just (tycon, tys, _) -> tycon == liftTyCon
704 (tvs, theta, tau) = splitType ty
708 alphaLiftTy = mkSigmaTy [alpha_tv] [] (UniData liftTyCon [alpha])
711 = pcDataTyCon liftTyConKey pRELUDE_BUILTIN SLIT("_Lift") [alpha_tv] [liftDataCon]
714 = pcDataCon liftDataConKey pRELUDE_BUILTIN SLIT("_Lift")
715 [alpha_tv] [] [alpha] liftTyCon
716 ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv`
717 (SpecInfo [Just realWorldStatePrimTy] 0 bottom))
719 bottom = panic "liftDataCon:State# _RealWorld"
723 %************************************************************************
725 \subsection[TysWiredIn-for-convenience]{Types wired in for convenience (e.g., @String@)}
727 %************************************************************************
730 stringTy = mkListTy charTy
735 (mkPreludeCoreName pRELUDE_CORE SLIT("String"))
744 packedStringTy = applyTyCon packedStringTyCon []
747 = pcDataTyCon packedStringTyConKey pRELUDE_PS SLIT("_PackedString") []
748 [psDataCon, cpsDataCon]
751 = pcDataCon psDataConKey pRELUDE_PS SLIT("_PS")
752 [] [] [intPrimTy, byteArrayPrimTy] packedStringTyCon
755 = pcDataCon cpsDataConKey pRELUDE_PS SLIT("_CPS")
756 [] [] [addrPrimTy] packedStringTyCon