2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[HsExpr]{Abstract Haskell syntax: expressions}
9 #include "HsVersions.h"
12 import HsDecls ( HsDecl )
13 import HsBinds ( HsBinds(..), nullBinds )
15 import HsLit ( HsLit, HsOverLit )
16 import HsTypes ( HsType, PostTcType, SyntaxName )
17 import HsImpExp ( isOperator, pprHsVar )
20 import ForeignCall ( Safety )
21 import PprType ( pprParendType )
23 import Var ( TyVar, Id )
25 import DataCon ( DataCon )
26 import CStrings ( CLabelString, pprCLabelString )
27 import BasicTypes ( IPName, Boxity, tupleParens, Fixity(..) )
28 import SrcLoc ( SrcLoc )
33 %************************************************************************
35 \subsection{Expressions proper}
37 %************************************************************************
41 = HsVar id -- variable
42 | HsIPVar (IPName id) -- implicit parameter
43 | HsOverLit HsOverLit -- Overloaded literals; eliminated by type checker
44 | HsLit HsLit -- Simple (non-overloaded) literals
46 | HsLam (Match id) -- lambda
47 | HsApp (HsExpr id) -- application
50 -- Operator applications:
51 -- NB Bracketed ops such as (+) come out as Vars.
53 -- NB We need an expr for the operator in an OpApp/Section since
54 -- the typechecker may need to apply the operator to a few types.
56 | OpApp (HsExpr id) -- left operand
57 (HsExpr id) -- operator
58 Fixity -- Renamer adds fixity; bottom until then
59 (HsExpr id) -- right operand
61 -- We preserve prefix negation and parenthesis for the precedence parser.
62 -- They are eventually removed by the type checker.
64 | NegApp (HsExpr id) -- negated expr
65 SyntaxName -- Name of 'negate' (see RnEnv.lookupSyntaxName)
67 | HsPar (HsExpr id) -- parenthesised expr
69 | SectionL (HsExpr id) -- operand
70 (HsExpr id) -- operator
71 | SectionR (HsExpr id) -- operator
72 (HsExpr id) -- operand
78 | HsIf (HsExpr id) -- predicate
79 (HsExpr id) -- then part
80 (HsExpr id) -- else part
83 | HsLet (HsBinds id) -- let(rec)
86 | HsWith (HsExpr id) -- implicit parameter binding
87 [(IPName id, HsExpr id)]
88 Bool -- True <=> this was a 'with' binding
89 -- (tmp, until 'with' is removed)
92 [Stmt id] -- "do":one or more stmts
93 [id] -- Ids for [return,fail,>>=,>>]
95 -- Before type checking, used for rebindable syntax
96 PostTcType -- Type of the whole expression
99 | ExplicitList -- syntactic list
100 PostTcType -- Gives type of components of list
103 | ExplicitPArr -- syntactic parallel array: [:e1, ..., en:]
104 PostTcType -- type of elements of the parallel array
107 | ExplicitTuple -- tuple
109 -- NB: Unit is ExplicitTuple []
110 -- for tuples, we can get the types
111 -- direct from the components
115 -- Record construction
116 | RecordCon id -- The constructor
119 | RecordConOut DataCon
120 (HsExpr id) -- Data con Id applied to type args
125 | RecordUpd (HsExpr id)
128 | RecordUpdOut (HsExpr id) -- TRANSLATION
129 Type -- Type of *input* record
130 Type -- Type of *result* record (may differ from
131 -- type of input record)
134 | ExprWithTySig -- signature binding
137 | ArithSeqIn -- arithmetic sequence
140 (HsExpr id) -- (typechecked, of course)
142 | PArrSeqIn -- arith. sequence for parallel array
143 (ArithSeqInfo id) -- [:e1..e2:] or [:e1, e2..e3:]
145 (HsExpr id) -- (typechecked, of course)
148 | HsCCall CLabelString -- call into the C world; string is
149 [HsExpr id] -- the C function; exprs are the
150 -- arguments to pass.
151 Safety -- True <=> might cause Haskell
152 -- garbage-collection (must generate
153 -- more paranoid code)
154 Bool -- True <=> it's really a "casm"
155 -- NOTE: this CCall is the *boxed*
156 -- version; the desugarer will convert
157 -- it into the unboxed "ccall#".
158 PostTcType -- The result type; will be *bottom*
159 -- until the typechecker gets ahold of it
161 | HsSCC FastString -- "set cost centre" (_scc_) annotation
162 (HsExpr id) -- expr whose cost is to be measured
164 -- MetaHaskell Extensions
165 | HsBracket (HsBracket id)
167 | HsBracketOut (HsBracket Name) -- Output of the type checker is the *original*
168 [PendingSplice] -- renamed expression, plus *typechecked* splices
169 -- to be pasted back in by the desugarer
171 | HsSplice id (HsExpr id ) -- $z or $(f 4)
172 -- The id is just a unique name to
173 -- identify this splice point
177 These constructors only appear temporarily in the parser.
178 The renamer translates them into the Right Thing.
181 | EWildPat -- wildcard
183 | EAsPat id -- as pattern
186 | ELazyPat (HsExpr id) -- ~ pattern
188 | HsType (HsType id) -- Explicit type argument; e.g f {| Int |} x y
191 Everything from here on appears only in typechecker output.
194 | TyLam -- TRANSLATION
197 | TyApp -- TRANSLATION
198 (HsExpr id) -- generated by Spec
201 -- DictLam and DictApp are "inverses"
209 type PendingSplice = (Name, HsExpr Id) -- Typechecked splices, waiting to be
210 -- pasted back in by the desugarer
214 A @Dictionary@, unless of length 0 or 1, becomes a tuple. A
215 @ClassDictLam dictvars methods expr@ is, therefore:
217 \ x -> case x of ( dictvars-and-methods-tuple ) -> expr
221 instance OutputableBndr id => Outputable (HsExpr id) where
222 ppr expr = pprExpr expr
226 pprExpr :: OutputableBndr id => HsExpr id -> SDoc
228 pprExpr e = pprDeeper (ppr_expr e)
229 pprBinds b = pprDeeper (ppr b)
231 ppr_expr (HsVar v) = pprHsVar v
232 ppr_expr (HsIPVar v) = ppr v
233 ppr_expr (HsLit lit) = ppr lit
234 ppr_expr (HsOverLit lit) = ppr lit
236 ppr_expr (HsLam match)
237 = hsep [char '\\', nest 2 (pprMatch LambdaExpr match)]
239 ppr_expr expr@(HsApp e1 e2)
240 = let (fun, args) = collect_args expr [] in
241 (ppr_expr fun) <+> (sep (map ppr_expr args))
243 collect_args (HsApp fun arg) args = collect_args fun (arg:args)
244 collect_args fun args = (fun, args)
246 ppr_expr (OpApp e1 op fixity e2)
248 HsVar v -> pp_infixly v
251 pp_e1 = pprParendExpr e1 -- Add parens to make precedence clear
252 pp_e2 = pprParendExpr e2
255 = hang (pprExpr op) 4 (sep [pp_e1, pp_e2])
258 = sep [pp_e1, hsep [pp_v_op, pp_e2]]
261 pp_v_op | isOperator ppr_v = ppr_v
262 | otherwise = char '`' <> ppr_v <> char '`'
263 -- Put it in backquotes if it's not an operator already
265 ppr_expr (NegApp e _) = char '-' <+> pprParendExpr e
267 ppr_expr (HsPar e) = parens (ppr_expr e)
269 ppr_expr (SectionL expr op)
271 HsVar v -> pp_infixly v
274 pp_expr = pprParendExpr expr
276 pp_prefixly = hang (hsep [text " \\ x_ ->", ppr op])
277 4 (hsep [pp_expr, ptext SLIT("x_ )")])
278 pp_infixly v = parens (sep [pp_expr, ppr v])
280 ppr_expr (SectionR op expr)
282 HsVar v -> pp_infixly v
285 pp_expr = pprParendExpr expr
287 pp_prefixly = hang (hsep [text "( \\ x_ ->", ppr op, ptext SLIT("x_")])
288 4 ((<>) pp_expr rparen)
290 = parens (sep [ppr v, pp_expr])
292 ppr_expr (HsCase expr matches _)
293 = sep [ sep [ptext SLIT("case"), nest 4 (pprExpr expr), ptext SLIT("of")],
294 nest 2 (pprMatches CaseAlt matches) ]
296 ppr_expr (HsIf e1 e2 e3 _)
297 = sep [hsep [ptext SLIT("if"), nest 2 (pprExpr e1), ptext SLIT("then")],
302 -- special case: let ... in let ...
303 ppr_expr (HsLet binds expr@(HsLet _ _))
304 = sep [hang (ptext SLIT("let")) 2 (hsep [pprBinds binds, ptext SLIT("in")]),
307 ppr_expr (HsLet binds expr)
308 = sep [hang (ptext SLIT("let")) 2 (pprBinds binds),
309 hang (ptext SLIT("in")) 2 (ppr expr)]
311 ppr_expr (HsWith expr binds is_with)
312 = sep [hang (ptext SLIT("let")) 2 (pp_ipbinds binds),
313 hang (ptext SLIT("in")) 2 (ppr expr)]
315 ppr_expr (HsDo do_or_list_comp stmts _ _ _) = pprDo do_or_list_comp stmts
317 ppr_expr (ExplicitList _ exprs)
318 = brackets (fsep (punctuate comma (map ppr_expr exprs)))
320 ppr_expr (ExplicitPArr _ exprs)
321 = pa_brackets (fsep (punctuate comma (map ppr_expr exprs)))
323 ppr_expr (ExplicitTuple exprs boxity)
324 = tupleParens boxity (sep (punctuate comma (map ppr_expr exprs)))
326 ppr_expr (RecordCon con_id rbinds)
327 = pp_rbinds (ppr con_id) rbinds
328 ppr_expr (RecordConOut data_con con rbinds)
329 = pp_rbinds (ppr con) rbinds
331 ppr_expr (RecordUpd aexp rbinds)
332 = pp_rbinds (pprParendExpr aexp) rbinds
333 ppr_expr (RecordUpdOut aexp _ _ rbinds)
334 = pp_rbinds (pprParendExpr aexp) rbinds
336 ppr_expr (ExprWithTySig expr sig)
337 = hang (nest 2 (ppr_expr expr) <+> dcolon)
340 ppr_expr (ArithSeqIn info)
341 = brackets (ppr info)
342 ppr_expr (ArithSeqOut expr info)
343 = brackets (ppr info)
345 ppr_expr (PArrSeqIn info)
346 = pa_brackets (ppr info)
347 ppr_expr (PArrSeqOut expr info)
348 = pa_brackets (ppr info)
350 ppr_expr EWildPat = char '_'
351 ppr_expr (ELazyPat e) = char '~' <> pprParendExpr e
352 ppr_expr (EAsPat v e) = ppr v <> char '@' <> pprParendExpr e
354 ppr_expr (HsCCall fun args _ is_asm result_ty)
356 then ptext SLIT("_casm_ ``") <> pprCLabelString fun <> ptext SLIT("''")
357 else ptext SLIT("_ccall_") <+> pprCLabelString fun)
358 4 (sep (map pprParendExpr args))
360 ppr_expr (HsSCC lbl expr)
361 = sep [ ptext SLIT("_scc_") <+> doubleQuotes (ftext lbl), pprParendExpr expr ]
363 ppr_expr (TyLam tyvars expr)
364 = hang (hsep [ptext SLIT("/\\"),
365 hsep (map (pprBndr LambdaBind) tyvars),
369 ppr_expr (TyApp expr [ty])
370 = hang (ppr_expr expr) 4 (pprParendType ty)
372 ppr_expr (TyApp expr tys)
373 = hang (ppr_expr expr)
374 4 (brackets (interpp'SP tys))
376 ppr_expr (DictLam dictvars expr)
377 = hang (hsep [ptext SLIT("\\{-dict-}"),
378 hsep (map (pprBndr LambdaBind) dictvars),
382 ppr_expr (DictApp expr [dname])
383 = hang (ppr_expr expr) 4 (ppr dname)
385 ppr_expr (DictApp expr dnames)
386 = hang (ppr_expr expr)
387 4 (brackets (interpp'SP dnames))
389 ppr_expr (HsType id) = ppr id
391 ppr_expr (HsSplice n e) = char '$' <> brackets (ppr n) <> pprParendExpr e
392 ppr_expr (HsBracket b) = pprHsBracket b
393 ppr_expr (HsBracketOut e ps) = ppr e $$ ptext SLIT("where") <+> ppr ps
395 -- add parallel array brackets around a document
397 pa_brackets :: SDoc -> SDoc
398 pa_brackets p = ptext SLIT("[:") <> p <> ptext SLIT(":]")
401 Parenthesize unless very simple:
403 pprParendExpr :: OutputableBndr id => HsExpr id -> SDoc
407 pp_as_was = pprExpr expr
414 HsIPVar _ -> pp_as_was
415 ExplicitList _ _ -> pp_as_was
416 ExplicitPArr _ _ -> pp_as_was
417 ExplicitTuple _ _ -> pp_as_was
420 _ -> parens pp_as_was
423 %************************************************************************
425 \subsection{Record binds}
427 %************************************************************************
430 type HsRecordBinds id = [(id, HsExpr id)]
432 recBindFields :: HsRecordBinds id -> [id]
433 recBindFields rbinds = [field | (field,_) <- rbinds]
435 pp_rbinds :: OutputableBndr id => SDoc -> HsRecordBinds id -> SDoc
437 pp_rbinds thing rbinds
439 4 (braces (sep (punctuate comma (map (pp_rbind) rbinds))))
441 pp_rbind (v, e) = hsep [pprBndr LetBind v, char '=', ppr e]
445 pp_ipbinds :: OutputableBndr id => [(IPName id, HsExpr id)] -> SDoc
446 pp_ipbinds pairs = hsep (punctuate semi (map pp_item pairs))
448 pp_item (id,rhs) = pprBndr LetBind id <+> equals <+> ppr_expr rhs
452 %************************************************************************
454 \subsection{@Match@, @GRHSs@, and @GRHS@ datatypes}
456 %************************************************************************
458 @Match@es are sets of pattern bindings and right hand sides for
459 functions, patterns or case branches. For example, if a function @g@
465 then \tr{g} has two @Match@es: @(x,y) = y@ and @((x:ys),y) = y+1@.
467 It is always the case that each element of an @[Match]@ list has the
468 same number of @pats@s inside it. This corresponds to saying that
469 a function defined by pattern matching must have the same number of
470 patterns in each equation.
475 [Pat id] -- The patterns
476 (Maybe (HsType id)) -- A type signature for the result of the match
477 -- Nothing after typechecking
481 -- GRHSs are used both for pattern bindings and for Matches
483 = GRHSs [GRHS id] -- Guarded RHSs
484 (HsBinds id) -- The where clause
485 PostTcType -- Type of RHS (after type checking)
488 = GRHS [Stmt id] -- The RHS is the final ResultStmt
491 mkSimpleMatch :: [Pat id] -> HsExpr id -> Type -> SrcLoc -> Match id
492 mkSimpleMatch pats rhs rhs_ty locn
493 = Match pats Nothing (GRHSs (unguardedRHS rhs locn) EmptyBinds rhs_ty)
495 unguardedRHS :: HsExpr id -> SrcLoc -> [GRHS id]
496 unguardedRHS rhs loc = [GRHS [ResultStmt rhs loc] loc]
499 @getMatchLoc@ takes a @Match@ and returns the
500 source-location gotten from the GRHS inside.
501 THis is something of a nuisance, but no more.
504 getMatchLoc :: Match id -> SrcLoc
505 getMatchLoc (Match _ _ (GRHSs (GRHS _ loc : _) _ _)) = loc
508 We know the list must have at least one @Match@ in it.
511 pprMatches :: (OutputableBndr id) => HsMatchContext id -> [Match id] -> SDoc
512 pprMatches ctxt matches = vcat (map (pprMatch ctxt) matches)
514 -- Exported to HsBinds, which can't see the defn of HsMatchContext
515 pprFunBind :: (OutputableBndr id) => id -> [Match id] -> SDoc
516 pprFunBind fun matches = pprMatches (FunRhs fun) matches
518 -- Exported to HsBinds, which can't see the defn of HsMatchContext
519 pprPatBind :: (OutputableBndr id)
520 => Pat id -> GRHSs id -> SDoc
521 pprPatBind pat grhss = sep [ppr pat, nest 4 (pprGRHSs PatBindRhs grhss)]
524 pprMatch :: OutputableBndr id => HsMatchContext id -> Match id -> SDoc
525 pprMatch ctxt (Match pats maybe_ty grhss)
526 = pp_name ctxt <+> sep [sep (map ppr pats),
528 nest 2 (pprGRHSs ctxt grhss)]
530 pp_name (FunRhs fun) = ppr fun -- Not pprBndr; the AbsBinds will
531 -- have printed the signature
532 pp_name other = empty
533 ppr_maybe_ty = case maybe_ty of
534 Just ty -> dcolon <+> ppr ty
538 pprGRHSs :: OutputableBndr id => HsMatchContext id -> GRHSs id -> SDoc
539 pprGRHSs ctxt (GRHSs grhss binds ty)
540 = vcat (map (pprGRHS ctxt) grhss)
542 (if nullBinds binds then empty
543 else text "where" $$ nest 4 (pprDeeper (ppr binds)))
546 pprGRHS :: OutputableBndr id => HsMatchContext id -> GRHS id -> SDoc
548 pprGRHS ctxt (GRHS [ResultStmt expr _] locn)
551 pprGRHS ctxt (GRHS guarded locn)
552 = sep [char '|' <+> interpp'SP guards, pp_rhs ctxt expr]
554 ResultStmt expr _ = last guarded -- Last stmt should be a ResultStmt for guards
555 guards = init guarded
557 pp_rhs ctxt rhs = matchSeparator ctxt <+> pprDeeper (ppr rhs)
562 %************************************************************************
564 \subsection{Do stmts and list comprehensions}
566 %************************************************************************
570 = BindStmt (Pat id) (HsExpr id) SrcLoc
571 | LetStmt (HsBinds id)
572 | ResultStmt (HsExpr id) SrcLoc -- See notes that follow
573 | ExprStmt (HsExpr id) PostTcType SrcLoc -- See notes that follow
574 -- The type is the *element type* of the expression
576 -- ParStmts only occur in a list comprehension
577 | ParStmt [[Stmt id]] -- List comp only: parallel set of quals
578 | ParStmtOut [([id], [Stmt id])] -- PLC after renaming; the ids are the binders
579 -- bound by the stmts
581 -- mdo-notation (only exists after renamer)
582 -- The ids are a subset of the variables bound by the stmts that
583 -- either (a) are used before they are bound in the stmts
584 -- or (b) are used in stmts that follow the RecStmt
589 ExprStmts and ResultStmts are a bit tricky, because what they mean
590 depends on the context. Consider the following contexts:
592 A do expression of type (m res_ty)
593 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
594 * ExprStmt E any_ty: do { ....; E; ... }
596 Translation: E >> ...
598 * ResultStmt E: do { ....; E }
602 A list comprehensions of type [elt_ty]
603 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
604 * ExprStmt E Bool: [ .. | .... E ]
606 [ .. | .... | ..., E | ... ]
608 Translation: if E then fail else ...
610 * ResultStmt E: [ E | ... ]
612 Translation: return E
614 A guard list, guarding a RHS of type rhs_ty
615 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
616 * ExprStmt E Bool: f x | ..., E, ... = ...rhs...
618 Translation: if E then fail else ...
620 * ResultStmt E: f x | ...guards... = E
624 Array comprehensions are handled like list comprehensions -=chak
627 consLetStmt :: HsBinds id -> [Stmt id] -> [Stmt id]
628 consLetStmt EmptyBinds stmts = stmts
629 consLetStmt binds stmts = LetStmt binds : stmts
633 instance OutputableBndr id => Outputable (Stmt id) where
634 ppr stmt = pprStmt stmt
636 pprStmt (BindStmt pat expr _) = hsep [ppr pat, ptext SLIT("<-"), ppr expr]
637 pprStmt (LetStmt binds) = hsep [ptext SLIT("let"), pprBinds binds]
638 pprStmt (ExprStmt expr _ _) = ppr expr
639 pprStmt (ResultStmt expr _) = ppr expr
640 pprStmt (ParStmt stmtss)
641 = hsep (map (\stmts -> ptext SLIT("| ") <> ppr stmts) stmtss)
642 pprStmt (ParStmtOut stmtss)
643 = hsep (map (\stmts -> ptext SLIT("| ") <> ppr stmts) stmtss)
644 pprStmt (RecStmt _ segment) = vcat (map ppr segment)
646 pprDo :: OutputableBndr id => HsStmtContext -> [Stmt id] -> SDoc
647 pprDo DoExpr stmts = hang (ptext SLIT("do")) 2 (vcat (map ppr stmts))
648 pprDo MDoExpr stmts = hang (ptext SLIT("mdo")) 3 (vcat (map ppr stmts))
649 pprDo ListComp stmts = pprComp brackets stmts
650 pprDo PArrComp stmts = pprComp pa_brackets stmts
652 pprComp :: OutputableBndr id => (SDoc -> SDoc) -> [Stmt id] -> SDoc
653 pprComp brack stmts = brack $
654 hang (pprExpr expr <+> char '|')
657 ResultStmt expr _ = last stmts -- Last stmt should
658 quals = init stmts -- be an ResultStmt
661 %************************************************************************
663 Template Haskell quotation brackets
665 %************************************************************************
668 data HsBracket id = ExpBr (HsExpr id)
673 instance OutputableBndr id => Outputable (HsBracket id) where
677 pprHsBracket (ExpBr e) = thBrackets empty (ppr e)
678 pprHsBracket (PatBr p) = thBrackets (char 'p') (ppr p)
679 pprHsBracket (DecBr d) = thBrackets (char 'd') (vcat (map ppr d))
680 pprHsBracket (TypBr t) = thBrackets (char 't') (ppr t)
683 thBrackets pp_kind pp_body = char '[' <> pp_kind <> char '|' <+>
684 pp_body <+> ptext SLIT("|]")
687 %************************************************************************
689 \subsection{Enumerations and list comprehensions}
691 %************************************************************************
696 | FromThen (HsExpr id)
700 | FromThenTo (HsExpr id)
706 instance OutputableBndr id => Outputable (ArithSeqInfo id) where
707 ppr (From e1) = hcat [ppr e1, pp_dotdot]
708 ppr (FromThen e1 e2) = hcat [ppr e1, comma, space, ppr e2, pp_dotdot]
709 ppr (FromTo e1 e3) = hcat [ppr e1, pp_dotdot, ppr e3]
710 ppr (FromThenTo e1 e2 e3)
711 = hcat [ppr e1, comma, space, ppr e2, pp_dotdot, ppr e3]
713 pp_dotdot = ptext SLIT(" .. ")
717 %************************************************************************
719 \subsection{HsMatchCtxt}
721 %************************************************************************
724 data HsMatchContext id -- Context of a Match or Stmt
725 = StmtCtxt HsStmtContext -- Do-stmt or list comprehension
726 | FunRhs id -- Function binding for f
727 | CaseAlt -- Guard on a case alternative
728 | LambdaExpr -- Lambda
729 | PatBindRhs -- Pattern binding
730 | RecUpd -- Record update
736 | MDoExpr -- recursive do-expression
737 | PArrComp -- parallel array comprehension
738 | PatGuard -- Never occurs in an HsDo expression, of course
742 isDoExpr DoExpr = True
743 isDoExpr MDoExpr = True
744 isDoExpr other = False
748 matchSeparator (FunRhs _) = ptext SLIT("=")
749 matchSeparator CaseAlt = ptext SLIT("->")
750 matchSeparator LambdaExpr = ptext SLIT("->")
751 matchSeparator PatBindRhs = ptext SLIT("=")
752 matchSeparator (StmtCtxt _) = ptext SLIT("<-")
753 matchSeparator RecUpd = panic "When is this used?"
757 pprMatchContext (FunRhs fun) = ptext SLIT("In the definition of") <+> quotes (ppr fun)
758 pprMatchContext CaseAlt = ptext SLIT("In a case alternative")
759 pprMatchContext RecUpd = ptext SLIT("In a record-update construct")
760 pprMatchContext PatBindRhs = ptext SLIT("In a pattern binding")
761 pprMatchContext LambdaExpr = ptext SLIT("In a lambda abstraction")
762 pprMatchContext (StmtCtxt ctxt) = pprStmtCtxt ctxt
764 pprStmtCtxt PatGuard = ptext SLIT("In a pattern guard")
765 pprStmtCtxt DoExpr = ptext SLIT("In a 'do' expression pattern binding")
766 pprStmtCtxt MDoExpr = ptext SLIT("In an 'mdo' expression pattern binding")
767 pprStmtCtxt ListComp = ptext SLIT("In a 'list comprehension' pattern binding")
768 pprStmtCtxt PArrComp = ptext SLIT("In an 'array comprehension' pattern binding")
770 -- Used to generate the string for a *runtime* error message
771 matchContextErrString (FunRhs fun) = "function " ++ showSDoc (ppr fun)
772 matchContextErrString CaseAlt = "case"
773 matchContextErrString PatBindRhs = "pattern binding"
774 matchContextErrString RecUpd = "record update"
775 matchContextErrString LambdaExpr = "lambda"
776 matchContextErrString (StmtCtxt PatGuard) = "pattern gaurd"
777 matchContextErrString (StmtCtxt DoExpr) = "'do' expression"
778 matchContextErrString (StmtCtxt MDoExpr) = "'mdo' expression"
779 matchContextErrString (StmtCtxt ListComp) = "list comprehension"
780 matchContextErrString (StmtCtxt PArrComp) = "array comprehension"