958feb47da8bd08f4c47e27899489f4482ffab29
[ghc-hetmet.git] / compiler / hsSyn / HsUtils.lhs
1
2 %
3 % (c) The University of Glasgow, 1992-2006
4 %
5
6 Here we collect a variety of helper functions that construct or
7 analyse HsSyn.  All these functions deal with generic HsSyn; functions
8 which deal with the intantiated versions are located elsewhere:
9
10    Parameterised by     Module
11    ----------------     -------------
12    RdrName              parser/RdrHsSyn
13    Name                 rename/RnHsSyn
14    Id                   typecheck/TcHsSyn       
15
16 \begin{code}
17 module HsUtils where
18
19 import HsBinds
20 import HsExpr
21 import HsPat
22 import HsTypes  
23 import HsLit
24
25 import RdrName
26 import Var
27 import Coercion
28 import Type
29 import DataCon
30 import Name
31 import BasicTypes
32 import SrcLoc
33 import FastString
34 import Outputable
35 import Util
36 import Bag
37 \end{code}
38
39
40 %************************************************************************
41 %*                                                                      *
42         Some useful helpers for constructing syntax
43 %*                                                                      *
44 %************************************************************************
45
46 These functions attempt to construct a not-completely-useless SrcSpan
47 from their components, compared with the nl* functions below which
48 just attach noSrcSpan to everything.
49
50 \begin{code}
51 mkHsPar :: LHsExpr id -> LHsExpr id
52 mkHsPar e = L (getLoc e) (HsPar e)
53
54 mkSimpleMatch :: [LPat id] -> LHsExpr id -> LMatch id
55 mkSimpleMatch pats rhs 
56   = L loc $
57     Match pats Nothing (unguardedGRHSs rhs)
58   where
59     loc = case pats of
60                 []      -> getLoc rhs
61                 (pat:_) -> combineSrcSpans (getLoc pat) (getLoc rhs)
62
63 unguardedGRHSs :: LHsExpr id -> GRHSs id
64 unguardedGRHSs rhs = GRHSs (unguardedRHS rhs) emptyLocalBinds
65
66 unguardedRHS :: LHsExpr id -> [LGRHS id]
67 unguardedRHS rhs@(L loc _) = [L loc (GRHS [] rhs)]
68
69 mkHsAppTy :: LHsType name -> LHsType name -> LHsType name
70 mkHsAppTy t1 t2 = addCLoc t1 t2 (HsAppTy t1 t2)
71
72 mkHsApp :: LHsExpr name -> LHsExpr name -> LHsExpr name
73 mkHsApp e1 e2 = addCLoc e1 e2 (HsApp e1 e2)
74
75 nlHsTyApp :: name -> [Type] -> LHsExpr name
76 nlHsTyApp fun_id tys = noLoc (HsWrap (mkWpTyApps tys) (HsVar fun_id))
77
78 mkLHsWrap :: HsWrapper -> LHsExpr id -> LHsExpr id
79 mkLHsWrap co_fn (L loc e) = L loc (mkHsWrap co_fn e)
80
81 mkHsWrap :: HsWrapper -> HsExpr id -> HsExpr id
82 mkHsWrap co_fn e | isIdHsWrapper co_fn = e
83                  | otherwise           = HsWrap co_fn e
84
85 mkHsWrapCoI :: CoercionI -> HsExpr id -> HsExpr id
86 mkHsWrapCoI IdCo     e = e
87 mkHsWrapCoI (ACo co) e = mkHsWrap (WpCast co) e
88
89 coiToHsWrapper :: CoercionI -> HsWrapper
90 coiToHsWrapper IdCo     = idHsWrapper
91 coiToHsWrapper (ACo co) = WpCast co
92
93 mkHsLam :: [LPat id] -> LHsExpr id -> LHsExpr id
94 mkHsLam pats body = mkHsPar (L (getLoc body) (HsLam matches))
95         where
96           matches = mkMatchGroup [mkSimpleMatch pats body]
97
98 mkMatchGroup :: [LMatch id] -> MatchGroup id
99 mkMatchGroup matches = MatchGroup matches placeHolderType
100
101 mkHsDictLet :: LHsBinds Id -> LHsExpr Id -> LHsExpr Id
102 -- Used for the dictionary bindings gotten from TcSimplify
103 -- We make them recursive to be on the safe side
104 mkHsDictLet binds expr 
105   | isEmptyLHsBinds binds = expr
106   | otherwise             = L (getLoc expr) (HsLet (HsValBinds val_binds) expr)
107                           where
108                             val_binds = ValBindsOut [(Recursive, binds)] []
109
110 mkHsConApp :: DataCon -> [Type] -> [HsExpr Id] -> LHsExpr Id
111 -- Used for constructing dictionary terms etc, so no locations 
112 mkHsConApp data_con tys args 
113   = foldl mk_app (nlHsTyApp (dataConWrapId data_con) tys) args
114   where
115     mk_app f a = noLoc (HsApp f (noLoc a))
116
117 mkSimpleHsAlt :: LPat id -> LHsExpr id -> LMatch id
118 -- A simple lambda with a single pattern, no binds, no guards; pre-typechecking
119 mkSimpleHsAlt pat expr 
120   = mkSimpleMatch [pat] expr
121
122 -------------------------------
123 -- These are the bits of syntax that contain rebindable names
124 -- See RnEnv.lookupSyntaxName
125
126 mkHsIntegral   :: Integer -> PostTcType -> HsOverLit id
127 mkHsFractional :: Rational -> PostTcType -> HsOverLit id
128 mkHsIsString   :: FastString -> PostTcType -> HsOverLit id
129 mkHsDo         :: HsStmtContext Name -> [LStmt id] -> LHsExpr id -> HsExpr id
130
131 mkNPat      :: HsOverLit id -> Maybe (SyntaxExpr id) -> Pat id
132 mkNPlusKPat :: Located id -> HsOverLit id -> Pat id
133
134 mkTransformStmt   :: [LStmt idL] -> LHsExpr idR                -> StmtLR idL idR
135 mkTransformByStmt :: [LStmt idL] -> LHsExpr idR -> LHsExpr idR -> StmtLR idL idR
136
137 mkGroupUsingStmt   :: [LStmt idL]                -> LHsExpr idR -> StmtLR idL idR
138 mkGroupByStmt      :: [LStmt idL] -> LHsExpr idR                -> StmtLR idL idR
139 mkGroupByUsingStmt :: [LStmt idL] -> LHsExpr idR -> LHsExpr idR -> StmtLR idL idR
140
141 mkExprStmt :: LHsExpr idR -> StmtLR idL idR
142 mkBindStmt :: LPat idL -> LHsExpr idR -> StmtLR idL idR
143 mkRecStmt  :: [LStmtLR idL idR] -> StmtLR idL idR
144
145
146 mkHsIntegral   i       = OverLit (HsIntegral   i)  noRebindableInfo noSyntaxExpr
147 mkHsFractional f       = OverLit (HsFractional f)  noRebindableInfo noSyntaxExpr
148 mkHsIsString   s       = OverLit (HsIsString   s)  noRebindableInfo noSyntaxExpr
149
150 noRebindableInfo :: Bool
151 noRebindableInfo = error "noRebindableInfo"     -- Just another placeholder; 
152
153 mkHsDo ctxt stmts body = HsDo ctxt stmts body placeHolderType
154
155 mkNPat lit neg     = NPat lit neg noSyntaxExpr
156 mkNPlusKPat id lit = NPlusKPat id lit noSyntaxExpr noSyntaxExpr
157
158 mkTransformStmt   stmts usingExpr        = TransformStmt (stmts, []) usingExpr Nothing
159 mkTransformByStmt stmts usingExpr byExpr = TransformStmt (stmts, []) usingExpr (Just byExpr)
160
161 mkGroupUsingStmt   stmts usingExpr        = GroupStmt (stmts, []) (GroupByNothing usingExpr)
162 mkGroupByStmt      stmts byExpr           = GroupStmt (stmts, []) (GroupBySomething (Right noSyntaxExpr) byExpr)
163 mkGroupByUsingStmt stmts byExpr usingExpr = GroupStmt (stmts, []) (GroupBySomething (Left usingExpr) byExpr)
164
165 mkExprStmt expr     = ExprStmt expr noSyntaxExpr placeHolderType
166 mkBindStmt pat expr = BindStmt pat expr noSyntaxExpr noSyntaxExpr
167 mkRecStmt stmts     = RecStmt stmts [] [] [] emptyLHsBinds
168
169 -------------------------------
170 --- A useful function for building @OpApps@.  The operator is always a
171 -- variable, and we don't know the fixity yet.
172 mkHsOpApp :: LHsExpr id -> id -> LHsExpr id -> HsExpr id
173 mkHsOpApp e1 op e2 = OpApp e1 (noLoc (HsVar op)) (error "mkOpApp:fixity") e2
174
175 mkHsSplice :: LHsExpr RdrName -> HsSplice RdrName
176 mkHsSplice e = HsSplice unqualSplice e
177
178 unqualSplice :: RdrName
179 unqualSplice = mkRdrUnqual (mkVarOccFS (fsLit "splice"))
180                 -- A name (uniquified later) to
181                 -- identify the splice
182
183 mkHsQuasiQuote :: RdrName -> SrcSpan -> FastString -> HsQuasiQuote RdrName
184 mkHsQuasiQuote quoter span quote = HsQuasiQuote unqualQuasiQuote quoter span quote
185
186 unqualQuasiQuote :: RdrName
187 unqualQuasiQuote = mkRdrUnqual (mkVarOccFS (fsLit "quasiquote"))
188                 -- A name (uniquified later) to
189                 -- identify the quasi-quote
190
191 mkHsString :: String -> HsLit
192 mkHsString s = HsString (mkFastString s)
193
194 -------------
195 userHsTyVarBndrs :: [Located name] -> [Located (HsTyVarBndr name)]
196 userHsTyVarBndrs bndrs = [ L loc (UserTyVar v) | L loc v <- bndrs ]
197 \end{code}
198
199
200 %************************************************************************
201 %*                                                                      *
202         Constructing syntax with no location info
203 %*                                                                      *
204 %************************************************************************
205
206 \begin{code}
207 nlHsVar :: id -> LHsExpr id
208 nlHsVar n = noLoc (HsVar n)
209
210 nlHsLit :: HsLit -> LHsExpr id
211 nlHsLit n = noLoc (HsLit n)
212
213 nlVarPat :: id -> LPat id
214 nlVarPat n = noLoc (VarPat n)
215
216 nlLitPat :: HsLit -> LPat id
217 nlLitPat l = noLoc (LitPat l)
218
219 nlHsApp :: LHsExpr id -> LHsExpr id -> LHsExpr id
220 nlHsApp f x = noLoc (HsApp f x)
221
222 nlHsIntLit :: Integer -> LHsExpr id
223 nlHsIntLit n = noLoc (HsLit (HsInt n))
224
225 nlHsApps :: id -> [LHsExpr id] -> LHsExpr id
226 nlHsApps f xs = foldl nlHsApp (nlHsVar f) xs
227              
228 nlHsVarApps :: id -> [id] -> LHsExpr id
229 nlHsVarApps f xs = noLoc (foldl mk (HsVar f) (map HsVar xs))
230                  where
231                    mk f a = HsApp (noLoc f) (noLoc a)
232
233 nlConVarPat :: id -> [id] -> LPat id
234 nlConVarPat con vars = nlConPat con (map nlVarPat vars)
235
236 nlInfixConPat :: id -> LPat id -> LPat id -> LPat id
237 nlInfixConPat con l r = noLoc (ConPatIn (noLoc con) (InfixCon l r))
238
239 nlConPat :: id -> [LPat id] -> LPat id
240 nlConPat con pats = noLoc (ConPatIn (noLoc con) (PrefixCon pats))
241
242 nlNullaryConPat :: id -> LPat id
243 nlNullaryConPat con = noLoc (ConPatIn (noLoc con) (PrefixCon []))
244
245 nlWildConPat :: DataCon -> LPat RdrName
246 nlWildConPat con = noLoc (ConPatIn (noLoc (getRdrName con))
247                                    (PrefixCon (nOfThem (dataConSourceArity con) nlWildPat)))
248
249 nlTuplePat :: [LPat id] -> Boxity -> LPat id
250 nlTuplePat pats box = noLoc (TuplePat pats box placeHolderType)
251
252 nlWildPat :: LPat id
253 nlWildPat  = noLoc (WildPat placeHolderType)    -- Pre-typechecking
254
255 nlHsDo :: HsStmtContext Name -> [LStmt id] -> LHsExpr id -> LHsExpr id
256 nlHsDo ctxt stmts body = noLoc (mkHsDo ctxt stmts body)
257
258 nlHsOpApp :: LHsExpr id -> id -> LHsExpr id -> LHsExpr id
259 nlHsOpApp e1 op e2 = noLoc (mkHsOpApp e1 op e2)
260
261 nlHsLam  :: LMatch id -> LHsExpr id
262 nlHsPar  :: LHsExpr id -> LHsExpr id
263 nlHsIf   :: LHsExpr id -> LHsExpr id -> LHsExpr id -> LHsExpr id
264 nlHsCase :: LHsExpr id -> [LMatch id] -> LHsExpr id
265 nlTuple  :: [LHsExpr id] -> Boxity -> LHsExpr id
266 nlList   :: [LHsExpr id] -> LHsExpr id
267
268 nlHsLam match           = noLoc (HsLam (mkMatchGroup [match]))
269 nlHsPar e               = noLoc (HsPar e)
270 nlHsIf cond true false  = noLoc (HsIf cond true false)
271 nlHsCase expr matches   = noLoc (HsCase expr (mkMatchGroup matches))
272 nlTuple exprs box       = noLoc (ExplicitTuple exprs box)
273 nlList exprs            = noLoc (ExplicitList placeHolderType exprs)
274
275 nlHsAppTy :: LHsType name -> LHsType name -> LHsType name
276 nlHsTyVar :: name                         -> LHsType name
277 nlHsFunTy :: LHsType name -> LHsType name -> LHsType name
278
279 nlHsAppTy f t           = noLoc (HsAppTy f t)
280 nlHsTyVar x             = noLoc (HsTyVar x)
281 nlHsFunTy a b           = noLoc (HsFunTy a b)
282
283 nlHsTyConApp :: name -> [LHsType name] -> LHsType name
284 nlHsTyConApp tycon tys  = foldl nlHsAppTy (nlHsTyVar tycon) tys
285 \end{code}
286
287
288
289 %************************************************************************
290 %*                                                                      *
291                 Bindings; with a location at the top
292 %*                                                                      *
293 %************************************************************************
294
295 \begin{code}
296 mkFunBind :: Located id -> [LMatch id] -> HsBind id
297 -- Not infix, with place holders for coercion and free vars
298 mkFunBind fn ms = FunBind { fun_id = fn, fun_infix = False, fun_matches = mkMatchGroup ms,
299                             fun_co_fn = idHsWrapper, bind_fvs = placeHolderNames,
300                             fun_tick = Nothing }
301
302
303 mkHsVarBind :: SrcSpan -> id -> LHsExpr id -> LHsBind id
304 mkHsVarBind loc var rhs = mk_easy_FunBind loc var [] rhs
305
306 mkVarBind :: id -> LHsExpr id -> LHsBind id
307 mkVarBind var rhs = L (getLoc rhs) $
308                     VarBind { var_id = var, var_rhs = rhs, var_inline = False }
309
310 ------------
311 mk_easy_FunBind :: SrcSpan -> id -> [LPat id]
312                 -> LHsExpr id -> LHsBind id
313
314 mk_easy_FunBind loc fun pats expr
315   = L loc $ mkFunBind (L loc fun) [mkMatch pats expr emptyLocalBinds]
316
317 ------------
318 mk_FunBind :: SrcSpan -> id
319            -> [([LPat id], LHsExpr id)]
320            -> LHsBind id
321
322 mk_FunBind _   _   [] = panic "TcGenDeriv:mk_FunBind"
323 mk_FunBind loc fun pats_and_exprs
324   = L loc $ mkFunBind (L loc fun) matches
325   where
326     matches = [mkMatch p e emptyLocalBinds | (p,e) <-pats_and_exprs]
327
328 ------------
329 mkMatch :: [LPat id] -> LHsExpr id -> HsLocalBinds id -> LMatch id
330 mkMatch pats expr binds
331   = noLoc (Match (map paren pats) Nothing 
332                  (GRHSs (unguardedRHS expr) binds))
333   where
334     paren p = case p of
335                 L _ (VarPat _) -> p
336                 L l _          -> L l (ParPat p)
337 \end{code}
338
339
340 %************************************************************************
341 %*                                                                      *
342         Collecting binders from HsBindGroups and HsBinds
343 %*                                                                      *
344 %************************************************************************
345
346 Get all the binders in some HsBindGroups, IN THE ORDER OF APPEARANCE. eg.
347
348 ...
349 where
350   (x, y) = ...
351   f i j  = ...
352   [a, b] = ...
353
354 it should return [x, y, f, a, b] (remember, order important).
355
356 \begin{code}
357 collectLocalBinders :: HsLocalBindsLR idL idR -> [Located idL]
358 collectLocalBinders (HsValBinds val_binds) = collectHsValBinders val_binds
359 collectLocalBinders (HsIPBinds _)   = []
360 collectLocalBinders EmptyLocalBinds = []
361
362 collectHsValBinders :: HsValBindsLR idL idR -> [Located idL]
363 collectHsValBinders (ValBindsIn  binds _) = collectHsBindLocatedBinders binds
364 collectHsValBinders (ValBindsOut binds _) = foldr collect_one [] binds
365   where
366    collect_one (_,binds) acc = foldrBag (collectAcc . unLoc) acc binds
367
368 collectAcc :: HsBindLR idL idR -> [Located idL] -> [Located idL]
369 collectAcc (PatBind { pat_lhs = p }) acc = collectLocatedPatBinders p ++ acc
370 collectAcc (FunBind { fun_id = f })  acc    = f : acc
371 collectAcc (VarBind { var_id = f })  acc    = noLoc f : acc
372 collectAcc (AbsBinds { abs_exports = dbinds, abs_binds = _binds }) acc
373   = [noLoc dp | (_,dp,_,_) <- dbinds] ++ acc
374         -- ++ foldr collectAcc acc binds
375         -- I don't think we want the binders from the nested binds
376         -- The only time we collect binders from a typechecked 
377         -- binding (hence see AbsBinds) is in zonking in TcHsSyn
378
379 collectHsBindBinders :: LHsBindsLR idL idR -> [idL]
380 collectHsBindBinders binds = map unLoc (collectHsBindLocatedBinders binds)
381
382 collectHsBindLocatedBinders :: LHsBindsLR idL idR -> [Located idL]
383 collectHsBindLocatedBinders binds = foldrBag (collectAcc . unLoc) [] binds
384 \end{code}
385
386
387 %************************************************************************
388 %*                                                                      *
389         Getting binders from statements
390 %*                                                                      *
391 %************************************************************************
392
393 \begin{code}
394 collectLStmtsBinders :: [LStmtLR idL idR] -> [Located idL]
395 collectLStmtsBinders = concatMap collectLStmtBinders
396
397 collectStmtsBinders :: [StmtLR idL idR] -> [Located idL]
398 collectStmtsBinders = concatMap collectStmtBinders
399
400 collectLStmtBinders :: LStmtLR idL idR -> [Located idL]
401 collectLStmtBinders = collectStmtBinders . unLoc
402
403 collectStmtBinders :: StmtLR idL idR -> [Located idL]
404   -- Id Binders for a Stmt... [but what about pattern-sig type vars]?
405 collectStmtBinders (BindStmt pat _ _ _) = collectLocatedPatBinders pat
406 collectStmtBinders (LetStmt binds)      = collectLocalBinders binds
407 collectStmtBinders (ExprStmt _ _ _)     = []
408 collectStmtBinders (ParStmt xs)         = collectLStmtsBinders
409                                         $ concatMap fst xs
410 collectStmtBinders (TransformStmt (stmts, _) _ _) = collectLStmtsBinders stmts
411 collectStmtBinders (GroupStmt (stmts, _) _)     = collectLStmtsBinders stmts
412 collectStmtBinders (RecStmt ss _ _ _ _) = collectLStmtsBinders ss
413 \end{code}
414
415
416 %************************************************************************
417 %*                                                                      *
418 %*      Gathering stuff out of patterns
419 %*                                                                      *
420 %************************************************************************
421
422 This function @collectPatBinders@ works with the ``collectBinders''
423 functions for @HsBinds@, etc.  The order in which the binders are
424 collected is important; see @HsBinds.lhs@.
425
426 It collects the bounds *value* variables in renamed patterns; type variables
427 are *not* collected.
428
429 \begin{code}
430 collectPatBinders :: LPat a -> [a]
431 collectPatBinders pat = map unLoc (collectLocatedPatBinders pat)
432
433 collectLocatedPatBinders :: LPat a -> [Located a]
434 collectLocatedPatBinders pat = collectl pat []
435
436 collectPatsBinders :: [LPat a] -> [a]
437 collectPatsBinders pats = map unLoc (collectLocatedPatsBinders pats)
438
439 collectLocatedPatsBinders :: [LPat a] -> [Located a]
440 collectLocatedPatsBinders pats = foldr collectl [] pats
441
442 ---------------------
443 collectl :: LPat name -> [Located name] -> [Located name]
444 collectl (L l pat) bndrs
445   = go pat
446   where
447     go (VarPat var)               = L l var : bndrs
448     go (VarPatOut var bs)         = L l var : collectHsBindLocatedBinders bs 
449                                     ++ bndrs
450     go (WildPat _)                = bndrs
451     go (LazyPat pat)              = collectl pat bndrs
452     go (BangPat pat)              = collectl pat bndrs
453     go (AsPat a pat)              = a : collectl pat bndrs
454     go (ViewPat _ pat _)          = collectl pat bndrs
455     go (ParPat  pat)              = collectl pat bndrs
456                                   
457     go (ListPat pats _)           = foldr collectl bndrs pats
458     go (PArrPat pats _)           = foldr collectl bndrs pats
459     go (TuplePat pats _ _)        = foldr collectl bndrs pats
460                                   
461     go (ConPatIn _ ps)            = foldr collectl bndrs (hsConPatArgs ps)
462     go (ConPatOut {pat_args=ps})  = foldr collectl bndrs (hsConPatArgs ps)
463         -- See Note [Dictionary binders in ConPatOut]
464     go (LitPat _)                 = bndrs
465     go (NPat _ _ _)               = bndrs
466     go (NPlusKPat n _ _ _)        = n : bndrs
467                                   
468     go (SigPatIn pat _)           = collectl pat bndrs
469     go (SigPatOut pat _)          = collectl pat bndrs
470     go (QuasiQuotePat _)          = bndrs
471     go (TypePat _)                = bndrs
472     go (CoPat _ pat _)            = collectl (noLoc pat) bndrs
473 \end{code}
474
475 Note [Dictionary binders in ConPatOut]
476 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
477 Do *not* gather (a) dictionary and (b) dictionary bindings as binders
478 of a ConPatOut pattern.  For most calls it doesn't matter, because
479 it's pre-typechecker and there are no ConPatOuts.  But it does matter
480 more in the desugarer; for example, DsUtils.mkSelectorBinds uses
481 collectPatBinders.  In a lazy pattern, for example f ~(C x y) = ...,
482 we want to generate bindings for x,y but not for dictionaries bound by
483 C.  (The type checker ensures they would not be used.)
484
485 Desugaring of arrow case expressions needs these bindings (see DsArrows
486 and arrowcase1), but SPJ (Jan 2007) says it's safer for it to use its
487 own pat-binder-collector:
488
489 Here's the problem.  Consider
490
491 data T a where
492    C :: Num a => a -> Int -> T a
493
494 f ~(C (n+1) m) = (n,m)
495
496 Here, the pattern (C (n+1)) binds a hidden dictionary (d::Num a),
497 and *also* uses that dictionary to match the (n+1) pattern.  Yet, the
498 variables bound by the lazy pattern are n,m, *not* the dictionary d.
499 So in mkSelectorBinds in DsUtils, we want just m,n as the variables bound.
500
501 \begin{code}
502 collectSigTysFromPats :: [InPat name] -> [LHsType name]
503 collectSigTysFromPats pats = foldr collect_lpat [] pats
504
505 collectSigTysFromPat :: InPat name -> [LHsType name]
506 collectSigTysFromPat pat = collect_lpat pat []
507
508 collect_lpat :: InPat name -> [LHsType name] -> [LHsType name]
509 collect_lpat pat acc = collect_pat (unLoc pat) acc
510
511 collect_pat :: Pat name -> [LHsType name] -> [LHsType name]
512 collect_pat (SigPatIn pat ty)   acc = collect_lpat pat (ty:acc)
513 collect_pat (TypePat ty)        acc = ty:acc
514
515 collect_pat (LazyPat pat)       acc = collect_lpat pat acc
516 collect_pat (BangPat pat)       acc = collect_lpat pat acc
517 collect_pat (AsPat _ pat)       acc = collect_lpat pat acc
518 collect_pat (ParPat  pat)       acc = collect_lpat pat acc
519 collect_pat (ListPat pats _)    acc = foldr collect_lpat acc pats
520 collect_pat (PArrPat pats _)    acc = foldr collect_lpat acc pats
521 collect_pat (TuplePat pats _ _) acc = foldr collect_lpat acc pats
522 collect_pat (ConPatIn _ ps)     acc = foldr collect_lpat acc (hsConPatArgs ps)
523 collect_pat _                   acc = acc       -- Literals, vars, wildcard
524 \end{code}