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,
63 stateAndAddrPrimTyCon,
64 stateAndArrayPrimTyCon,
65 stateAndByteArrayPrimTyCon,
66 stateAndCharPrimTyCon,
67 stateAndDoublePrimTyCon,
68 stateAndFloatPrimTyCon,
70 stateAndMallocPtrPrimTyCon,
71 stateAndMutableArrayPrimTyCon,
72 stateAndMutableByteArrayPrimTyCon,
74 stateAndStablePtrPrimTyCon,
75 stateAndSynchVarPrimTyCon,
76 stateAndWordPrimTyCon,
88 import Pretty --ToDo:rm debugging only
90 import PrelFuns -- help functions, types and things
93 import AbsUniType ( applyTyCon, mkTupleTyCon, mkSynonymTyCon,
94 getUniDataTyCon_maybe, mkSigmaTy, TyCon
95 , pprUniType --ToDo: rm debugging only
96 IF_ATTACK_PRAGMAS(COMMA cmpTyCon)
99 import Maybes ( Maybe(..) )
104 %************************************************************************
106 \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
108 %************************************************************************
111 charTy = UniData charTyCon []
113 charTyCon = pcDataTyCon charTyConKey pRELUDE_BUILTIN SLIT("Char") [] [charDataCon]
114 charDataCon = pcDataCon charDataConKey pRELUDE_BUILTIN SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv
118 intTy = UniData intTyCon []
120 intTyCon = pcDataTyCon intTyConKey pRELUDE_BUILTIN SLIT("Int") [] [intDataCon]
121 intDataCon = pcDataCon intDataConKey pRELUDE_BUILTIN SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv
125 wordTy = UniData wordTyCon []
127 wordTyCon = pcDataTyCon wordTyConKey pRELUDE_BUILTIN SLIT("_Word") [] [wordDataCon]
128 wordDataCon = pcDataCon wordDataConKey pRELUDE_BUILTIN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv
132 addrTy = UniData addrTyCon []
134 addrTyCon = pcDataTyCon addrTyConKey pRELUDE_BUILTIN SLIT("_Addr") [] [addrDataCon]
135 addrDataCon = pcDataCon addrDataConKey pRELUDE_BUILTIN SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv
139 floatTy = UniData floatTyCon []
141 floatTyCon = pcDataTyCon floatTyConKey pRELUDE_BUILTIN SLIT("Float") [] [floatDataCon]
142 floatDataCon = pcDataCon floatDataConKey pRELUDE_BUILTIN SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv
146 doubleTy = UniData doubleTyCon []
148 doubleTyCon = pcDataTyCon doubleTyConKey pRELUDE_BUILTIN SLIT("Double") [] [doubleDataCon]
149 doubleDataCon = pcDataCon doubleDataConKey pRELUDE_BUILTIN SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv
153 mkStateTy ty = applyTyCon stateTyCon [ty]
154 realWorldStateTy = mkStateTy realWorldTy -- a common use
156 stateTyCon = pcDataTyCon stateTyConKey pRELUDE_BUILTIN SLIT("_State") [alpha_tv] [stateDataCon]
158 = pcDataCon stateDataConKey pRELUDE_BUILTIN SLIT("S#")
159 [alpha_tv] [] [mkStatePrimTy alpha] stateTyCon nullSpecEnv
165 = pcDataTyCon byteArrayTyConKey pRELUDE_ARRAY SLIT("_ByteArray")
166 [alpha_tv] [byteArrayDataCon]
169 = pcDataCon byteArrayDataConKey pRELUDE_ARRAY SLIT("_ByteArray")
171 [mkTupleTy 2 [alpha, alpha], byteArrayPrimTy]
172 byteArrayTyCon nullSpecEnv
179 = pcDataTyCon mutableArrayTyConKey gLASGOW_ST SLIT("_MutableArray")
180 [alpha_tv, beta_tv, gamma_tv] [mutableArrayDataCon]
183 = pcDataCon mutableArrayDataConKey gLASGOW_ST SLIT("_MutableArray")
184 [alpha_tv, beta_tv, gamma_tv] []
185 [mkTupleTy 2 [beta, beta], applyTyCon mutableArrayPrimTyCon [alpha, gamma]]
186 mutableArrayTyCon nullSpecEnv
192 mutableByteArrayTyCon
193 = pcDataTyCon mutableByteArrayTyConKey gLASGOW_ST SLIT("_MutableByteArray")
194 [alpha_tv, beta_tv] [mutableByteArrayDataCon]
196 mutableByteArrayDataCon
197 = pcDataCon mutableByteArrayDataConKey gLASGOW_ST SLIT("_MutableByteArray")
198 [alpha_tv, beta_tv] []
199 [mkTupleTy 2 [beta, beta], mkMutableByteArrayPrimTy alpha]
200 mutableByteArrayTyCon nullSpecEnv
206 = pcDataTyCon stablePtrTyConKey gLASGOW_MISC SLIT("_StablePtr")
207 [alpha_tv] [stablePtrDataCon]
210 = pcDataCon stablePtrDataConKey gLASGOW_MISC SLIT("_StablePtr")
211 [alpha_tv] [] [applyTyCon stablePtrPrimTyCon [alpha]] stablePtrTyCon nullSpecEnv
216 = pcDataTyCon mallocPtrTyConKey gLASGOW_MISC SLIT("_MallocPtr")
217 [] [mallocPtrDataCon]
220 = pcDataCon mallocPtrDataConKey gLASGOW_MISC SLIT("_MallocPtr")
221 [] [] [applyTyCon mallocPtrPrimTyCon []] mallocPtrTyCon nullSpecEnv
224 %************************************************************************
226 \subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
228 %************************************************************************
230 @Integer@ and its pals are not really primitive. @Integer@ itself, first:
233 integerTy = UniData integerTyCon []
235 integerTyCon = pcDataTyCon integerTyConKey pRELUDE_BUILTIN SLIT("Integer") [] [integerDataCon]
238 integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#")
239 [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv
241 -- DPH: For the time being we implement Integers in the same way as Ints.
242 integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#")
243 [] [] [intPrimTy] integerTyCon nullSpecEnv
244 #endif {- Data Parallel Haskell -}
247 And the other pairing types:
249 return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey
250 pRELUDE_BUILTIN SLIT("_Return2GMPs") [] [return2GMPsDataCon]
253 = pcDataCon return2GMPsDataConKey pRELUDE_BUILTIN SLIT("_Return2GMPs") [] []
254 [intPrimTy, intPrimTy, byteArrayPrimTy,
255 intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv
257 returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey
258 pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
260 returnIntAndGMPDataCon
261 = pcDataCon returnIntAndGMPDataConKey pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] []
262 [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv
265 %************************************************************************
267 \subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
269 %************************************************************************
271 These boring types pair a \tr{State#} with another primitive type.
272 They are not really primitive, so they are given here, not in
275 We fish one of these \tr{StateAnd<blah>#} things with
276 @getStatePairingConInfo@ (given a little way down).
280 = pcDataTyCon stateAndPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
281 [alpha_tv, beta_tv] [stateAndPtrPrimDataCon]
282 stateAndPtrPrimDataCon
283 = pcDataCon stateAndPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndPtr#")
284 [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, beta]
285 stateAndPtrPrimTyCon nullSpecEnv
287 stateAndCharPrimTyCon
288 = pcDataTyCon stateAndCharPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
289 [alpha_tv] [stateAndCharPrimDataCon]
290 stateAndCharPrimDataCon
291 = pcDataCon stateAndCharPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndChar#")
292 [alpha_tv] [] [mkStatePrimTy alpha, charPrimTy]
293 stateAndCharPrimTyCon nullSpecEnv
296 = pcDataTyCon stateAndIntPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
297 [alpha_tv] [stateAndIntPrimDataCon]
298 stateAndIntPrimDataCon
299 = pcDataCon stateAndIntPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndInt#")
300 [alpha_tv] [] [mkStatePrimTy alpha, intPrimTy]
301 stateAndIntPrimTyCon nullSpecEnv
303 stateAndWordPrimTyCon
304 = pcDataTyCon stateAndWordPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
305 [alpha_tv] [stateAndWordPrimDataCon]
306 stateAndWordPrimDataCon
307 = pcDataCon stateAndWordPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndWord#")
308 [alpha_tv] [] [mkStatePrimTy alpha, wordPrimTy]
309 stateAndWordPrimTyCon nullSpecEnv
311 stateAndAddrPrimTyCon
312 = pcDataTyCon stateAndAddrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
313 [alpha_tv] [stateAndAddrPrimDataCon]
314 stateAndAddrPrimDataCon
315 = pcDataCon stateAndAddrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndAddr#")
316 [alpha_tv] [] [mkStatePrimTy alpha, addrPrimTy]
317 stateAndAddrPrimTyCon nullSpecEnv
319 stateAndStablePtrPrimTyCon
320 = pcDataTyCon stateAndStablePtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
321 [alpha_tv, beta_tv] [stateAndStablePtrPrimDataCon]
322 stateAndStablePtrPrimDataCon
323 = pcDataCon stateAndStablePtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#")
324 [alpha_tv, beta_tv] []
325 [mkStatePrimTy alpha, applyTyCon stablePtrPrimTyCon [beta]]
326 stateAndStablePtrPrimTyCon nullSpecEnv
328 stateAndMallocPtrPrimTyCon
329 = pcDataTyCon stateAndMallocPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
330 [alpha_tv] [stateAndMallocPtrPrimDataCon]
331 stateAndMallocPtrPrimDataCon
332 = pcDataCon stateAndMallocPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#")
334 [mkStatePrimTy alpha, applyTyCon mallocPtrPrimTyCon []]
335 stateAndMallocPtrPrimTyCon nullSpecEnv
337 stateAndFloatPrimTyCon
338 = pcDataTyCon stateAndFloatPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
339 [alpha_tv] [stateAndFloatPrimDataCon]
340 stateAndFloatPrimDataCon
341 = pcDataCon stateAndFloatPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndFloat#")
342 [alpha_tv] [] [mkStatePrimTy alpha, floatPrimTy]
343 stateAndFloatPrimTyCon nullSpecEnv
345 stateAndDoublePrimTyCon
346 = pcDataTyCon stateAndDoublePrimTyConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
347 [alpha_tv] [stateAndDoublePrimDataCon]
348 stateAndDoublePrimDataCon
349 = pcDataCon stateAndDoublePrimDataConKey pRELUDE_BUILTIN SLIT("StateAndDouble#")
350 [alpha_tv] [] [mkStatePrimTy alpha, doublePrimTy]
351 stateAndDoublePrimTyCon nullSpecEnv
355 stateAndArrayPrimTyCon
356 = pcDataTyCon stateAndArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
357 [alpha_tv, beta_tv] [stateAndArrayPrimDataCon]
358 stateAndArrayPrimDataCon
359 = pcDataCon stateAndArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndArray#")
360 [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkArrayPrimTy beta]
361 stateAndArrayPrimTyCon nullSpecEnv
363 stateAndMutableArrayPrimTyCon
364 = pcDataTyCon stateAndMutableArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
365 [alpha_tv, beta_tv] [stateAndMutableArrayPrimDataCon]
366 stateAndMutableArrayPrimDataCon
367 = pcDataCon stateAndMutableArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#")
368 [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkMutableArrayPrimTy alpha beta]
369 stateAndMutableArrayPrimTyCon nullSpecEnv
371 stateAndByteArrayPrimTyCon
372 = pcDataTyCon stateAndByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
373 [alpha_tv] [stateAndByteArrayPrimDataCon]
374 stateAndByteArrayPrimDataCon
375 = pcDataCon stateAndByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#")
376 [alpha_tv] [] [mkStatePrimTy alpha, byteArrayPrimTy]
377 stateAndByteArrayPrimTyCon nullSpecEnv
379 stateAndMutableByteArrayPrimTyCon
380 = pcDataTyCon stateAndMutableByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
381 [alpha_tv] [stateAndMutableByteArrayPrimDataCon]
382 stateAndMutableByteArrayPrimDataCon
383 = pcDataCon stateAndMutableByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#")
384 [alpha_tv] [] [mkStatePrimTy alpha, applyTyCon mutableByteArrayPrimTyCon [alpha]]
385 stateAndMutableByteArrayPrimTyCon nullSpecEnv
387 stateAndSynchVarPrimTyCon
388 = pcDataTyCon stateAndSynchVarPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
389 [alpha_tv, beta_tv] [stateAndSynchVarPrimDataCon]
390 stateAndSynchVarPrimDataCon
391 = pcDataCon stateAndSynchVarPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#")
392 [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkSynchVarPrimTy alpha beta]
393 stateAndSynchVarPrimTyCon nullSpecEnv
396 The ccall-desugaring mechanism uses this function to figure out how to
397 rebox the result. It's really a HACK, especially the part about
398 how many types to drop from \tr{tys_applied}.
401 getStatePairingConInfo
402 :: UniType -- primitive type
403 -> (Id, -- state pair constructor for prim type
404 UniType) -- type of state pair
406 getStatePairingConInfo prim_ty
407 = case (getUniDataTyCon_maybe prim_ty) of
408 Nothing -> panic "getStatePairingConInfo:1"
409 Just (prim_tycon, tys_applied, _) ->
411 (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
412 pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied)
417 (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
418 (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
419 (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
420 (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
421 (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
422 (mallocPtrPrimTyCon, (stateAndMallocPtrPrimDataCon, stateAndMallocPtrPrimTyCon, 0)),
423 (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
424 (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
425 (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
426 (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
427 (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
428 (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
429 (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
430 -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
434 %************************************************************************
436 \subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
438 %************************************************************************
440 This is really just an ordinary synonym, except it is ABSTRACT.
443 mkStateTransformerTy s a = applyTyCon stTyCon [s, a]
448 (mkPreludeCoreName gLASGOW_ST SLIT("_ST"))
451 (mkStateTy alpha `UniFun` mkTupleTy 2 [beta, mkStateTy alpha])
452 True -- ToDo: make... *** ABSTRACT ***
455 %************************************************************************
457 \subsection[TysWiredIn-IO]{The @PrimIO@ and @IO@ monadic-I/O types}
459 %************************************************************************
461 @PrimIO@ and @IO@ really are just a plain synonyms.
464 mkPrimIoTy a = applyTyCon primIoTyCon [a]
469 (mkPreludeCoreName pRELUDE_PRIMIO SLIT("PrimIO"))
472 (mkStateTransformerTy realWorldTy alpha)
473 True -- need not be abstract
476 %************************************************************************
478 \subsection[TysWiredIn-Bool]{The @Bool@ type}
480 %************************************************************************
482 An ordinary enumeration type, but deeply wired in. There are no
483 magical operations on @Bool@ (just the regular Prelude code).
485 {\em BEGIN IDLE SPECULATION BY SIMON}
487 This is not the only way to encode @Bool@. A more obvious coding makes
488 @Bool@ just a boxed up version of @Bool#@, like this:
491 data Bool = MkBool Bool#
494 Unfortunately, this doesn't correspond to what the Report says @Bool@
495 looks like! Furthermore, we get slightly less efficient code (I
496 think) with this coding. @gtInt@ would look like this:
499 gtInt :: Int -> Int -> Bool
500 gtInt x y = case x of I# x# ->
502 case (gtIntPrim x# y#) of
506 Notice that the result of the @gtIntPrim@ comparison has to be turned
507 into an integer (here called @b#@), and returned in a @MkBool@ box.
509 The @if@ expression would compile to this:
512 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
515 I think this code is a little less efficient than the previous code,
516 but I'm not certain. At all events, corresponding with the Report is
517 important. The interesting thing is that the language is expressive
518 enough to describe more than one alternative; and that a type doesn't
519 necessarily need to be a straightforwardly boxed version of its
520 primitive counterpart.
522 {\em END IDLE SPECULATION BY SIMON}
525 boolTy = UniData boolTyCon []
527 boolTyCon = pcDataTyCon boolTyConKey pRELUDE_CORE SLIT("Bool") [] [falseDataCon, trueDataCon]
529 falseDataCon = pcDataCon falseDataConKey pRELUDE_CORE SLIT("False") [] [] [] boolTyCon nullSpecEnv
530 trueDataCon = pcDataCon trueDataConKey pRELUDE_CORE SLIT("True") [] [] [] boolTyCon nullSpecEnv
533 %************************************************************************
535 \subsection[TysWiredIn-CMP-TAG]{The @CMP_TAG#@ type (for fast `derived' comparisons)}
537 %************************************************************************
540 ---------------------------------------------
541 -- data _CMP_TAG = _LT | _EQ | _GT deriving ()
542 ---------------------------------------------
544 cmpTagTy = UniData cmpTagTyCon []
546 cmpTagTyCon = pcDataTyCon cmpTagTyConKey pRELUDE_BUILTIN SLIT("_CMP_TAG") []
547 [ltPrimDataCon, eqPrimDataCon, gtPrimDataCon]
549 ltPrimDataCon = pcDataCon ltTagDataConKey pRELUDE_BUILTIN SLIT("_LT") [] [] [] cmpTagTyCon nullSpecEnv
550 eqPrimDataCon = pcDataCon eqTagDataConKey pRELUDE_BUILTIN SLIT("_EQ") [] [] [] cmpTagTyCon nullSpecEnv
551 gtPrimDataCon = pcDataCon gtTagDataConKey pRELUDE_BUILTIN SLIT("_GT") [] [] [] cmpTagTyCon nullSpecEnv
554 %************************************************************************
556 \subsection[TysWiredIn-List]{The @List@ type (incl ``build'' magic)}
558 %************************************************************************
560 Special syntax, deeply wired in, but otherwise an ordinary algebraic
563 data List a = Nil | a : (List a)
567 mkListTy :: UniType -> UniType
568 mkListTy ty = UniData listTyCon [ty]
570 alphaListTy = mkSigmaTy [alpha_tv] [] (mkListTy alpha)
572 listTyCon = pcDataTyCon listTyConKey pRELUDE_BUILTIN SLIT("List") [alpha_tv] [nilDataCon, consDataCon]
574 nilDataCon = pcDataCon nilDataConKey pRELUDE_BUILTIN SLIT("Nil") [alpha_tv] [] [] listTyCon
575 (pcGenerateDataSpecs alphaListTy)
576 consDataCon = pcDataCon consDataConKey pRELUDE_BUILTIN SLIT(":")
577 [alpha_tv] [] [alpha, mkListTy alpha] listTyCon
578 (pcGenerateDataSpecs alphaListTy)
581 This is the @_Build@ data constructor, it does {\em not} appear inside
582 listTyCon. It has this type: \tr{((a -> b -> b) -> b -> b) -> [a]}.
586 = pcDataCon buildDataConKey pRELUDE_BUILTIN "Build"
588 mkSigmaTy [beta_tv] []
589 ((alpha `UniFun` (beta `UniFun` beta))
591 `UniFun` beta))] listTyCon nullSpecEnv
595 %************************************************************************
597 \subsection[TysWiredIn-Tuples]{The @Tuple@ types}
599 %************************************************************************
601 The tuple types are definitely magic, because they form an infinite
606 They have a special family of type constructors, of type
607 @TyCon@\srcloc{uniType/TyCon.lhs}.
608 These contain the tycon arity, but don't require a Unique.
611 They have a special family of constructors, of type
612 @Id@\srcloc{basicTypes/Id.lhs}. Again these contain their arity but
616 There should be a magic way of generating the info tables and
617 entry code for all tuples.
619 But at the moment we just compile a Haskell source
620 file\srcloc{lib/prelude/...} containing declarations like:
623 data Tuple2 a b = Tup2 a b
624 data Tuple3 a b c = Tup3 a b c
625 data Tuple4 a b c d = Tup4 a b c d
628 The print-names associated with the magic @Id@s for tuple constructors
629 ``just happen'' to be the same as those generated by these
633 The instance environment should have a magic way to know
634 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
635 so on. \ToDo{Not implemented yet.}
638 There should also be a way to generate the appropriate code for each
639 of these instances, but (like the info tables and entry code) it is
640 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
644 mkTupleTy :: Int -> [UniType] -> UniType
646 mkTupleTy arity tys = applyTyCon (mkTupleTyCon arity) tys
648 unitTy = mkTupleTy 0 []
651 %************************************************************************
653 \subsection[TysWiredIn-Ratios]{@Ratio@ and @Rational@}
655 %************************************************************************
657 ToDo: make this (mostly) go away.
660 rationalTy :: UniType
662 mkRatioTy ty = UniData ratioTyCon [ty]
663 rationalTy = mkRatioTy integerTy
665 ratioTyCon = pcDataTyCon ratioTyConKey pRELUDE_RATIO SLIT("Ratio") [alpha_tv] [ratioDataCon]
667 ratioDataCon = pcDataCon ratioDataConKey pRELUDE_RATIO SLIT(":%")
668 [alpha_tv] [{-(integralClass,alpha)-}] [alpha, alpha] ratioTyCon nullSpecEnv
669 -- context omitted to match lib/prelude/ defn of "data Ratio ..."
674 (mkPreludeCoreName pRELUDE_RATIO SLIT("Rational"))
677 rationalTy -- == mkRatioTy integerTy
681 %************************************************************************
683 \subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
685 %************************************************************************
687 Again, deeply turgid: \tr{data _Lift a = _Lift a}.
690 mkLiftTy ty = applyTyCon liftTyCon [ty]
694 = mkSigmaTy tvs theta (UniData liftTyCon [tau])
696 (tvs, theta, tau) = splitType ty
699 = case getUniDataTyCon_maybe tau of
700 Just (tycon, tys, _) -> tycon == liftTyCon
703 (tvs, theta, tau) = splitType ty
707 alphaLiftTy = mkSigmaTy [alpha_tv] [] (UniData liftTyCon [alpha])
710 = pcDataTyCon liftTyConKey pRELUDE_BUILTIN SLIT("_Lift") [alpha_tv] [liftDataCon]
713 = pcDataCon liftDataConKey pRELUDE_BUILTIN SLIT("_Lift")
714 [alpha_tv] [] [alpha] liftTyCon
715 ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv`
716 (SpecInfo [Just realWorldStatePrimTy] 0 bottom))
718 bottom = panic "liftDataCon:State# _RealWorld"
722 %************************************************************************
724 \subsection[TysWiredIn-for-convenience]{Types wired in for convenience (e.g., @String@)}
726 %************************************************************************
729 stringTy = mkListTy charTy
734 (mkPreludeCoreName pRELUDE_CORE SLIT("String"))
743 packedStringTy = applyTyCon packedStringTyCon []
746 = pcDataTyCon packedStringTyConKey pRELUDE_PS SLIT("_PackedString") []
747 [psDataCon, cpsDataCon]
750 = pcDataCon psDataConKey pRELUDE_PS SLIT("_PS")
751 [] [] [intPrimTy, byteArrayPrimTy] packedStringTyCon
754 = pcDataCon cpsDataConKey pRELUDE_PS SLIT("_CPS")
755 [] [] [addrPrimTy] packedStringTyCon