2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[DsExpr]{Matching expressions (Exprs)}
7 module DsExpr ( dsExpr, dsLet ) where
9 #include "HsVersions.h"
12 import HsSyn ( failureFreePat,
13 HsExpr(..), OutPat(..), HsLit(..), ArithSeqInfo(..),
14 Stmt(..), StmtCtxt(..), Match(..), HsBinds(..), MonoBinds(..),
17 import TcHsSyn ( TypecheckedHsExpr, TypecheckedHsBinds,
25 import DsBinds ( dsMonoBinds, AutoScc(..) )
26 import DsGRHSs ( dsGuarded )
27 import DsCCall ( dsCCall )
28 import DsListComp ( dsListComp )
29 import DsUtils ( mkErrorAppDs, mkDsLets, mkConsExpr, mkNilExpr )
30 import Match ( matchWrapper, matchSimply )
32 import CoreUtils ( coreExprType )
33 import CostCentre ( mkUserCC )
34 import FieldLabel ( FieldLabel )
35 import Id ( Id, idType, recordSelectorFieldLabel )
36 import Const ( Con(..) )
37 import DataCon ( DataCon, dataConId, dataConTyCon, dataConArgTys, dataConFieldLabels )
38 import Const ( mkMachInt, Literal(..), mkStrLit )
39 import PrelInfo ( rEC_CON_ERROR_ID, rEC_UPD_ERROR_ID, iRREFUT_PAT_ERROR_ID )
40 import TyCon ( isNewTyCon )
41 import DataCon ( isExistentialDataCon )
42 import Type ( splitFunTys, mkTyConApp,
43 splitAlgTyConApp, splitTyConApp_maybe, isNotUsgTy, unUsgTy,
44 splitAppTy, isUnLiftedType, Type
46 import TysWiredIn ( tupleCon, unboxedTupleCon,
48 charDataCon, charTy, stringTy
50 import BasicTypes ( RecFlag(..) )
51 import Maybes ( maybeToBool )
52 import Util ( zipEqual, zipWithEqual )
57 %************************************************************************
61 %************************************************************************
63 @dsLet@ is a match-result transformer, taking the @MatchResult@ for the body
64 and transforming it into one for the let-bindings enclosing the body.
66 This may seem a bit odd, but (source) let bindings can contain unboxed
71 This must be transformed to a case expression and, if the type has
72 more than one constructor, may fail.
75 dsLet :: TypecheckedHsBinds -> CoreExpr -> DsM CoreExpr
80 dsLet (ThenBinds b1 b2) body
81 = dsLet b2 body `thenDs` \ body' ->
84 -- Special case for bindings which bind unlifted variables
85 -- Silently ignore INLINE pragmas...
86 dsLet (MonoBind (AbsBinds [] [] binder_triples inlines
87 (PatMonoBind pat grhss loc)) sigs is_rec) body
88 | or [isUnLiftedType (idType g) | (_, g, l) <- binder_triples]
89 = ASSERT (case is_rec of {NonRecursive -> True; other -> False})
91 dsGuarded grhss `thenDs` \ rhs ->
93 body' = foldr bind body binder_triples
94 bind (tyvars, g, l) body = ASSERT( null tyvars )
95 bindNonRec g (Var l) body
97 mkErrorAppDs iRREFUT_PAT_ERROR_ID result_ty (showSDoc (ppr pat))
98 `thenDs` \ error_expr ->
99 matchSimply rhs PatBindMatch pat body' error_expr
101 result_ty = coreExprType body
103 -- Ordinary case for bindings
104 dsLet (MonoBind binds sigs is_rec) body
105 = dsMonoBinds NoSccs binds [] `thenDs` \ prs ->
107 Recursive -> returnDs (Let (Rec prs) body)
108 NonRecursive -> returnDs (mkDsLets [NonRec b r | (b,r) <- prs] body)
111 %************************************************************************
113 \subsection[DsExpr-vars-and-cons]{Variables and constructors}
115 %************************************************************************
118 dsExpr :: TypecheckedHsExpr -> DsM CoreExpr
120 dsExpr e@(HsVar var) = returnDs (Var var)
123 %************************************************************************
125 \subsection[DsExpr-literals]{Literals}
127 %************************************************************************
129 We give int/float literals type @Integer@ and @Rational@, respectively.
130 The typechecker will (presumably) have put \tr{from{Integer,Rational}s}
133 ToDo: put in range checks for when converting ``@i@''
134 (or should that be in the typechecker?)
136 For numeric literals, we try to detect there use at a standard type
137 (@Int@, @Float@, etc.) are directly put in the right constructor.
138 [NB: down with the @App@ conversion.]
139 Otherwise, we punt, putting in a @NoRep@ Core literal (where the
140 representation decisions are delayed)...
142 See also below where we look for @DictApps@ for \tr{plusInt}, etc.
145 dsExpr (HsLitOut (HsString s) _)
147 = returnDs (mkNilExpr charTy)
151 the_char = mkConApp charDataCon [mkLit (MachChar (_HEAD_ s))]
152 the_nil = mkNilExpr charTy
153 the_cons = mkConsExpr charTy the_char the_nil
158 -- "_" => build (\ c n -> c 'c' n) -- LATER
160 -- "str" ==> build (\ c n -> foldr charTy T c n "str")
163 dsExpr (HsLitOut (HsString str) _)
164 = newTyVarsDs [alphaTyVar] `thenDs` \ [new_tyvar] ->
166 new_ty = mkTyVarTy new_tyvar
169 charTy `mkFunTy` (new_ty `mkFunTy` new_ty),
171 mkForallTy [alphaTyVar]
172 ((charTy `mkFunTy` (alphaTy `mkFunTy` alphaTy))
173 `mkFunTy` (alphaTy `mkFunTy` alphaTy))
174 ] `thenDs` \ [c,n,g] ->
175 returnDs (mkBuild charTy new_tyvar c n g (
177 (CoTyApp (CoTyApp (Var foldrId) charTy) new_ty) *** ensure non-prim type ***
178 [VarArg c,VarArg n,LitArg (NoRepStr str)]))
181 -- otherwise, leave it as a NoRepStr;
182 -- the Core-to-STG pass will wrap it in an application of "unpackCStringId".
184 dsExpr (HsLitOut (HsString str) _)
185 = returnDs (mkLit (NoRepStr str stringTy))
187 dsExpr (HsLitOut (HsLitLit str) ty)
189 = returnDs (mkLit (MachLitLit str ty))
191 = case (maybeBoxedPrimType ty) of
192 Just (boxing_data_con, prim_ty) ->
193 returnDs ( mkConApp boxing_data_con [mkLit (MachLitLit str prim_ty)] )
197 [ hcat [ text "Cannot see data constructor of ``literal-literal''s type: "
198 , text "value:", quotes (quotes (ptext str))
199 , text "; type: ", ppr ty
201 , text "Try compiling with -fno-prune-tydecls."
206 = case (maybeBoxedPrimType ty) of
207 Just (boxing_data_con, prim_ty) -> (boxing_data_con, prim_ty)
209 -> pprPanic "ERROR: ``literal-literal'' not a single-constructor type: "
210 (hcat [ptext str, text "; type: ", ppr ty])
212 dsExpr (HsLitOut (HsInt i) ty)
213 = returnDs (mkLit (NoRepInteger i ty))
215 dsExpr (HsLitOut (HsFrac r) ty)
216 = returnDs (mkLit (NoRepRational r ty))
218 -- others where we know what to do:
220 dsExpr (HsLitOut (HsIntPrim i) _)
221 | (i >= toInteger minInt && i <= toInteger maxInt)
222 = returnDs (mkLit (mkMachInt i))
224 = error ("ERROR: Int constant " ++ show i ++ out_of_range_msg)
226 dsExpr (HsLitOut (HsFloatPrim f) _)
227 = returnDs (mkLit (MachFloat f))
228 -- ToDo: range checking needed!
230 dsExpr (HsLitOut (HsDoublePrim d) _)
231 = returnDs (mkLit (MachDouble d))
232 -- ToDo: range checking needed!
234 dsExpr (HsLitOut (HsChar c) _)
235 = returnDs ( mkConApp charDataCon [mkLit (MachChar c)] )
237 dsExpr (HsLitOut (HsCharPrim c) _)
238 = returnDs (mkLit (MachChar c))
240 dsExpr (HsLitOut (HsStringPrim s) _)
241 = returnDs (mkLit (MachStr s))
243 -- end of literals magic. --
245 dsExpr expr@(HsLam a_Match)
246 = matchWrapper LambdaMatch [a_Match] "lambda" `thenDs` \ (binders, matching_code) ->
247 returnDs (mkLams binders matching_code)
249 dsExpr expr@(HsApp fun arg)
250 = dsExpr fun `thenDs` \ core_fun ->
251 dsExpr arg `thenDs` \ core_arg ->
252 returnDs (core_fun `App` core_arg)
256 Operator sections. At first it looks as if we can convert
265 But no! expr might be a redex, and we can lose laziness badly this
270 for example. So we convert instead to
272 let y = expr in \x -> op y x
274 If \tr{expr} is actually just a variable, say, then the simplifier
278 dsExpr (OpApp e1 op _ e2)
279 = dsExpr op `thenDs` \ core_op ->
280 -- for the type of y, we need the type of op's 2nd argument
281 dsExpr e1 `thenDs` \ x_core ->
282 dsExpr e2 `thenDs` \ y_core ->
283 returnDs (mkApps core_op [x_core, y_core])
285 dsExpr (SectionL expr op)
286 = dsExpr op `thenDs` \ core_op ->
287 -- for the type of y, we need the type of op's 2nd argument
289 (x_ty:y_ty:_, _) = splitFunTys (coreExprType core_op)
291 dsExpr expr `thenDs` \ x_core ->
292 newSysLocalDs x_ty `thenDs` \ x_id ->
293 newSysLocalDs y_ty `thenDs` \ y_id ->
295 returnDs (bindNonRec x_id x_core $
296 Lam y_id (mkApps core_op [Var x_id, Var y_id]))
298 -- dsExpr (SectionR op expr) -- \ x -> op x expr
299 dsExpr (SectionR op expr)
300 = dsExpr op `thenDs` \ core_op ->
301 -- for the type of x, we need the type of op's 2nd argument
303 (x_ty:y_ty:_, _) = splitFunTys (coreExprType core_op)
305 dsExpr expr `thenDs` \ y_core ->
306 newSysLocalDs x_ty `thenDs` \ x_id ->
307 newSysLocalDs y_ty `thenDs` \ y_id ->
309 returnDs (bindNonRec y_id y_core $
310 Lam x_id (mkApps core_op [Var x_id, Var y_id]))
312 dsExpr (CCall lbl args may_gc is_asm result_ty)
313 = mapDs dsExpr args `thenDs` \ core_args ->
314 dsCCall lbl core_args may_gc is_asm result_ty
315 -- dsCCall does all the unboxification, etc.
317 dsExpr (HsSCC cc expr)
318 = dsExpr expr `thenDs` \ core_expr ->
319 getModuleAndGroupDs `thenDs` \ (mod_name, group_name) ->
320 returnDs (Note (SCC (mkUserCC cc mod_name group_name)) core_expr)
322 -- special case to handle unboxed tuple patterns.
324 dsExpr (HsCase discrim matches@[Match _ [TuplePat ps boxed] _ _] src_loc)
325 | not boxed && all var_pat ps
326 = putSrcLocDs src_loc $
327 dsExpr discrim `thenDs` \ core_discrim ->
328 matchWrapper CaseMatch matches "case" `thenDs` \ ([discrim_var], matching_code) ->
329 case matching_code of
330 Case (Var x) bndr alts | x == discrim_var ->
331 returnDs (Case core_discrim bndr alts)
332 _ -> panic ("dsExpr: tuple pattern:\n" ++ showSDoc (ppr matching_code))
334 dsExpr (HsCase discrim matches src_loc)
335 = putSrcLocDs src_loc $
336 dsExpr discrim `thenDs` \ core_discrim ->
337 matchWrapper CaseMatch matches "case" `thenDs` \ ([discrim_var], matching_code) ->
338 returnDs (bindNonRec discrim_var core_discrim matching_code)
340 dsExpr (HsLet binds body)
341 = dsExpr body `thenDs` \ body' ->
344 dsExpr (HsDoOut do_or_lc stmts return_id then_id fail_id result_ty src_loc)
345 | maybeToBool maybe_list_comp
346 = -- Special case for list comprehensions
347 putSrcLocDs src_loc $
348 dsListComp stmts elt_ty
351 = putSrcLocDs src_loc $
352 dsDo do_or_lc stmts return_id then_id fail_id result_ty
355 = case (do_or_lc, splitTyConApp_maybe result_ty) of
356 (ListComp, Just (tycon, [elt_ty]))
360 -- We need the ListComp form to use deListComp (rather than the "do" form)
361 -- because the "return" in a do block is a call to "PrelBase.return", and
362 -- not a ReturnStmt. Only the ListComp form has ReturnStmts
364 Just elt_ty = maybe_list_comp
366 dsExpr (HsIf guard_expr then_expr else_expr src_loc)
367 = putSrcLocDs src_loc $
368 dsExpr guard_expr `thenDs` \ core_guard ->
369 dsExpr then_expr `thenDs` \ core_then ->
370 dsExpr else_expr `thenDs` \ core_else ->
371 returnDs (mkIfThenElse core_guard core_then core_else)
376 \underline{\bf Type lambda and application}
377 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~
379 dsExpr (TyLam tyvars expr)
380 = dsExpr expr `thenDs` \ core_expr ->
381 returnDs (mkLams tyvars core_expr)
383 dsExpr (TyApp expr tys)
384 = dsExpr expr `thenDs` \ core_expr ->
385 returnDs (mkTyApps core_expr tys)
390 \underline{\bf Various data construction things}
391 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
393 dsExpr (ExplicitListOut ty xs)
396 list_ty = mkListTy ty
398 go [] = returnDs (mkNilExpr ty)
399 go (x:xs) = dsExpr x `thenDs` \ core_x ->
400 go xs `thenDs` \ core_xs ->
401 ASSERT( isNotUsgTy ty )
402 returnDs (mkConsExpr ty core_x core_xs)
404 dsExpr (ExplicitTuple expr_list boxed)
405 = mapDs dsExpr expr_list `thenDs` \ core_exprs ->
406 returnDs (mkConApp ((if boxed
408 else unboxedTupleCon) (length expr_list))
409 (map (Type . unUsgTy . coreExprType) core_exprs ++ core_exprs))
410 -- the above unUsgTy is *required* -- KSW 1999-04-07
412 dsExpr (HsCon con_id [ty] [arg])
414 = dsExpr arg `thenDs` \ arg' ->
415 returnDs (Note (Coerce result_ty (unUsgTy (coreExprType arg'))) arg')
417 result_ty = mkTyConApp tycon [ty]
418 tycon = dataConTyCon con_id
420 dsExpr (HsCon con_id tys args)
421 = mapDs dsExpr args `thenDs` \ args2 ->
422 ASSERT( all isNotUsgTy tys )
423 returnDs (mkConApp con_id (map Type tys ++ args2))
425 dsExpr (ArithSeqOut expr (From from))
426 = dsExpr expr `thenDs` \ expr2 ->
427 dsExpr from `thenDs` \ from2 ->
428 returnDs (App expr2 from2)
430 dsExpr (ArithSeqOut expr (FromTo from two))
431 = dsExpr expr `thenDs` \ expr2 ->
432 dsExpr from `thenDs` \ from2 ->
433 dsExpr two `thenDs` \ two2 ->
434 returnDs (mkApps expr2 [from2, two2])
436 dsExpr (ArithSeqOut expr (FromThen from thn))
437 = dsExpr expr `thenDs` \ expr2 ->
438 dsExpr from `thenDs` \ from2 ->
439 dsExpr thn `thenDs` \ thn2 ->
440 returnDs (mkApps expr2 [from2, thn2])
442 dsExpr (ArithSeqOut expr (FromThenTo from thn two))
443 = dsExpr expr `thenDs` \ expr2 ->
444 dsExpr from `thenDs` \ from2 ->
445 dsExpr thn `thenDs` \ thn2 ->
446 dsExpr two `thenDs` \ two2 ->
447 returnDs (mkApps expr2 [from2, thn2, two2])
451 \underline{\bf Record construction and update}
452 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
453 For record construction we do this (assuming T has three arguments)
457 let err = /\a -> recConErr a
458 T (recConErr t1 "M.lhs/230/op1")
460 (recConErr t1 "M.lhs/230/op3")
462 @recConErr@ then converts its arugment string into a proper message
463 before printing it as
465 M.lhs, line 230: missing field op1 was evaluated
468 We also handle @C{}@ as valid construction syntax for an unlabelled
469 constructor @C@, setting all of @C@'s fields to bottom.
472 dsExpr (RecordConOut data_con con_expr rbinds)
473 = dsExpr con_expr `thenDs` \ con_expr' ->
475 (arg_tys, _) = splitFunTys (coreExprType con_expr')
478 = case [rhs | (sel_id,rhs,_) <- rbinds,
479 lbl == recordSelectorFieldLabel sel_id] of
480 (rhs:rhss) -> ASSERT( null rhss )
482 [] -> mkErrorAppDs rEC_CON_ERROR_ID arg_ty (showSDoc (ppr lbl))
483 unlabelled_bottom arg_ty = mkErrorAppDs rEC_CON_ERROR_ID arg_ty ""
485 labels = dataConFieldLabels data_con
489 then mapDs unlabelled_bottom arg_tys
490 else mapDs mk_arg (zipEqual "dsExpr:RecordCon" arg_tys labels))
491 `thenDs` \ con_args ->
493 returnDs (mkApps con_expr' con_args)
496 Record update is a little harder. Suppose we have the decl:
498 data T = T1 {op1, op2, op3 :: Int}
499 | T2 {op4, op2 :: Int}
502 Then we translate as follows:
508 T1 op1 _ op3 -> T1 op1 op2 op3
509 T2 op4 _ -> T2 op4 op2
510 other -> recUpdError "M.lhs/230"
512 It's important that we use the constructor Ids for @T1@, @T2@ etc on the
513 RHSs, and do not generate a Core @Con@ directly, because the constructor
514 might do some argument-evaluation first; and may have to throw away some
518 dsExpr (RecordUpdOut record_expr record_out_ty dicts rbinds)
519 = dsExpr record_expr `thenDs` \ record_expr' ->
521 -- Desugar the rbinds, and generate let-bindings if
522 -- necessary so that we don't lose sharing
525 ds_rbind (sel_id, rhs, pun_flag)
526 = dsExpr rhs `thenDs` \ rhs' ->
527 returnDs (recordSelectorFieldLabel sel_id, rhs')
529 mapDs ds_rbind rbinds `thenDs` \ rbinds' ->
531 record_in_ty = coreExprType record_expr'
532 (tycon, in_inst_tys, cons) = splitAlgTyConApp record_in_ty
533 (_, out_inst_tys, _) = splitAlgTyConApp record_out_ty
534 cons_to_upd = filter has_all_fields cons
536 -- initial_args are passed to every constructor
537 initial_args = map Type out_inst_tys ++ map Var dicts
539 mk_val_arg field old_arg_id
540 = case [rhs | (f, rhs) <- rbinds', field == f] of
541 (rhs:rest) -> ASSERT(null rest) rhs
545 = newSysLocalsDs (dataConArgTys con in_inst_tys) `thenDs` \ arg_ids ->
546 -- This call to dataConArgTys won't work for existentials
548 val_args = zipWithEqual "dsExpr:RecordUpd" mk_val_arg
549 (dataConFieldLabels con) arg_ids
550 rhs = mkApps (mkApps (Var (dataConId con)) initial_args) val_args
552 returnDs (DataCon con, arg_ids, rhs)
555 | length cons_to_upd == length cons
558 = mkErrorAppDs rEC_UPD_ERROR_ID record_out_ty "" `thenDs` \ err ->
559 returnDs [(DEFAULT, [], err)]
561 -- Record stuff doesn't work for existentials
562 ASSERT( all (not . isExistentialDataCon) cons )
564 newSysLocalDs record_in_ty `thenDs` \ case_bndr ->
565 mapDs mk_alt cons_to_upd `thenDs` \ alts ->
566 mk_default `thenDs` \ deflt ->
568 returnDs (Case record_expr' case_bndr (alts ++ deflt))
570 has_all_fields :: DataCon -> Bool
571 has_all_fields con_id
574 con_fields = dataConFieldLabels con_id
575 ok (sel_id, _, _) = recordSelectorFieldLabel sel_id `elem` con_fields
580 \underline{\bf Dictionary lambda and application}
581 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
582 @DictLam@ and @DictApp@ turn into the regular old things.
583 (OLD:) @DictFunApp@ also becomes a curried application, albeit slightly more
584 complicated; reminiscent of fully-applied constructors.
586 dsExpr (DictLam dictvars expr)
587 = dsExpr expr `thenDs` \ core_expr ->
588 returnDs (mkLams dictvars core_expr)
592 dsExpr (DictApp expr dicts) -- becomes a curried application
593 = dsExpr expr `thenDs` \ core_expr ->
594 returnDs (foldl (\f d -> f `App` (Var d)) core_expr dicts)
600 -- HsSyn constructs that just shouldn't be here:
601 dsExpr (HsDo _ _ _) = panic "dsExpr:HsDo"
602 dsExpr (ExplicitList _) = panic "dsExpr:ExplicitList"
603 dsExpr (ExprWithTySig _ _) = panic "dsExpr:ExprWithTySig"
604 dsExpr (ArithSeqIn _) = panic "dsExpr:ArithSeqIn"
607 out_of_range_msg -- ditto
608 = " out of range: [" ++ show minInt ++ ", " ++ show maxInt ++ "]\n"
611 %--------------------------------------------------------------------
613 Basically does the translation given in the Haskell~1.3 report:
618 -> Id -- id for: return m
619 -> Id -- id for: (>>=) m
620 -> Id -- id for: fail m
621 -> Type -- Element type; the whole expression has type (m t)
624 dsDo do_or_lc stmts return_id then_id fail_id result_ty
626 (_, b_ty) = splitAppTy result_ty -- result_ty must be of the form (m b)
629 = dsExpr expr `thenDs` \ expr2 ->
630 returnDs (mkApps (Var return_id) [Type b_ty, expr2])
632 go (GuardStmt expr locn : stmts)
633 = do_expr expr locn `thenDs` \ expr2 ->
634 go stmts `thenDs` \ rest ->
635 let msg = ASSERT( isNotUsgTy b_ty )
636 "Pattern match failure in do expression, " ++ showSDoc (ppr locn) in
637 returnDs (mkIfThenElse expr2
639 (App (App (Var fail_id)
641 (mkLit (mkStrLit msg stringTy))))
643 go (ExprStmt expr locn : stmts)
644 = do_expr expr locn `thenDs` \ expr2 ->
646 (_, a_ty) = splitAppTy (coreExprType expr2) -- Must be of form (m a)
651 go stmts `thenDs` \ rest ->
652 newSysLocalDs a_ty `thenDs` \ ignored_result_id ->
653 returnDs (mkApps (Var then_id) [Type a_ty, Type b_ty, expr2,
654 Lam ignored_result_id rest])
656 go (LetStmt binds : stmts )
657 = go stmts `thenDs` \ rest ->
660 go (BindStmt pat expr locn : stmts)
662 dsExpr expr `thenDs` \ expr2 ->
664 (_, a_ty) = splitAppTy (coreExprType expr2) -- Must be of form (m a)
665 fail_expr = HsApp (TyApp (HsVar fail_id) [b_ty])
666 (HsLitOut (HsString (_PK_ msg)) stringTy)
667 msg = ASSERT2( isNotUsgTy a_ty, ppr a_ty )
668 ASSERT2( isNotUsgTy b_ty, ppr b_ty )
669 "Pattern match failure in do expression, " ++ showSDoc (ppr locn)
670 main_match = mkSimpleMatch [pat]
671 (HsDoOut do_or_lc stmts return_id then_id
672 fail_id result_ty locn)
673 (Just result_ty) locn
675 | failureFreePat pat = [main_match]
678 , mkSimpleMatch [WildPat a_ty] fail_expr (Just result_ty) locn
681 matchWrapper DoBindMatch the_matches match_msg
682 `thenDs` \ (binders, matching_code) ->
683 returnDs (mkApps (Var then_id) [Type a_ty, Type b_ty, expr2,
684 mkLams binders matching_code])
689 do_expr expr locn = putSrcLocDs locn (dsExpr expr)
691 match_msg = case do_or_lc of
692 DoStmt -> "`do' statement"
693 ListComp -> "comprehension"
697 var_pat (WildPat _) = True
698 var_pat (VarPat _) = True