2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
4 \section[AbsSyntax]{Abstract syntax definition}
6 This module glues together the pieces of the Haskell abstract syntax,
7 which is declared in the various \tr{Hs*} modules. This module,
8 therefore, is almost nothing but re-exporting.
10 The abstract syntax, used in the front end of the compiler, follows
11 that of a paper on the static semantics of Haskell by Simon Peyton
12 Jones and Phil Wadler.
14 The abstract syntax is parameterised with respect to variables
15 (abbrev: \tr{name}) and patterns (abbrev: \tr{pat}); here is a typical
18 type ProtoNameExpr = Expr ProtoName ProtoNamePat
19 type TypecheckedExpr = Expr Id TypecheckedPat
21 Some parts of the syntax are unparameterised, because there is no
25 #include "HsVersions.h"
28 -- the mostly-parameterised data types
33 ClassPragmas, -- abstract
41 ImportedInterface(..),
45 InstancePragmas, -- abstract
56 GenPragmas, -- abstract
57 ClassOpPragmas, -- abstract
59 DataPragmas, -- abstract
60 TypePragmas, -- abstract
62 SpecialisedInstanceSig(..), -- a user pragma
65 Context(..), -- synonyms
68 -- synonyms for the (unparameterised) typechecker input
69 ProtoNameArithSeqInfo(..),
72 ProtoNameClassDecl(..),
73 ProtoNameClassPragmas(..),
76 ProtoNameDefaultDecl(..),
78 ProtoNameFixityDecl(..),
79 ProtoNameGRHSsAndBinds(..),
81 ProtoNameImportedInterface(..),
82 ProtoNameInstDecl(..),
83 ProtoNameInstancePragmas(..),
84 ProtoNameInterface(..),
87 ProtoNameMonoBinds(..),
88 ProtoNameMonoType(..),
90 ProtoNamePolyType(..),
93 ProtoNameClassOpSig(..),
94 ProtoNameGenPragmas(..),
95 ProtoNameClassOpPragmas(..),
97 ProtoNameDataPragmas(..),
98 ProtoNameSpecialisedInstanceSig(..),
99 ProtoNameDataTypeSig(..),
101 RenamedArithSeqInfo(..),
104 RenamedClassDecl(..),
105 RenamedClassPragmas(..),
108 RenamedDefaultDecl(..),
110 RenamedFixityDecl(..),
111 RenamedGRHSsAndBinds(..),
113 RenamedImportedInterface(..),
115 RenamedInstancePragmas(..),
116 RenamedInterface(..),
119 RenamedMonoBinds(..),
125 RenamedClassOpSig(..),
126 RenamedGenPragmas(..),
127 RenamedClassOpPragmas(..),
129 RenamedDataPragmas(..),
130 RenamedSpecialisedInstanceSig(..),
131 RenamedDataTypeSig(..),
133 -- synonyms for the (unparameterised) typechecker output
134 TypecheckedArithSeqInfo(..),
136 TypecheckedBinds(..),
138 TypecheckedGRHSsAndBinds(..),
140 TypecheckedMatch(..),
141 TypecheckedMonoBinds(..),
142 TypecheckedModule(..),
145 -- little help functions (AbsSynFuns)
146 collectTopLevelBinders,
147 collectBinders, collectTypedBinders,
149 collectMonoBindersAndLocs,
152 collectTypedPatBinders,
154 cmpInstanceTypes, getNonPrelOuterTyCon,
155 getIEStrings, getRawIEStrings, ImExportListInfo(..),
156 --OLD: getMentionedVars,
163 isLitPat, patsAreAllLits, isConPat, patsAreAllCons,
168 unfailablePat, unfailablePats,
173 eqConDecls, eqMonoType, cmpPolyType,
175 -- imported things so we get a closed interface
176 Outputable(..), NamedThing(..),
178 Pretty(..), PprStyle, PrettyRep,
180 OptIdInfo(..), -- I hate the instance virus!
181 IdInfo, SpecEnv, StrictnessInfo, UpdateInfo, ArityInfo,
182 DemandInfo, Demand, ArgUsageInfo, ArgUsage, DeforestInfo,
183 FBTypeInfo, FBType, FBConsum, FBProd,
185 Name(..), -- NB: goes out *WITH* constructors
186 Id, DictVar(..), Inst, ProtoName, TyVar, UniType, TauType(..),
187 Maybe, PreludeNameFun(..), Unique,
188 FullName, ShortName, Arity(..), TyCon, Class, ClassOp,
189 UnfoldingGuidance, BinderInfo, BasicLit, PrimOp, PrimKind,
190 IdEnv(..), UniqFM, FiniteMap,
191 CoreExpr, CoreAtom, UnfoldingCoreAtom, UnfoldingCoreExpr,
192 UnfoldingPrimOp, UfCostCentre, Bag
193 IF_ATTACK_PRAGMAS(COMMA cmpClass COMMA cmpTyCon COMMA cmpTyVar)
194 IF_ATTACK_PRAGMAS(COMMA cmpUniType COMMA pprPrimOp)
195 #ifndef __GLASGOW_HASKELL__
199 ,ParQuals(..), ProtoNameParQuals(..),
200 RenamedParQuals(..), TypecheckedParQuals(..),
201 collectParQualBinders
202 #endif {- Data Parallel Haskell -}
206 import AbsSynFuns -- help functions
208 import HsBinds -- the main stuff to export
219 import AbsPrel ( PrimKind, PrimOp
220 IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
221 IF_ATTACK_PRAGMAS(COMMA pprPrimOp)
223 import AbsUniType ( TyVar, TyCon, Arity(..), Class, ClassOp, TauType(..)
224 IF_ATTACK_PRAGMAS(COMMA cmpTyVar)
225 IF_ATTACK_PRAGMAS(COMMA cmpClass)
226 IF_ATTACK_PRAGMAS(COMMA cmpTyCon)
227 IF_ATTACK_PRAGMAS(COMMA cmpUniType)
229 import BasicLit ( BasicLit )
230 import FiniteMap ( FiniteMap )
231 import Id ( Id, DictVar(..), DataCon(..) )
234 import Maybes ( Maybe )
236 import NameTypes ( ShortName, FullName ) -- .. for pragmas only
239 import ProtoName ( ProtoName(..) ) -- .. for pragmas only
240 import SrcLoc ( SrcLoc )
241 import Unique ( Unique )
245 All we actually declare here is the top-level structure for a module.
249 FAST_STRING -- module name
251 [ImportedInterface name pat]
252 -- We snaffle interesting stuff out of the
253 -- imported interfaces early on, adding that
254 -- info to TyDecls/etc; so this list is
255 -- often empty, downstream.
258 [DataTypeSig name] -- user pragmas that modify TyDecls;
259 -- (much like "Sigs" modify value "Binds")
262 [SpecialisedInstanceSig name] -- user pragmas that modify InstDecls
264 (Binds name pat) -- the main stuff!
265 [Sig name] -- "Sigs" are folded into the "Binds"
266 -- pretty early on, so this list is
267 -- often either empty or just the
268 -- interface signatures.
273 type ProtoNameModule = Module ProtoName ProtoNamePat
274 type RenamedModule = Module Name RenamedPat
275 type TypecheckedModule = Module Id TypecheckedPat
279 instance (NamedThing name, Outputable name, NamedThing pat, Outputable pat) =>
280 Outputable (Module name pat) where
282 ppr sty (Module name exports imports fixities
283 typedecls typesigs classdecls instdecls instsigs
284 defdecls binds sigs src_loc)
286 ifPprShowAll sty (ppr sty src_loc),
288 then (ppCat [ppPStr SLIT("module"), ppPStr name, ppPStr SLIT("where")])
290 ppCat [ppPStr SLIT("module"), ppPStr name, ppLparen],
291 ppNest 8 (interpp'SP sty exports),
292 ppNest 4 (ppPStr SLIT(") where"))
294 ppr sty imports, ppr sty fixities,
295 ppr sty typedecls, ppr sty typesigs,
297 ppr sty instdecls, ppr sty instsigs,
299 ppr sty binds, ppr sty sigs