Deal correctly with infix type constructors in GADT decls
[ghc-hetmet.git] / compiler / prelude / PrelInfo.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[PrelInfo]{The @PrelInfo@ interface to the compiler's prelude knowledge}
5
6 \begin{code}
7 module PrelInfo (
8         module MkId,
9
10         ghcPrimExports,
11         wiredInThings, basicKnownKeyNames,
12         primOpId,
13         
14         -- Random other things
15         maybeCharLikeCon, maybeIntLikeCon,
16
17         -- Class categories
18         isNumericClass, isStandardClass
19
20     ) where
21
22 #include "HsVersions.h"
23
24 import PrelNames        ( basicKnownKeyNames, 
25                           hasKey, charDataConKey, intDataConKey,
26                           numericClassKeys, standardClassKeys )
27
28 import PrimOp           ( PrimOp, allThePrimOps, primOpOcc, primOpTag, maxPrimOpTag )
29 import DataCon          ( DataCon )
30 import Id               ( Id, idName )
31 import MkId             ( mkPrimOpId, wiredInIds )
32 import MkId             -- All of it, for re-export
33 import Name             ( nameOccName )
34 import TysPrim          ( primTyCons )
35 import TysWiredIn       ( wiredInTyCons )
36 import HscTypes         ( TyThing(..), implicitTyThings, GenAvailInfo(..), RdrAvailInfo )
37 import Class            ( Class, classKey )
38 import Type             ( funTyCon )
39 import TyCon            ( tyConName )
40 import Util             ( isIn )
41
42 import Array            ( Array, array, (!) )
43 \end{code}
44
45 %************************************************************************
46 %*                                                                      *
47 \subsection[builtinNameInfo]{Lookup built-in names}
48 %*                                                                      *
49 %************************************************************************
50
51 Notes about wired in things
52 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
53 * Wired-in things are Ids/TyCons that are completely known to the compiler.
54   They are global values in GHC, (e.g.  listTyCon :: TyCon).
55
56 * A wired in Name contains the thing itself inside the Name: 
57         see Name.wiredInNameTyThing_maybe
58   (E.g. listTyConName contains listTyCon. 
59
60 * The name cache is initialised with (the names of) all wired-in things
61
62 * The type checker sees if the Name is wired in before looking up 
63   the name in the type environment.  So the type envt itself contains
64   no wired in things.
65
66 * MkIface prunes out wired-in things before putting them in an interface file.
67   So interface files never contain wired-in things.
68
69
70 \begin{code}
71 wiredInThings :: [TyThing]
72 wiredInThings           
73   = concat
74     [           -- Wired in TyCons and their implicit Ids
75           tycon_things
76         , concatMap implicitTyThings tycon_things
77
78                 -- Wired in Ids
79         , map AnId wiredInIds
80
81                 -- PrimOps
82         , map (AnId . mkPrimOpId) allThePrimOps
83     ]
84   where
85     tycon_things = map ATyCon ([funTyCon] ++ primTyCons ++ wiredInTyCons)
86 \end{code}
87
88 We let a lot of "non-standard" values be visible, so that we can make
89 sense of them in interface pragmas. It's cool, though they all have
90 "non-standard" names, so they won't get past the parser in user code.
91
92 %************************************************************************
93 %*                                                                      *
94                 PrimOpIds
95 %*                                                                      *
96 %************************************************************************
97
98 \begin{code}
99 primOpIds :: Array Int Id       -- Indexed by PrimOp tag
100 primOpIds = array (1,maxPrimOpTag) [ (primOpTag op, mkPrimOpId op) 
101                                    | op <- allThePrimOps]
102
103 primOpId :: PrimOp -> Id
104 primOpId op = primOpIds ! primOpTag op
105 \end{code}
106
107
108 %************************************************************************
109 %*                                                                      *
110 \subsection{Export lists for pseudo-modules (GHC.Prim)}
111 %*                                                                      *
112 %************************************************************************
113
114 GHC.Prim "exports" all the primops and primitive types, some 
115 wired-in Ids.
116
117 \begin{code}
118 ghcPrimExports :: [RdrAvailInfo]
119 ghcPrimExports
120  = map (Avail . nameOccName . idName) ghcPrimIds ++
121    map (Avail . primOpOcc) allThePrimOps ++
122    [ AvailTC occ [occ] |
123      n <- funTyCon : primTyCons, let occ = nameOccName (tyConName n) 
124    ]
125 \end{code}
126
127
128 %************************************************************************
129 %*                                                                      *
130 \subsection{Built-in keys}
131 %*                                                                      *
132 %************************************************************************
133
134 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
135
136 \begin{code}
137 maybeCharLikeCon, maybeIntLikeCon :: DataCon -> Bool
138 maybeCharLikeCon con = con `hasKey` charDataConKey
139 maybeIntLikeCon  con = con `hasKey` intDataConKey
140 \end{code}
141
142
143 %************************************************************************
144 %*                                                                      *
145 \subsection{Class predicates}
146 %*                                                                      *
147 %************************************************************************
148
149 \begin{code}
150 isNumericClass, isStandardClass :: Class -> Bool
151
152 isNumericClass     clas = classKey clas `is_elem` numericClassKeys
153 isStandardClass    clas = classKey clas `is_elem` standardClassKeys
154 is_elem = isIn "is_X_Class"
155 \end{code}