Refactoring only
[ghc.git] / compiler / prelude / TysWiredIn.hs
1 {-
2 (c) The GRASP Project, Glasgow University, 1994-1998
3
4 \section[TysWiredIn]{Wired-in knowledge about {\em non-primitive} types}
5 -}
6
7 {-# LANGUAGE CPP #-}
8
9 -- | This module is about types that can be defined in Haskell, but which
10 -- must be wired into the compiler nonetheless. C.f module TysPrim
11 module TysWiredIn (
12 -- * All wired in things
13 wiredInTyCons, isBuiltInOcc_maybe,
14
15 -- * Bool
16 boolTy, boolTyCon, boolTyCon_RDR, boolTyConName,
17 trueDataCon, trueDataConId, true_RDR,
18 falseDataCon, falseDataConId, false_RDR,
19 promotedFalseDataCon, promotedTrueDataCon,
20
21 -- * Ordering
22 orderingTyCon,
23 ltDataCon, ltDataConId,
24 eqDataCon, eqDataConId,
25 gtDataCon, gtDataConId,
26 promotedLTDataCon, promotedEQDataCon, promotedGTDataCon,
27
28 -- * Char
29 charTyCon, charDataCon, charTyCon_RDR,
30 charTy, stringTy, charTyConName,
31
32 -- * Double
33 doubleTyCon, doubleDataCon, doubleTy, doubleTyConName,
34
35 -- * Float
36 floatTyCon, floatDataCon, floatTy, floatTyConName,
37
38 -- * Int
39 intTyCon, intDataCon, intTyCon_RDR, intDataCon_RDR, intTyConName,
40 intTy,
41
42 -- * Word
43 wordTyCon, wordDataCon, wordTyConName, wordTy,
44
45 -- * Word8
46 word8TyCon, word8DataCon, word8TyConName, word8Ty,
47
48 -- * List
49 listTyCon, listTyCon_RDR, listTyConName, listTyConKey,
50 nilDataCon, nilDataConName, nilDataConKey,
51 consDataCon_RDR, consDataCon, consDataConName,
52
53 mkListTy,
54
55 -- * Maybe
56 maybeTyCon, maybeTyConName,
57 nothingDataCon, nothingDataConName, promotedNothingDataCon,
58 justDataCon, justDataConName, promotedJustDataCon,
59
60 -- * Tuples
61 mkTupleTy, mkBoxedTupleTy,
62 tupleTyCon, tupleDataCon, tupleTyConName,
63 promotedTupleDataCon,
64 unitTyCon, unitDataCon, unitDataConId, unitTy, unitTyConKey,
65 pairTyCon,
66 unboxedUnitTyCon, unboxedUnitDataCon,
67 cTupleTyConName, cTupleTyConNames, isCTupleTyConName,
68
69 -- * Kinds
70 typeNatKindCon, typeNatKind, typeSymbolKindCon, typeSymbolKind,
71 isLiftedTypeKindTyConName, liftedTypeKind, constraintKind,
72 starKindTyCon, starKindTyConName,
73 unicodeStarKindTyCon, unicodeStarKindTyConName,
74 liftedTypeKindTyCon, constraintKindTyCon,
75
76 -- * Parallel arrays
77 mkPArrTy,
78 parrTyCon, parrFakeCon, isPArrTyCon, isPArrFakeCon,
79 parrTyCon_RDR, parrTyConName,
80
81 -- * Equality predicates
82 heqTyCon, heqClass, heqDataCon,
83 coercibleTyCon, coercibleDataCon, coercibleClass,
84
85 -- * Implicit Parameters
86 ipTyCon, ipDataCon, ipClass,
87
88 callStackTyCon,
89
90 mkWiredInTyConName, -- This is used in TcTypeNats to define the
91 -- built-in functions for evaluation.
92
93 mkWiredInIdName, -- used in MkId
94
95 -- * Levity
96 levityTy, levityTyCon, liftedDataCon, unliftedDataCon,
97 liftedPromDataCon, unliftedPromDataCon,
98 liftedDataConTy, unliftedDataConTy,
99 liftedDataConName, unliftedDataConName
100 ) where
101
102 #include "HsVersions.h"
103
104 import {-# SOURCE #-} MkId( mkDataConWorkId, mkDictSelId )
105
106 -- friends:
107 import PrelNames
108 import TysPrim
109
110 -- others:
111 import FamInstEnv( mkNewTypeCoAxiom )
112 import CoAxiom
113 import Id
114 import Constants ( mAX_TUPLE_SIZE, mAX_CTUPLE_SIZE )
115 import Module ( Module )
116 import Type
117 import DataCon
118 import {-# SOURCE #-} ConLike
119 import TyCon
120 import Class ( Class, mkClass )
121 import RdrName
122 import Name
123 import NameSet ( NameSet, mkNameSet, elemNameSet )
124 import BasicTypes ( Arity, RecFlag(..), Boxity(..),
125 TupleSort(..) )
126 import ForeignCall
127 import SrcLoc ( noSrcSpan )
128 import Unique
129 import Data.Array
130 import FastString
131 import Outputable
132 import Util
133 import BooleanFormula ( mkAnd )
134
135 alpha_tyvar :: [TyVar]
136 alpha_tyvar = [alphaTyVar]
137
138 alpha_ty :: [Type]
139 alpha_ty = [alphaTy]
140
141 {-
142 ************************************************************************
143 * *
144 \subsection{Wired in type constructors}
145 * *
146 ************************************************************************
147
148 If you change which things are wired in, make sure you change their
149 names in PrelNames, so they use wTcQual, wDataQual, etc
150 -}
151
152 -- This list is used only to define PrelInfo.wiredInThings. That in turn
153 -- is used to initialise the name environment carried around by the renamer.
154 -- This means that if we look up the name of a TyCon (or its implicit binders)
155 -- that occurs in this list that name will be assigned the wired-in key we
156 -- define here.
157 --
158 -- Because of their infinite nature, this list excludes tuples, Any and implicit
159 -- parameter TyCons. Instead, we have a hack in lookupOrigNameCache to deal with
160 -- these names.
161 --
162 -- See also Note [Known-key names]
163 wiredInTyCons :: [TyCon]
164
165 wiredInTyCons = [ unitTyCon -- Not treated like other tuples, because
166 -- it's defined in GHC.Base, and there's only
167 -- one of it. We put it in wiredInTyCons so
168 -- that it'll pre-populate the name cache, so
169 -- the special case in lookupOrigNameCache
170 -- doesn't need to look out for it
171 , boolTyCon
172 , charTyCon
173 , doubleTyCon
174 , floatTyCon
175 , intTyCon
176 , wordTyCon
177 , word8TyCon
178 , listTyCon
179 , maybeTyCon
180 , parrTyCon
181 , heqTyCon
182 , coercibleTyCon
183 , typeNatKindCon
184 , typeSymbolKindCon
185 , levityTyCon
186 , constraintKindTyCon
187 , liftedTypeKindTyCon
188 , starKindTyCon
189 , unicodeStarKindTyCon
190 , ipTyCon
191 ]
192
193 mkWiredInTyConName :: BuiltInSyntax -> Module -> FastString -> Unique -> TyCon -> Name
194 mkWiredInTyConName built_in modu fs unique tycon
195 = mkWiredInName modu (mkTcOccFS fs) unique
196 (ATyCon tycon) -- Relevant TyCon
197 built_in
198
199 mkWiredInDataConName :: BuiltInSyntax -> Module -> FastString -> Unique -> DataCon -> Name
200 mkWiredInDataConName built_in modu fs unique datacon
201 = mkWiredInName modu (mkDataOccFS fs) unique
202 (AConLike (RealDataCon datacon)) -- Relevant DataCon
203 built_in
204
205 mkWiredInCoAxiomName :: BuiltInSyntax -> Module -> FastString -> Unique
206 -> CoAxiom Branched -> Name
207 mkWiredInCoAxiomName built_in modu fs unique ax
208 = mkWiredInName modu (mkTcOccFS fs) unique
209 (ACoAxiom ax) -- Relevant CoAxiom
210 built_in
211
212 mkWiredInIdName :: Module -> FastString -> Unique -> Id -> Name
213 mkWiredInIdName mod fs uniq id
214 = mkWiredInName mod (mkOccNameFS Name.varName fs) uniq (AnId id) UserSyntax
215
216 -- See Note [Kind-changing of (~) and Coercible]
217 -- in libraries/ghc-prim/GHC/Types.hs
218 heqTyConName, heqDataConName, heqSCSelIdName :: Name
219 heqTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "~~") heqTyConKey heqTyCon
220 heqDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "Eq#") heqDataConKey heqDataCon
221 heqSCSelIdName = mkWiredInIdName gHC_TYPES (fsLit "HEq_sc") heqSCSelIdKey heqSCSelId
222
223 -- See Note [Kind-changing of (~) and Coercible] in libraries/ghc-prim/GHC/Types.hs
224 coercibleTyConName, coercibleDataConName, coercibleSCSelIdName :: Name
225 coercibleTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Coercible") coercibleTyConKey coercibleTyCon
226 coercibleDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "MkCoercible") coercibleDataConKey coercibleDataCon
227 coercibleSCSelIdName = mkWiredInIdName gHC_TYPES (fsLit "Coercible_sc") coercibleSCSelIdKey coercibleSCSelId
228
229 charTyConName, charDataConName, intTyConName, intDataConName :: Name
230 charTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Char") charTyConKey charTyCon
231 charDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "C#") charDataConKey charDataCon
232 intTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Int") intTyConKey intTyCon
233 intDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "I#") intDataConKey intDataCon
234
235 boolTyConName, falseDataConName, trueDataConName :: Name
236 boolTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Bool") boolTyConKey boolTyCon
237 falseDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "False") falseDataConKey falseDataCon
238 trueDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "True") trueDataConKey trueDataCon
239
240 listTyConName, nilDataConName, consDataConName :: Name
241 listTyConName = mkWiredInTyConName BuiltInSyntax gHC_TYPES (fsLit "[]") listTyConKey listTyCon
242 nilDataConName = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit "[]") nilDataConKey nilDataCon
243 consDataConName = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit ":") consDataConKey consDataCon
244
245 maybeTyConName, nothingDataConName, justDataConName :: Name
246 maybeTyConName = mkWiredInTyConName UserSyntax gHC_BASE (fsLit "Maybe")
247 maybeTyConKey maybeTyCon
248 nothingDataConName = mkWiredInDataConName UserSyntax gHC_BASE (fsLit "Nothing")
249 nothingDataConKey nothingDataCon
250 justDataConName = mkWiredInDataConName UserSyntax gHC_BASE (fsLit "Just")
251 justDataConKey justDataCon
252
253 wordTyConName, wordDataConName, word8TyConName, word8DataConName :: Name
254 wordTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Word") wordTyConKey wordTyCon
255 wordDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "W#") wordDataConKey wordDataCon
256 word8TyConName = mkWiredInTyConName UserSyntax gHC_WORD (fsLit "Word8") word8TyConKey word8TyCon
257 word8DataConName = mkWiredInDataConName UserSyntax gHC_WORD (fsLit "W8#") word8DataConKey word8DataCon
258
259 floatTyConName, floatDataConName, doubleTyConName, doubleDataConName :: Name
260 floatTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Float") floatTyConKey floatTyCon
261 floatDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "F#") floatDataConKey floatDataCon
262 doubleTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Double") doubleTyConKey doubleTyCon
263 doubleDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "D#") doubleDataConKey doubleDataCon
264
265 -- Kinds
266 typeNatKindConName, typeSymbolKindConName :: Name
267 typeNatKindConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Nat") typeNatKindConNameKey typeNatKindCon
268 typeSymbolKindConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Symbol") typeSymbolKindConNameKey typeSymbolKindCon
269
270 constraintKindTyConName :: Name
271 constraintKindTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Constraint") constraintKindTyConKey constraintKindTyCon
272
273 liftedTypeKindTyConName, starKindTyConName, unicodeStarKindTyConName
274 :: Name
275 liftedTypeKindTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Type") liftedTypeKindTyConKey liftedTypeKindTyCon
276 starKindTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "*") starKindTyConKey starKindTyCon
277 unicodeStarKindTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "★") unicodeStarKindTyConKey unicodeStarKindTyCon
278
279 levityTyConName, liftedDataConName, unliftedDataConName :: Name
280 levityTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Levity") levityTyConKey levityTyCon
281 liftedDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "Lifted") liftedDataConKey liftedDataCon
282 unliftedDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "Unlifted") unliftedDataConKey unliftedDataCon
283
284 parrTyConName, parrDataConName :: Name
285 parrTyConName = mkWiredInTyConName BuiltInSyntax
286 gHC_PARR' (fsLit "[::]") parrTyConKey parrTyCon
287 parrDataConName = mkWiredInDataConName UserSyntax
288 gHC_PARR' (fsLit "PArr") parrDataConKey parrDataCon
289
290 boolTyCon_RDR, false_RDR, true_RDR, intTyCon_RDR, charTyCon_RDR,
291 intDataCon_RDR, listTyCon_RDR, consDataCon_RDR, parrTyCon_RDR :: RdrName
292 boolTyCon_RDR = nameRdrName boolTyConName
293 false_RDR = nameRdrName falseDataConName
294 true_RDR = nameRdrName trueDataConName
295 intTyCon_RDR = nameRdrName intTyConName
296 charTyCon_RDR = nameRdrName charTyConName
297 intDataCon_RDR = nameRdrName intDataConName
298 listTyCon_RDR = nameRdrName listTyConName
299 consDataCon_RDR = nameRdrName consDataConName
300 parrTyCon_RDR = nameRdrName parrTyConName
301
302 {-
303 ************************************************************************
304 * *
305 \subsection{mkWiredInTyCon}
306 * *
307 ************************************************************************
308 -}
309
310 pcNonRecDataTyCon :: Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon
311 -- Not an enumeration
312 pcNonRecDataTyCon = pcTyCon False NonRecursive
313
314 -- This function assumes that the types it creates have all parameters at
315 -- Representational role, and that there is no kind polymorphism.
316 pcTyCon :: Bool -> RecFlag -> Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon
317 pcTyCon is_enum is_rec name cType tyvars cons
318 = mkAlgTyCon name
319 (mkFunTys (map tyVarKind tyvars) liftedTypeKind)
320 tyvars
321 (map (const Representational) tyvars)
322 cType
323 [] -- No stupid theta
324 (DataTyCon cons is_enum)
325 (VanillaAlgTyCon (mkPrelTyConRepName name))
326 is_rec
327 False -- Not in GADT syntax
328
329 pcDataCon :: Name -> [TyVar] -> [Type] -> TyCon -> DataCon
330 pcDataCon n univs = pcDataConWithFixity False n univs [] -- no ex_tvs
331
332 pcDataConWithFixity :: Bool -- ^ declared infix?
333 -> Name -- ^ datacon name
334 -> [TyVar] -- ^ univ tyvars
335 -> [TyVar] -- ^ ex tyvars
336 -> [Type] -- ^ args
337 -> TyCon
338 -> DataCon
339 pcDataConWithFixity infx n = pcDataConWithFixity' infx n (incrUnique (nameUnique n))
340 -- The Name's unique is the first of two free uniques;
341 -- the first is used for the datacon itself,
342 -- the second is used for the "worker name"
343 --
344 -- To support this the mkPreludeDataConUnique function "allocates"
345 -- one DataCon unique per pair of Ints.
346
347 pcDataConWithFixity' :: Bool -> Name -> Unique -> [TyVar] -> [TyVar]
348 -> [Type] -> TyCon -> DataCon
349 -- The Name should be in the DataName name space; it's the name
350 -- of the DataCon itself.
351
352 pcDataConWithFixity' declared_infix dc_name wrk_key tyvars ex_tyvars arg_tys tycon
353 = data_con
354 where
355 data_con = mkDataCon dc_name declared_infix prom_info
356 (map (const no_bang) arg_tys)
357 [] -- No labelled fields
358 tyvars
359 ex_tyvars
360 [] -- No equality spec
361 [] -- No theta
362 arg_tys (mkTyConApp tycon (mkTyVarTys tyvars))
363 tycon
364 [] -- No stupid theta
365 (mkDataConWorkId wrk_name data_con)
366 NoDataConRep -- Wired-in types are too simple to need wrappers
367
368 no_bang = HsSrcBang Nothing NoSrcUnpack NoSrcStrict
369
370 modu = ASSERT( isExternalName dc_name )
371 nameModule dc_name
372 dc_occ = nameOccName dc_name
373 wrk_occ = mkDataConWorkerOcc dc_occ
374 wrk_name = mkWiredInName modu wrk_occ wrk_key
375 (AnId (dataConWorkId data_con)) UserSyntax
376
377 prom_info = mkPrelTyConRepName dc_name
378
379 {-
380 ************************************************************************
381 * *
382 Kinds
383 * *
384 ************************************************************************
385 -}
386
387 typeNatKindCon, typeSymbolKindCon :: TyCon
388 -- data Nat
389 -- data Symbol
390 typeNatKindCon = pcTyCon False NonRecursive typeNatKindConName Nothing [] []
391 typeSymbolKindCon = pcTyCon False NonRecursive typeSymbolKindConName Nothing [] []
392
393 typeNatKind, typeSymbolKind :: Kind
394 typeNatKind = mkTyConTy typeNatKindCon
395 typeSymbolKind = mkTyConTy typeSymbolKindCon
396
397 constraintKindTyCon :: TyCon
398 constraintKindTyCon = pcTyCon False NonRecursive constraintKindTyConName
399 Nothing [] []
400
401 liftedTypeKind, constraintKind :: Kind
402 liftedTypeKind = tYPE liftedDataConTy
403 constraintKind = mkTyConApp constraintKindTyCon []
404
405
406 {-
407 ************************************************************************
408 * *
409 Stuff for dealing with tuples
410 * *
411 ************************************************************************
412
413 Note [How tuples work] See also Note [Known-key names] in PrelNames
414 ~~~~~~~~~~~~~~~~~~~~~~
415 * There are three families of tuple TyCons and corresponding
416 DataCons, expressed by the type BasicTypes.TupleSort:
417 data TupleSort = BoxedTuple | UnboxedTuple | ConstraintTuple
418
419 * All three families are AlgTyCons, whose AlgTyConRhs is TupleTyCon
420
421 * BoxedTuples
422 - A wired-in type
423 - Data type declarations in GHC.Tuple
424 - The data constructors really have an info table
425
426 * UnboxedTuples
427 - A wired-in type
428 - Have a pretend DataCon, defined in GHC.Prim,
429 but no actual declaration and no info table
430
431 * ConstraintTuples
432 - Are known-key rather than wired-in. Reason: it's awkward to
433 have all the superclass selectors wired-in.
434 - Declared as classes in GHC.Classes, e.g.
435 class (c1,c2) => (c1,c2)
436 - Given constraints: the superclasses automatically become available
437 - Wanted constraints: there is a built-in instance
438 instance (c1,c2) => (c1,c2)
439 - Currently just go up to 16; beyond that
440 you have to use manual nesting
441 - Their OccNames look like (%,,,%), so they can easily be
442 distinguished from term tuples. But (following Haskell) we
443 pretty-print saturated constraint tuples with round parens; see
444 BasicTypes.tupleParens.
445
446 * In quite a lot of places things are restrcted just to
447 BoxedTuple/UnboxedTuple, and then we used BasicTypes.Boxity to distinguish
448 E.g. tupleTyCon has a Boxity argument
449
450 * When looking up an OccName in the original-name cache
451 (IfaceEnv.lookupOrigNameCache), we spot the tuple OccName to make sure
452 we get the right wired-in name. This guy can't tell the difference
453 betweeen BoxedTuple and ConstraintTuple (same OccName!), so tuples
454 are not serialised into interface files using OccNames at all.
455 -}
456
457 isBuiltInOcc_maybe :: OccName -> Maybe Name
458 -- Built in syntax isn't "in scope" so these OccNames
459 -- map to wired-in Names with BuiltInSyntax
460 isBuiltInOcc_maybe occ
461 = case occNameString occ of
462 "[]" -> choose_ns listTyConName nilDataConName
463 ":" -> Just consDataConName
464 "[::]" -> Just parrTyConName
465 "()" -> tup_name Boxed 0
466 "(##)" -> tup_name Unboxed 0
467 '(':',':rest -> parse_tuple Boxed 2 rest
468 '(':'#':',':rest -> parse_tuple Unboxed 2 rest
469 _other -> Nothing
470 where
471 ns = occNameSpace occ
472
473 parse_tuple sort n rest
474 | (',' : rest2) <- rest = parse_tuple sort (n+1) rest2
475 | tail_matches sort rest = tup_name sort n
476 | otherwise = Nothing
477
478 tail_matches Boxed ")" = True
479 tail_matches Unboxed "#)" = True
480 tail_matches _ _ = False
481
482 tup_name boxity arity
483 = choose_ns (getName (tupleTyCon boxity arity))
484 (getName (tupleDataCon boxity arity))
485
486 choose_ns tc dc
487 | isTcClsNameSpace ns = Just tc
488 | isDataConNameSpace ns = Just dc
489 | otherwise = pprPanic "tup_name" (ppr occ)
490
491 mkTupleOcc :: NameSpace -> Boxity -> Arity -> OccName
492 mkTupleOcc ns sort ar = mkOccName ns str
493 where
494 -- No need to cache these, the caching is done in mk_tuple
495 str = case sort of
496 Unboxed -> '(' : '#' : commas ++ "#)"
497 Boxed -> '(' : commas ++ ")"
498
499 commas = take (ar-1) (repeat ',')
500
501 mkCTupleOcc :: NameSpace -> Arity -> OccName
502 mkCTupleOcc ns ar = mkOccName ns str
503 where
504 str = "(%" ++ commas ++ "%)"
505 commas = take (ar-1) (repeat ',')
506
507 cTupleTyConName :: Arity -> Name
508 cTupleTyConName arity
509 = mkExternalName (mkCTupleTyConUnique arity) gHC_CLASSES
510 (mkCTupleOcc tcName arity) noSrcSpan
511 -- The corresponding DataCon does not have a known-key name
512
513 cTupleTyConNames :: [Name]
514 cTupleTyConNames = map cTupleTyConName (0 : [2..mAX_CTUPLE_SIZE])
515
516 cTupleTyConNameSet :: NameSet
517 cTupleTyConNameSet = mkNameSet cTupleTyConNames
518
519 isCTupleTyConName :: Name -> Bool
520 -- Use Type.isCTupleClass where possible
521 isCTupleTyConName n
522 = ASSERT2( isExternalName n, ppr n )
523 nameModule n == gHC_CLASSES
524 && n `elemNameSet` cTupleTyConNameSet
525
526 tupleTyCon :: Boxity -> Arity -> TyCon
527 tupleTyCon sort i | i > mAX_TUPLE_SIZE = fst (mk_tuple sort i) -- Build one specially
528 tupleTyCon Boxed i = fst (boxedTupleArr ! i)
529 tupleTyCon Unboxed i = fst (unboxedTupleArr ! i)
530
531 tupleTyConName :: TupleSort -> Arity -> Name
532 tupleTyConName ConstraintTuple a = cTupleTyConName a
533 tupleTyConName BoxedTuple a = tyConName (tupleTyCon Boxed a)
534 tupleTyConName UnboxedTuple a = tyConName (tupleTyCon Unboxed a)
535
536 promotedTupleDataCon :: Boxity -> Arity -> TyCon
537 promotedTupleDataCon boxity i = promoteDataCon (tupleDataCon boxity i)
538
539 tupleDataCon :: Boxity -> Arity -> DataCon
540 tupleDataCon sort i | i > mAX_TUPLE_SIZE = snd (mk_tuple sort i) -- Build one specially
541 tupleDataCon Boxed i = snd (boxedTupleArr ! i)
542 tupleDataCon Unboxed i = snd (unboxedTupleArr ! i)
543
544 boxedTupleArr, unboxedTupleArr :: Array Int (TyCon,DataCon)
545 boxedTupleArr = listArray (0,mAX_TUPLE_SIZE) [mk_tuple Boxed i | i <- [0..mAX_TUPLE_SIZE]]
546 unboxedTupleArr = listArray (0,mAX_TUPLE_SIZE) [mk_tuple Unboxed i | i <- [0..mAX_TUPLE_SIZE]]
547
548 mk_tuple :: Boxity -> Int -> (TyCon,DataCon)
549 mk_tuple boxity arity = (tycon, tuple_con)
550 where
551 tycon = mkTupleTyCon tc_name tc_kind tc_arity tyvars tuple_con
552 tup_sort flavour
553
554 (tup_sort, modu, tc_kind, tc_arity, tyvars, tyvar_tys, flavour)
555 = case boxity of
556 Boxed ->
557 let boxed_tyvars = take arity alphaTyVars in
558 ( BoxedTuple
559 , gHC_TUPLE
560 , mkFunTys (nOfThem arity liftedTypeKind) liftedTypeKind
561 , arity
562 , boxed_tyvars
563 , mkTyVarTys boxed_tyvars
564 , VanillaAlgTyCon (mkPrelTyConRepName tc_name)
565 )
566 -- See Note [Unboxed tuple levity vars] in TyCon
567 Unboxed ->
568 let all_tvs = mkTemplateTyVars (replicate arity levityTy ++
569 map (tYPE . mkTyVarTy) (take arity all_tvs))
570 -- NB: This must be one call to mkTemplateTyVars, to make
571 -- sure that all the uniques are different
572 (lev_tvs, open_tvs) = splitAt arity all_tvs
573 in
574 ( UnboxedTuple
575 , gHC_PRIM
576 , mkInvForAllTys lev_tvs $
577 mkFunTys (map tyVarKind open_tvs) $
578 unliftedTypeKind
579 , arity * 2
580 , all_tvs
581 , mkTyVarTys open_tvs
582 , UnboxedAlgTyCon
583 )
584
585 tc_name = mkWiredInName modu (mkTupleOcc tcName boxity arity) tc_uniq
586 (ATyCon tycon) BuiltInSyntax
587 tuple_con = pcDataCon dc_name tyvars tyvar_tys tycon
588 dc_name = mkWiredInName modu (mkTupleOcc dataName boxity arity) dc_uniq
589 (AConLike (RealDataCon tuple_con)) BuiltInSyntax
590 tc_uniq = mkTupleTyConUnique boxity arity
591 dc_uniq = mkTupleDataConUnique boxity arity
592
593 unitTyCon :: TyCon
594 unitTyCon = tupleTyCon Boxed 0
595
596 unitTyConKey :: Unique
597 unitTyConKey = getUnique unitTyCon
598
599 unitDataCon :: DataCon
600 unitDataCon = head (tyConDataCons unitTyCon)
601
602 unitDataConId :: Id
603 unitDataConId = dataConWorkId unitDataCon
604
605 pairTyCon :: TyCon
606 pairTyCon = tupleTyCon Boxed 2
607
608 unboxedUnitTyCon :: TyCon
609 unboxedUnitTyCon = tupleTyCon Unboxed 0
610
611 unboxedUnitDataCon :: DataCon
612 unboxedUnitDataCon = tupleDataCon Unboxed 0
613
614
615 {- *********************************************************************
616 * *
617 Equality types and classes
618 * *
619 ********************************************************************* -}
620
621 -- See Note [The equality types story] in TysPrim
622 heqTyCon, coercibleTyCon :: TyCon
623 heqClass, coercibleClass :: Class
624 heqDataCon, coercibleDataCon :: DataCon
625 heqSCSelId, coercibleSCSelId :: Id
626
627 (heqTyCon, heqClass, heqDataCon, heqSCSelId)
628 = (tycon, klass, datacon, sc_sel_id)
629 where
630 tycon = mkClassTyCon heqTyConName kind tvs roles
631 rhs klass NonRecursive
632 (mkSpecialTyConRepName (fsLit "tcHEq") heqTyConName)
633 klass = mkClass tvs [] [sc_pred] [sc_sel_id] [] [] (mkAnd []) tycon
634 datacon = pcDataCon heqDataConName tvs [sc_pred] tycon
635
636 kind = mkInvForAllTys [kv1, kv2] $ mkFunTys [k1, k2] constraintKind
637 kv1:kv2:_ = drop 9 alphaTyVars -- gets "j" and "k"
638 k1 = mkTyVarTy kv1
639 k2 = mkTyVarTy kv2
640 [av,bv] = mkTemplateTyVars [k1, k2]
641 tvs = [kv1, kv2, av, bv]
642 roles = [Nominal, Nominal, Nominal, Nominal]
643 rhs = DataTyCon { data_cons = [datacon], is_enum = False }
644
645 sc_pred = mkTyConApp eqPrimTyCon (mkTyVarTys tvs)
646 sc_sel_id = mkDictSelId heqSCSelIdName klass
647
648 (coercibleTyCon, coercibleClass, coercibleDataCon, coercibleSCSelId)
649 = (tycon, klass, datacon, sc_sel_id)
650 where
651 tycon = mkClassTyCon coercibleTyConName kind tvs roles
652 rhs klass NonRecursive
653 (mkPrelTyConRepName coercibleTyConName)
654 klass = mkClass tvs [] [sc_pred] [sc_sel_id] [] [] (mkAnd []) tycon
655 datacon = pcDataCon coercibleDataConName tvs [sc_pred] tycon
656
657 kind = mkInvForAllTys [kKiVar] $ mkFunTys [k, k] constraintKind
658 k = mkTyVarTy kKiVar
659 [av,bv] = mkTemplateTyVars [k, k]
660 tvs = [kKiVar, av, bv]
661 roles = [Nominal, Representational, Representational]
662 rhs = DataTyCon { data_cons = [datacon], is_enum = False }
663
664 sc_pred = mkTyConApp eqReprPrimTyCon [k, k, mkTyVarTy av, mkTyVarTy bv]
665 sc_sel_id = mkDictSelId coercibleSCSelIdName klass
666
667
668 {- *********************************************************************
669 * *
670 Kinds and levity
671 * *
672 ********************************************************************* -}
673
674 -- For information about the usage of the following type, see Note [TYPE]
675 -- in module TysPrim
676 levityTy :: Type
677 levityTy = mkTyConTy levityTyCon
678
679 levityTyCon :: TyCon
680 levityTyCon = pcTyCon True NonRecursive levityTyConName
681 Nothing [] [liftedDataCon, unliftedDataCon]
682
683 liftedDataCon, unliftedDataCon :: DataCon
684 liftedDataCon = pcDataCon liftedDataConName [] [] levityTyCon
685 unliftedDataCon = pcDataCon unliftedDataConName [] [] levityTyCon
686
687 liftedPromDataCon, unliftedPromDataCon :: TyCon
688 liftedPromDataCon = promoteDataCon liftedDataCon
689 unliftedPromDataCon = promoteDataCon unliftedDataCon
690
691 liftedDataConTy, unliftedDataConTy :: Type
692 liftedDataConTy = mkTyConTy liftedPromDataCon
693 unliftedDataConTy = mkTyConTy unliftedPromDataCon
694
695 liftedTypeKindTyCon, starKindTyCon, unicodeStarKindTyCon :: TyCon
696
697 -- See Note [TYPE] in TysPrim
698 liftedTypeKindTyCon = mkSynonymTyCon liftedTypeKindTyConName
699 liftedTypeKind
700 [] []
701 (tYPE liftedDataConTy)
702
703 starKindTyCon = mkSynonymTyCon starKindTyConName
704 liftedTypeKind
705 [] []
706 (tYPE liftedDataConTy)
707
708 unicodeStarKindTyCon = mkSynonymTyCon unicodeStarKindTyConName
709 liftedTypeKind
710 [] []
711 (tYPE liftedDataConTy)
712
713 {- *********************************************************************
714 * *
715 The boxed primitive types: Char, Int, etc
716 * *
717 ********************************************************************* -}
718
719 charTy :: Type
720 charTy = mkTyConTy charTyCon
721
722 charTyCon :: TyCon
723 charTyCon = pcNonRecDataTyCon charTyConName
724 (Just (CType "" Nothing ("HsChar",fsLit "HsChar")))
725 [] [charDataCon]
726 charDataCon :: DataCon
727 charDataCon = pcDataCon charDataConName [] [charPrimTy] charTyCon
728
729 stringTy :: Type
730 stringTy = mkListTy charTy -- convenience only
731
732 intTy :: Type
733 intTy = mkTyConTy intTyCon
734
735 intTyCon :: TyCon
736 intTyCon = pcNonRecDataTyCon intTyConName
737 (Just (CType "" Nothing ("HsInt",fsLit "HsInt"))) []
738 [intDataCon]
739 intDataCon :: DataCon
740 intDataCon = pcDataCon intDataConName [] [intPrimTy] intTyCon
741
742 wordTy :: Type
743 wordTy = mkTyConTy wordTyCon
744
745 wordTyCon :: TyCon
746 wordTyCon = pcNonRecDataTyCon wordTyConName
747 (Just (CType "" Nothing ("HsWord", fsLit "HsWord"))) []
748 [wordDataCon]
749 wordDataCon :: DataCon
750 wordDataCon = pcDataCon wordDataConName [] [wordPrimTy] wordTyCon
751
752 word8Ty :: Type
753 word8Ty = mkTyConTy word8TyCon
754
755 word8TyCon :: TyCon
756 word8TyCon = pcNonRecDataTyCon word8TyConName
757 (Just (CType "" Nothing ("HsWord8", fsLit "HsWord8"))) []
758 [word8DataCon]
759 word8DataCon :: DataCon
760 word8DataCon = pcDataCon word8DataConName [] [wordPrimTy] word8TyCon
761
762 floatTy :: Type
763 floatTy = mkTyConTy floatTyCon
764
765 floatTyCon :: TyCon
766 floatTyCon = pcNonRecDataTyCon floatTyConName
767 (Just (CType "" Nothing ("HsFloat", fsLit "HsFloat"))) []
768 [floatDataCon]
769 floatDataCon :: DataCon
770 floatDataCon = pcDataCon floatDataConName [] [floatPrimTy] floatTyCon
771
772 doubleTy :: Type
773 doubleTy = mkTyConTy doubleTyCon
774
775 doubleTyCon :: TyCon
776 doubleTyCon = pcNonRecDataTyCon doubleTyConName
777 (Just (CType "" Nothing ("HsDouble",fsLit "HsDouble"))) []
778 [doubleDataCon]
779
780 doubleDataCon :: DataCon
781 doubleDataCon = pcDataCon doubleDataConName [] [doublePrimTy] doubleTyCon
782
783 {-
784 ************************************************************************
785 * *
786 The Bool type
787 * *
788 ************************************************************************
789
790 An ordinary enumeration type, but deeply wired in. There are no
791 magical operations on @Bool@ (just the regular Prelude code).
792
793 {\em BEGIN IDLE SPECULATION BY SIMON}
794
795 This is not the only way to encode @Bool@. A more obvious coding makes
796 @Bool@ just a boxed up version of @Bool#@, like this:
797 \begin{verbatim}
798 type Bool# = Int#
799 data Bool = MkBool Bool#
800 \end{verbatim}
801
802 Unfortunately, this doesn't correspond to what the Report says @Bool@
803 looks like! Furthermore, we get slightly less efficient code (I
804 think) with this coding. @gtInt@ would look like this:
805
806 \begin{verbatim}
807 gtInt :: Int -> Int -> Bool
808 gtInt x y = case x of I# x# ->
809 case y of I# y# ->
810 case (gtIntPrim x# y#) of
811 b# -> MkBool b#
812 \end{verbatim}
813
814 Notice that the result of the @gtIntPrim@ comparison has to be turned
815 into an integer (here called @b#@), and returned in a @MkBool@ box.
816
817 The @if@ expression would compile to this:
818 \begin{verbatim}
819 case (gtInt x y) of
820 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
821 \end{verbatim}
822
823 I think this code is a little less efficient than the previous code,
824 but I'm not certain. At all events, corresponding with the Report is
825 important. The interesting thing is that the language is expressive
826 enough to describe more than one alternative; and that a type doesn't
827 necessarily need to be a straightforwardly boxed version of its
828 primitive counterpart.
829
830 {\em END IDLE SPECULATION BY SIMON}
831 -}
832
833 boolTy :: Type
834 boolTy = mkTyConTy boolTyCon
835
836 boolTyCon :: TyCon
837 boolTyCon = pcTyCon True NonRecursive boolTyConName
838 (Just (CType "" Nothing ("HsBool", fsLit "HsBool")))
839 [] [falseDataCon, trueDataCon]
840
841 falseDataCon, trueDataCon :: DataCon
842 falseDataCon = pcDataCon falseDataConName [] [] boolTyCon
843 trueDataCon = pcDataCon trueDataConName [] [] boolTyCon
844
845 falseDataConId, trueDataConId :: Id
846 falseDataConId = dataConWorkId falseDataCon
847 trueDataConId = dataConWorkId trueDataCon
848
849 orderingTyCon :: TyCon
850 orderingTyCon = pcTyCon True NonRecursive orderingTyConName Nothing
851 [] [ltDataCon, eqDataCon, gtDataCon]
852
853 ltDataCon, eqDataCon, gtDataCon :: DataCon
854 ltDataCon = pcDataCon ltDataConName [] [] orderingTyCon
855 eqDataCon = pcDataCon eqDataConName [] [] orderingTyCon
856 gtDataCon = pcDataCon gtDataConName [] [] orderingTyCon
857
858 ltDataConId, eqDataConId, gtDataConId :: Id
859 ltDataConId = dataConWorkId ltDataCon
860 eqDataConId = dataConWorkId eqDataCon
861 gtDataConId = dataConWorkId gtDataCon
862
863 {-
864 ************************************************************************
865 * *
866 The List type
867 Special syntax, deeply wired in,
868 but otherwise an ordinary algebraic data type
869 * *
870 ************************************************************************
871
872 data [] a = [] | a : (List a)
873 -}
874
875 mkListTy :: Type -> Type
876 mkListTy ty = mkTyConApp listTyCon [ty]
877
878 listTyCon :: TyCon
879 listTyCon = buildAlgTyCon listTyConName alpha_tyvar [Representational]
880 Nothing []
881 (DataTyCon [nilDataCon, consDataCon] False )
882 Recursive False
883 (VanillaAlgTyCon (mkSpecialTyConRepName (fsLit "tcList") listTyConName))
884
885 nilDataCon :: DataCon
886 nilDataCon = pcDataCon nilDataConName alpha_tyvar [] listTyCon
887
888 consDataCon :: DataCon
889 consDataCon = pcDataConWithFixity True {- Declared infix -}
890 consDataConName
891 alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
892 -- Interesting: polymorphic recursion would help here.
893 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
894 -- gets the over-specific type (Type -> Type)
895
896 -- Wired-in type Maybe
897
898 maybeTyCon :: TyCon
899 maybeTyCon = pcTyCon False NonRecursive maybeTyConName Nothing alpha_tyvar
900 [nothingDataCon, justDataCon]
901
902 nothingDataCon :: DataCon
903 nothingDataCon = pcDataCon nothingDataConName alpha_tyvar [] maybeTyCon
904
905 justDataCon :: DataCon
906 justDataCon = pcDataCon justDataConName alpha_tyvar [alphaTy] maybeTyCon
907
908 {-
909 ** *********************************************************************
910 * *
911 The tuple types
912 * *
913 ************************************************************************
914
915 The tuple types are definitely magic, because they form an infinite
916 family.
917
918 \begin{itemize}
919 \item
920 They have a special family of type constructors, of type @TyCon@
921 These contain the tycon arity, but don't require a Unique.
922
923 \item
924 They have a special family of constructors, of type
925 @Id@. Again these contain their arity but don't need a Unique.
926
927 \item
928 There should be a magic way of generating the info tables and
929 entry code for all tuples.
930
931 But at the moment we just compile a Haskell source
932 file\srcloc{lib/prelude/...} containing declarations like:
933 \begin{verbatim}
934 data Tuple0 = Tup0
935 data Tuple2 a b = Tup2 a b
936 data Tuple3 a b c = Tup3 a b c
937 data Tuple4 a b c d = Tup4 a b c d
938 ...
939 \end{verbatim}
940 The print-names associated with the magic @Id@s for tuple constructors
941 ``just happen'' to be the same as those generated by these
942 declarations.
943
944 \item
945 The instance environment should have a magic way to know
946 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
947 so on. \ToDo{Not implemented yet.}
948
949 \item
950 There should also be a way to generate the appropriate code for each
951 of these instances, but (like the info tables and entry code) it is
952 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
953 \end{itemize}
954 -}
955
956 -- | Make a tuple type. The list of types should /not/ include any
957 -- levity specifications.
958 mkTupleTy :: Boxity -> [Type] -> Type
959 -- Special case for *boxed* 1-tuples, which are represented by the type itself
960 mkTupleTy Boxed [ty] = ty
961 mkTupleTy Boxed tys = mkTyConApp (tupleTyCon Boxed (length tys)) tys
962 mkTupleTy Unboxed tys = mkTyConApp (tupleTyCon Unboxed (length tys))
963 (map (getLevity "mkTupleTy") tys ++ tys)
964
965 -- | Build the type of a small tuple that holds the specified type of thing
966 mkBoxedTupleTy :: [Type] -> Type
967 mkBoxedTupleTy tys = mkTupleTy Boxed tys
968
969 unitTy :: Type
970 unitTy = mkTupleTy Boxed []
971
972
973 {- *********************************************************************
974 * *
975 The parallel-array type, [::]
976 * *
977 ************************************************************************
978
979 Special syntax for parallel arrays needs some wired in definitions.
980 -}
981
982 -- | Construct a type representing the application of the parallel array constructor
983 mkPArrTy :: Type -> Type
984 mkPArrTy ty = mkTyConApp parrTyCon [ty]
985
986 -- | Represents the type constructor of parallel arrays
987 --
988 -- * This must match the definition in @PrelPArr@
989 --
990 -- NB: Although the constructor is given here, it will not be accessible in
991 -- user code as it is not in the environment of any compiled module except
992 -- @PrelPArr@.
993 --
994 parrTyCon :: TyCon
995 parrTyCon = pcNonRecDataTyCon parrTyConName Nothing alpha_tyvar [parrDataCon]
996
997 parrDataCon :: DataCon
998 parrDataCon = pcDataCon
999 parrDataConName
1000 alpha_tyvar -- forall'ed type variables
1001 [intTy, -- 1st argument: Int
1002 mkTyConApp -- 2nd argument: Array# a
1003 arrayPrimTyCon
1004 alpha_ty]
1005 parrTyCon
1006
1007 -- | Check whether a type constructor is the constructor for parallel arrays
1008 isPArrTyCon :: TyCon -> Bool
1009 isPArrTyCon tc = tyConName tc == parrTyConName
1010
1011 -- | Fake array constructors
1012 --
1013 -- * These constructors are never really used to represent array values;
1014 -- however, they are very convenient during desugaring (and, in particular,
1015 -- in the pattern matching compiler) to treat array pattern just like
1016 -- yet another constructor pattern
1017 --
1018 parrFakeCon :: Arity -> DataCon
1019 parrFakeCon i | i > mAX_TUPLE_SIZE = mkPArrFakeCon i -- build one specially
1020 parrFakeCon i = parrFakeConArr!i
1021
1022 -- pre-defined set of constructors
1023 --
1024 parrFakeConArr :: Array Int DataCon
1025 parrFakeConArr = array (0, mAX_TUPLE_SIZE) [(i, mkPArrFakeCon i)
1026 | i <- [0..mAX_TUPLE_SIZE]]
1027
1028 -- build a fake parallel array constructor for the given arity
1029 --
1030 mkPArrFakeCon :: Int -> DataCon
1031 mkPArrFakeCon arity = data_con
1032 where
1033 data_con = pcDataCon name [tyvar] tyvarTys parrTyCon
1034 tyvar = head alphaTyVars
1035 tyvarTys = replicate arity $ mkTyVarTy tyvar
1036 nameStr = mkFastString ("MkPArr" ++ show arity)
1037 name = mkWiredInName gHC_PARR' (mkDataOccFS nameStr) unique
1038 (AConLike (RealDataCon data_con)) UserSyntax
1039 unique = mkPArrDataConUnique arity
1040
1041 -- | Checks whether a data constructor is a fake constructor for parallel arrays
1042 isPArrFakeCon :: DataCon -> Bool
1043 isPArrFakeCon dcon = dcon == parrFakeCon (dataConSourceArity dcon)
1044
1045 -- Promoted Booleans
1046
1047 promotedFalseDataCon, promotedTrueDataCon :: TyCon
1048 promotedTrueDataCon = promoteDataCon trueDataCon
1049 promotedFalseDataCon = promoteDataCon falseDataCon
1050
1051 -- Promoted Maybe
1052 promotedNothingDataCon, promotedJustDataCon :: TyCon
1053 promotedNothingDataCon = promoteDataCon nothingDataCon
1054 promotedJustDataCon = promoteDataCon justDataCon
1055
1056 -- Promoted Ordering
1057
1058 promotedLTDataCon
1059 , promotedEQDataCon
1060 , promotedGTDataCon
1061 :: TyCon
1062 promotedLTDataCon = promoteDataCon ltDataCon
1063 promotedEQDataCon = promoteDataCon eqDataCon
1064 promotedGTDataCon = promoteDataCon gtDataCon
1065
1066 {-
1067 Note [The Implicit Parameter class]
1068
1069 Implicit parameters `?x :: a` are desugared into dictionaries for the
1070 class `IP "x" a`, which is defined (in GHC.Classes) as
1071
1072 class IP (x :: Symbol) a | x -> a
1073
1074 This class is wired-in so that `error` and `undefined`, which have
1075 wired-in types, can use the implicit-call-stack feature to provide
1076 a call-stack alongside the error message.
1077 -}
1078
1079 ipDataConName, ipTyConName, ipCoName :: Name
1080 ipDataConName = mkWiredInDataConName UserSyntax gHC_CLASSES (fsLit "IP")
1081 ipDataConKey ipDataCon
1082 ipTyConName = mkWiredInTyConName UserSyntax gHC_CLASSES (fsLit "IP")
1083 ipTyConKey ipTyCon
1084 ipCoName = mkWiredInCoAxiomName BuiltInSyntax gHC_CLASSES (fsLit "NTCo:IP")
1085 ipCoNameKey (toBranchedAxiom ipCoAxiom)
1086
1087 -- See Note [The Implicit Parameter class]
1088 ipTyCon :: TyCon
1089 ipTyCon = mkClassTyCon ipTyConName kind [ip,a] [] rhs ipClass NonRecursive
1090 (mkPrelTyConRepName ipTyConName)
1091 where
1092 kind = mkFunTys [typeSymbolKind, liftedTypeKind] constraintKind
1093 [ip,a] = mkTemplateTyVars [typeSymbolKind, liftedTypeKind]
1094 rhs = NewTyCon ipDataCon (mkTyVarTy a) ([], mkTyVarTy a) ipCoAxiom
1095
1096 ipCoAxiom :: CoAxiom Unbranched
1097 ipCoAxiom = mkNewTypeCoAxiom ipCoName ipTyCon [ip,a] [Nominal, Nominal] (mkTyVarTy a)
1098 where
1099 [ip,a] = mkTemplateTyVars [typeSymbolKind, liftedTypeKind]
1100
1101 ipDataCon :: DataCon
1102 ipDataCon = pcDataCon ipDataConName [ip,a] ts ipTyCon
1103 where
1104 [ip,a] = mkTemplateTyVars [typeSymbolKind, liftedTypeKind]
1105 ts = [mkTyVarTy a]
1106
1107 ipClass :: Class
1108 ipClass = mkClass (tyConTyVars ipTyCon) [([ip], [a])] [] [] [] [] (mkAnd [])
1109 ipTyCon
1110 where
1111 [ip, a] = tyConTyVars ipTyCon
1112
1113 -- this is a fake version of the CallStack TyCon so we can refer to it
1114 -- in MkCore.errorTy
1115 callStackTyCon :: TyCon
1116 callStackTyCon = pcNonRecDataTyCon callStackTyConName Nothing [] []