2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[HsExpr]{Abstract Haskell syntax: expressions}
9 #include "HsVersions.h"
12 import HsDecls ( HsGroup )
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 )
22 import Type ( Type, TyThing )
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 | HsDo (HsStmtContext Name) -- The parameterisation is unimportant
87 -- because in this context we never use
88 -- the PatGuard or ParStmt variant
89 [Stmt id] -- "do":one or more stmts
90 [id] -- Ids for [return,fail,>>=,>>]
92 -- Before type checking, used for rebindable syntax
93 PostTcType -- Type of the whole expression
96 | ExplicitList -- syntactic list
97 PostTcType -- Gives type of components of list
100 | ExplicitPArr -- syntactic parallel array: [:e1, ..., en:]
101 PostTcType -- type of elements of the parallel array
104 | ExplicitTuple -- tuple
106 -- NB: Unit is ExplicitTuple []
107 -- for tuples, we can get the types
108 -- direct from the components
112 -- Record construction
113 | RecordCon id -- The constructor
116 | RecordConOut DataCon
117 (HsExpr id) -- Data con Id applied to type args
122 | RecordUpd (HsExpr id)
125 | RecordUpdOut (HsExpr id) -- TRANSLATION
126 Type -- Type of *input* record
127 Type -- Type of *result* record (may differ from
128 -- type of input record)
131 | ExprWithTySig -- signature binding
134 | ArithSeqIn -- arithmetic sequence
137 (HsExpr id) -- (typechecked, of course)
139 | PArrSeqIn -- arith. sequence for parallel array
140 (ArithSeqInfo id) -- [:e1..e2:] or [:e1, e2..e3:]
142 (HsExpr id) -- (typechecked, of course)
145 | HsCCall CLabelString -- call into the C world; string is
146 [HsExpr id] -- the C function; exprs are the
147 -- arguments to pass.
148 Safety -- True <=> might cause Haskell
149 -- garbage-collection (must generate
150 -- more paranoid code)
151 Bool -- True <=> it's really a "casm"
152 -- NOTE: this CCall is the *boxed*
153 -- version; the desugarer will convert
154 -- it into the unboxed "ccall#".
155 PostTcType -- The result type; will be *bottom*
156 -- until the typechecker gets ahold of it
158 | HsSCC FastString -- "set cost centre" (_scc_) annotation
159 (HsExpr id) -- expr whose cost is to be measured
161 -- MetaHaskell Extensions
162 | HsBracket (HsBracket id) SrcLoc
164 | HsBracketOut (HsBracket Name) -- Output of the type checker is the *original*
165 [PendingSplice] -- renamed expression, plus *typechecked* splices
166 -- to be pasted back in by the desugarer
168 | HsSplice id (HsExpr id) SrcLoc -- $z or $(f 4)
169 -- The id is just a unique name to
170 -- identify this splice point
172 | HsReify (HsReify id) -- reifyType t, reifyDecl i, reifyFixity
176 These constructors only appear temporarily in the parser.
177 The renamer translates them into the Right Thing.
180 | EWildPat -- wildcard
182 | EAsPat id -- as pattern
185 | ELazyPat (HsExpr id) -- ~ pattern
187 | HsType (HsType id) -- Explicit type argument; e.g f {| Int |} x y
190 Everything from here on appears only in typechecker output.
193 | TyLam -- TRANSLATION
196 | TyApp -- TRANSLATION
197 (HsExpr id) -- generated by Spec
200 -- DictLam and DictApp are "inverses"
208 type PendingSplice = (Name, HsExpr Id) -- Typechecked splices, waiting to be
209 -- pasted back in by the desugarer
213 A @Dictionary@, unless of length 0 or 1, becomes a tuple. A
214 @ClassDictLam dictvars methods expr@ is, therefore:
216 \ x -> case x of ( dictvars-and-methods-tuple ) -> expr
220 instance OutputableBndr id => Outputable (HsExpr id) where
221 ppr expr = pprExpr expr
225 pprExpr :: OutputableBndr id => HsExpr id -> SDoc
227 pprExpr e = pprDeeper (ppr_expr e)
228 pprBinds b = pprDeeper (ppr b)
230 ppr_expr (HsVar v) = pprHsVar v
231 ppr_expr (HsIPVar v) = ppr v
232 ppr_expr (HsLit lit) = ppr lit
233 ppr_expr (HsOverLit lit) = ppr lit
235 ppr_expr (HsLam match) = pprMatch LambdaExpr match
237 ppr_expr expr@(HsApp e1 e2)
238 = let (fun, args) = collect_args expr [] in
239 (ppr_expr fun) <+> (sep (map ppr_expr args))
241 collect_args (HsApp fun arg) args = collect_args fun (arg:args)
242 collect_args fun args = (fun, args)
244 ppr_expr (OpApp e1 op fixity e2)
246 HsVar v -> pp_infixly v
249 pp_e1 = pprParendExpr e1 -- Add parens to make precedence clear
250 pp_e2 = pprParendExpr e2
253 = hang (pprExpr op) 4 (sep [pp_e1, pp_e2])
256 = sep [pp_e1, hsep [pp_v_op, pp_e2]]
259 pp_v_op | isOperator ppr_v = ppr_v
260 | otherwise = char '`' <> ppr_v <> char '`'
261 -- Put it in backquotes if it's not an operator already
263 ppr_expr (NegApp e _) = char '-' <+> pprParendExpr e
265 ppr_expr (HsPar e) = parens (ppr_expr e)
267 ppr_expr (SectionL expr op)
269 HsVar v -> pp_infixly v
272 pp_expr = pprParendExpr expr
274 pp_prefixly = hang (hsep [text " \\ x_ ->", ppr op])
275 4 (hsep [pp_expr, ptext SLIT("x_ )")])
276 pp_infixly v = parens (sep [pp_expr, ppr v])
278 ppr_expr (SectionR op expr)
280 HsVar v -> pp_infixly v
283 pp_expr = pprParendExpr expr
285 pp_prefixly = hang (hsep [text "( \\ x_ ->", ppr op, ptext SLIT("x_")])
286 4 ((<>) pp_expr rparen)
288 = parens (sep [ppr v, pp_expr])
290 ppr_expr (HsCase expr matches _)
291 = sep [ sep [ptext SLIT("case"), nest 4 (pprExpr expr), ptext SLIT("of")],
292 nest 2 (pprMatches CaseAlt matches) ]
294 ppr_expr (HsIf e1 e2 e3 _)
295 = sep [hsep [ptext SLIT("if"), nest 2 (pprExpr e1), ptext SLIT("then")],
300 -- special case: let ... in let ...
301 ppr_expr (HsLet binds expr@(HsLet _ _))
302 = sep [hang (ptext SLIT("let")) 2 (hsep [pprBinds binds, ptext SLIT("in")]),
305 ppr_expr (HsLet binds expr)
306 = sep [hang (ptext SLIT("let")) 2 (pprBinds binds),
307 hang (ptext SLIT("in")) 2 (ppr expr)]
309 ppr_expr (HsDo do_or_list_comp stmts _ _ _) = pprDo do_or_list_comp stmts
311 ppr_expr (ExplicitList _ exprs)
312 = brackets (fsep (punctuate comma (map ppr_expr exprs)))
314 ppr_expr (ExplicitPArr _ exprs)
315 = pa_brackets (fsep (punctuate comma (map ppr_expr exprs)))
317 ppr_expr (ExplicitTuple exprs boxity)
318 = tupleParens boxity (sep (punctuate comma (map ppr_expr exprs)))
320 ppr_expr (RecordCon con_id rbinds)
321 = pp_rbinds (ppr con_id) rbinds
322 ppr_expr (RecordConOut data_con con rbinds)
323 = pp_rbinds (ppr con) rbinds
325 ppr_expr (RecordUpd aexp rbinds)
326 = pp_rbinds (pprParendExpr aexp) rbinds
327 ppr_expr (RecordUpdOut aexp _ _ rbinds)
328 = pp_rbinds (pprParendExpr aexp) rbinds
330 ppr_expr (ExprWithTySig expr sig)
331 = hang (nest 2 (ppr_expr expr) <+> dcolon)
334 ppr_expr (ArithSeqIn info)
335 = brackets (ppr info)
336 ppr_expr (ArithSeqOut expr info)
337 = brackets (ppr info)
339 ppr_expr (PArrSeqIn info)
340 = pa_brackets (ppr info)
341 ppr_expr (PArrSeqOut expr info)
342 = pa_brackets (ppr info)
344 ppr_expr EWildPat = char '_'
345 ppr_expr (ELazyPat e) = char '~' <> pprParendExpr e
346 ppr_expr (EAsPat v e) = ppr v <> char '@' <> pprParendExpr e
348 ppr_expr (HsCCall fun args _ is_asm result_ty)
350 then ptext SLIT("_casm_ ``") <> pprCLabelString fun <> ptext SLIT("''")
351 else ptext SLIT("_ccall_") <+> pprCLabelString fun)
352 4 (sep (map pprParendExpr args))
354 ppr_expr (HsSCC lbl expr)
355 = sep [ ptext SLIT("_scc_") <+> doubleQuotes (ftext lbl), pprParendExpr expr ]
357 ppr_expr (TyLam tyvars expr)
358 = hang (hsep [ptext SLIT("/\\"),
359 hsep (map (pprBndr LambdaBind) tyvars),
363 ppr_expr (TyApp expr [ty])
364 = hang (ppr_expr expr) 4 (pprParendType ty)
366 ppr_expr (TyApp expr tys)
367 = hang (ppr_expr expr)
368 4 (brackets (interpp'SP tys))
370 ppr_expr (DictLam dictvars expr)
371 = hang (hsep [ptext SLIT("\\{-dict-}"),
372 hsep (map (pprBndr LambdaBind) dictvars),
376 ppr_expr (DictApp expr [dname])
377 = hang (ppr_expr expr) 4 (ppr dname)
379 ppr_expr (DictApp expr dnames)
380 = hang (ppr_expr expr)
381 4 (brackets (interpp'SP dnames))
383 ppr_expr (HsType id) = ppr id
385 ppr_expr (HsSplice n e _) = char '$' <> brackets (ppr n) <> pprParendExpr e
386 ppr_expr (HsBracket b _) = pprHsBracket b
387 ppr_expr (HsBracketOut e ps) = ppr e $$ ptext SLIT("where") <+> ppr ps
388 ppr_expr (HsReify r) = ppr r
390 -- add parallel array brackets around a document
392 pa_brackets :: SDoc -> SDoc
393 pa_brackets p = ptext SLIT("[:") <> p <> ptext SLIT(":]")
396 Parenthesize unless very simple:
398 pprParendExpr :: OutputableBndr id => HsExpr id -> SDoc
402 pp_as_was = pprExpr expr
409 HsIPVar _ -> pp_as_was
410 ExplicitList _ _ -> pp_as_was
411 ExplicitPArr _ _ -> pp_as_was
412 ExplicitTuple _ _ -> pp_as_was
415 _ -> parens pp_as_was
418 %************************************************************************
420 \subsection{Record binds}
422 %************************************************************************
425 type HsRecordBinds id = [(id, HsExpr id)]
427 recBindFields :: HsRecordBinds id -> [id]
428 recBindFields rbinds = [field | (field,_) <- rbinds]
430 pp_rbinds :: OutputableBndr id => SDoc -> HsRecordBinds id -> SDoc
432 pp_rbinds thing rbinds
434 4 (braces (sep (punctuate comma (map (pp_rbind) rbinds))))
436 pp_rbind (v, e) = hsep [pprBndr LetBind v, char '=', ppr e]
441 %************************************************************************
443 \subsection{@Match@, @GRHSs@, and @GRHS@ datatypes}
445 %************************************************************************
447 @Match@es are sets of pattern bindings and right hand sides for
448 functions, patterns or case branches. For example, if a function @g@
454 then \tr{g} has two @Match@es: @(x,y) = y@ and @((x:ys),y) = y+1@.
456 It is always the case that each element of an @[Match]@ list has the
457 same number of @pats@s inside it. This corresponds to saying that
458 a function defined by pattern matching must have the same number of
459 patterns in each equation.
464 [Pat id] -- The patterns
465 (Maybe (HsType id)) -- A type signature for the result of the match
466 -- Nothing after typechecking
470 -- GRHSs are used both for pattern bindings and for Matches
472 = GRHSs [GRHS id] -- Guarded RHSs
473 (HsBinds id) -- The where clause
474 PostTcType -- Type of RHS (after type checking)
477 = GRHS [Stmt id] -- The RHS is the final ResultStmt
480 mkSimpleMatch :: [Pat id] -> HsExpr id -> Type -> SrcLoc -> Match id
481 mkSimpleMatch pats rhs rhs_ty locn
482 = Match pats Nothing (GRHSs (unguardedRHS rhs locn) EmptyBinds rhs_ty)
484 unguardedRHS :: HsExpr id -> SrcLoc -> [GRHS id]
485 unguardedRHS rhs loc = [GRHS [ResultStmt rhs loc] loc]
488 @getMatchLoc@ takes a @Match@ and returns the
489 source-location gotten from the GRHS inside.
490 THis is something of a nuisance, but no more.
493 getMatchLoc :: Match id -> SrcLoc
494 getMatchLoc (Match _ _ (GRHSs (GRHS _ loc : _) _ _)) = loc
497 We know the list must have at least one @Match@ in it.
500 pprMatches :: (OutputableBndr id) => HsMatchContext id -> [Match id] -> SDoc
501 pprMatches ctxt matches = vcat (map (pprMatch ctxt) matches)
503 -- Exported to HsBinds, which can't see the defn of HsMatchContext
504 pprFunBind :: (OutputableBndr id) => id -> [Match id] -> SDoc
505 pprFunBind fun matches = pprMatches (FunRhs fun) matches
507 -- Exported to HsBinds, which can't see the defn of HsMatchContext
508 pprPatBind :: (OutputableBndr id)
509 => Pat id -> GRHSs id -> SDoc
510 pprPatBind pat grhss = sep [ppr pat, nest 4 (pprGRHSs PatBindRhs grhss)]
513 pprMatch :: OutputableBndr id => HsMatchContext id -> Match id -> SDoc
514 pprMatch ctxt (Match pats maybe_ty grhss)
515 = pp_name ctxt <+> sep [sep (map ppr pats),
517 nest 2 (pprGRHSs ctxt grhss)]
519 pp_name (FunRhs fun) = ppr fun -- Not pprBndr; the AbsBinds will
520 -- have printed the signature
521 pp_name LambdaExpr = char '\\'
522 pp_name other = empty
524 ppr_maybe_ty = case maybe_ty of
525 Just ty -> dcolon <+> ppr ty
529 pprGRHSs :: OutputableBndr id => HsMatchContext id -> GRHSs id -> SDoc
530 pprGRHSs ctxt (GRHSs grhss binds ty)
531 = vcat (map (pprGRHS ctxt) grhss)
533 (if nullBinds binds then empty
534 else text "where" $$ nest 4 (pprDeeper (ppr binds)))
537 pprGRHS :: OutputableBndr id => HsMatchContext id -> GRHS id -> SDoc
539 pprGRHS ctxt (GRHS [ResultStmt expr _] locn)
542 pprGRHS ctxt (GRHS guarded locn)
543 = sep [char '|' <+> interpp'SP guards, pp_rhs ctxt expr]
545 ResultStmt expr _ = last guarded -- Last stmt should be a ResultStmt for guards
546 guards = init guarded
548 pp_rhs ctxt rhs = matchSeparator ctxt <+> pprDeeper (ppr rhs)
553 %************************************************************************
555 \subsection{Do stmts and list comprehensions}
557 %************************************************************************
561 = BindStmt (Pat id) (HsExpr id) SrcLoc
562 | LetStmt (HsBinds id)
563 | ResultStmt (HsExpr id) SrcLoc -- See notes that follow
564 | ExprStmt (HsExpr id) PostTcType SrcLoc -- See notes that follow
565 -- The type is the *element type* of the expression
567 -- ParStmts only occur in a list comprehension
568 | ParStmt [[Stmt id]] -- List comp only: parallel set of quals
569 | ParStmtOut [([id], [Stmt id])] -- PLC after renaming; the ids are the binders
570 -- bound by the stmts
572 -- mdo-notation (only exists after renamer)
573 -- The ids are a subset of the variables bound by the stmts that
574 -- either (a) are used before they are bound in the stmts
575 -- or (b) are used in stmts that follow the RecStmt
578 [HsExpr id] -- Post type-checking only; these expressions correspond
579 -- 1-to-1 with the [id], and are the expresions that should
580 -- be returned by the recursion. They may not quite be the
581 -- Ids themselves, because the Id may be polymorphic, but
582 -- the returned thing has to be monomorphic.
585 ExprStmts and ResultStmts are a bit tricky, because what they mean
586 depends on the context. Consider the following contexts:
588 A do expression of type (m res_ty)
589 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
590 * ExprStmt E any_ty: do { ....; E; ... }
592 Translation: E >> ...
594 * ResultStmt E: do { ....; E }
598 A list comprehensions of type [elt_ty]
599 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
600 * ExprStmt E Bool: [ .. | .... E ]
602 [ .. | .... | ..., E | ... ]
604 Translation: if E then fail else ...
606 * ResultStmt E: [ E | ... ]
608 Translation: return E
610 A guard list, guarding a RHS of type rhs_ty
611 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
612 * ExprStmt E Bool: f x | ..., E, ... = ...rhs...
614 Translation: if E then fail else ...
616 * ResultStmt E: f x | ...guards... = E
620 Array comprehensions are handled like list comprehensions -=chak
623 consLetStmt :: HsBinds id -> [Stmt id] -> [Stmt id]
624 consLetStmt EmptyBinds stmts = stmts
625 consLetStmt binds stmts = LetStmt binds : stmts
629 instance OutputableBndr id => Outputable (Stmt id) where
630 ppr stmt = pprStmt stmt
632 pprStmt (BindStmt pat expr _) = hsep [ppr pat, ptext SLIT("<-"), ppr expr]
633 pprStmt (LetStmt binds) = hsep [ptext SLIT("let"), pprBinds binds]
634 pprStmt (ExprStmt expr _ _) = ppr expr
635 pprStmt (ResultStmt expr _) = ppr expr
636 pprStmt (ParStmt stmtss)
637 = hsep (map (\stmts -> ptext SLIT("| ") <> ppr stmts) stmtss)
638 pprStmt (ParStmtOut stmtss)
639 = hsep (map (\stmts -> ptext SLIT("| ") <> ppr stmts) stmtss)
640 pprStmt (RecStmt _ segment _) = vcat (map ppr segment)
642 pprDo :: OutputableBndr id => HsStmtContext any -> [Stmt id] -> SDoc
643 pprDo DoExpr stmts = hang (ptext SLIT("do")) 2 (vcat (map ppr stmts))
644 pprDo MDoExpr stmts = hang (ptext SLIT("mdo")) 3 (vcat (map ppr stmts))
645 pprDo ListComp stmts = pprComp brackets stmts
646 pprDo PArrComp stmts = pprComp pa_brackets stmts
648 pprComp :: OutputableBndr id => (SDoc -> SDoc) -> [Stmt id] -> SDoc
649 pprComp brack stmts = brack $
650 hang (pprExpr expr <+> char '|')
653 ResultStmt expr _ = last stmts -- Last stmt should
654 quals = init stmts -- be an ResultStmt
657 %************************************************************************
659 Template Haskell quotation brackets
661 %************************************************************************
664 data HsBracket id = ExpBr (HsExpr id)
669 instance OutputableBndr id => Outputable (HsBracket id) where
673 pprHsBracket (ExpBr e) = thBrackets empty (ppr e)
674 pprHsBracket (PatBr p) = thBrackets (char 'p') (ppr p)
675 pprHsBracket (DecBr d) = thBrackets (char 'd') (ppr d)
676 pprHsBracket (TypBr t) = thBrackets (char 't') (ppr t)
679 thBrackets pp_kind pp_body = char '[' <> pp_kind <> char '|' <+>
680 pp_body <+> ptext SLIT("|]")
682 data HsReify id = Reify ReifyFlavour id -- Pre typechecking
683 | ReifyOut ReifyFlavour Name -- Post typechecking
684 -- The Name could be the name of
685 -- an Id, TyCon, or Class
687 data ReifyFlavour = ReifyDecl | ReifyType | ReifyFixity
689 instance Outputable id => Outputable (HsReify id) where
690 ppr (Reify flavour id) = ppr flavour <+> ppr id
691 ppr (ReifyOut flavour thing) = ppr flavour <+> ppr thing
693 instance Outputable ReifyFlavour where
694 ppr ReifyDecl = ptext SLIT("reifyDecl")
695 ppr ReifyType = ptext SLIT("reifyType")
696 ppr ReifyFixity = ptext SLIT("reifyFixity")
699 %************************************************************************
701 \subsection{Enumerations and list comprehensions}
703 %************************************************************************
708 | FromThen (HsExpr id)
712 | FromThenTo (HsExpr id)
718 instance OutputableBndr id => Outputable (ArithSeqInfo id) where
719 ppr (From e1) = hcat [ppr e1, pp_dotdot]
720 ppr (FromThen e1 e2) = hcat [ppr e1, comma, space, ppr e2, pp_dotdot]
721 ppr (FromTo e1 e3) = hcat [ppr e1, pp_dotdot, ppr e3]
722 ppr (FromThenTo e1 e2 e3)
723 = hcat [ppr e1, comma, space, ppr e2, pp_dotdot, ppr e3]
725 pp_dotdot = ptext SLIT(" .. ")
729 %************************************************************************
731 \subsection{HsMatchCtxt}
733 %************************************************************************
736 data HsMatchContext id -- Context of a Match
737 = FunRhs id -- Function binding for f
738 | CaseAlt -- Guard on a case alternative
739 | LambdaExpr -- Pattern of a lambda
740 | PatBindRhs -- Pattern binding
741 | RecUpd -- Record update [used only in DsExpr to tell matchWrapper
742 -- what sort of runtime error message to generate]
743 | StmtCtxt (HsStmtContext id) -- Pattern of a do-stmt or list comprehension
746 data HsStmtContext id
749 | MDoExpr -- Recursive do-expression
750 | PArrComp -- Parallel array comprehension
751 | PatGuard (HsMatchContext id) -- Pattern guard for specified thing
752 | ParStmtCtxt (HsStmtContext id) -- A branch of a parallel stmt
756 isDoExpr :: HsStmtContext id -> Bool
757 isDoExpr DoExpr = True
758 isDoExpr MDoExpr = True
759 isDoExpr other = False
763 matchSeparator (FunRhs _) = ptext SLIT("=")
764 matchSeparator CaseAlt = ptext SLIT("->")
765 matchSeparator LambdaExpr = ptext SLIT("->")
766 matchSeparator PatBindRhs = ptext SLIT("=")
767 matchSeparator (StmtCtxt _) = ptext SLIT("<-")
768 matchSeparator RecUpd = panic "unused"
772 pprMatchContext (FunRhs fun) = ptext SLIT("the definition of") <+> quotes (ppr fun)
773 pprMatchContext CaseAlt = ptext SLIT("a case alternative")
774 pprMatchContext RecUpd = ptext SLIT("a record-update construct")
775 pprMatchContext PatBindRhs = ptext SLIT("a pattern binding")
776 pprMatchContext LambdaExpr = ptext SLIT("a lambda abstraction")
777 pprMatchContext (StmtCtxt ctxt) = ptext SLIT("a pattern binding in") $$ pprStmtContext ctxt
779 pprMatchRhsContext (FunRhs fun) = ptext SLIT("a right-hand side of function") <+> quotes (ppr fun)
780 pprMatchRhsContext CaseAlt = ptext SLIT("the body of a case alternative")
781 pprMatchRhsContext PatBindRhs = ptext SLIT("the right-hand side of a pattern binding")
782 pprMatchRhsContext LambdaExpr = ptext SLIT("the body of a lambda")
783 pprMatchRhsContext RecUpd = panic "pprMatchRhsContext"
785 pprStmtContext (ParStmtCtxt c) = sep [ptext SLIT("a parallel branch of"), pprStmtContext c]
786 pprStmtContext (PatGuard ctxt) = ptext SLIT("a pattern guard for") $$ pprMatchContext ctxt
787 pprStmtContext DoExpr = ptext SLIT("a 'do' expression")
788 pprStmtContext MDoExpr = ptext SLIT("an 'mdo' expression")
789 pprStmtContext ListComp = ptext SLIT("a list comprehension")
790 pprStmtContext PArrComp = ptext SLIT("an array comprehension")
792 -- Used for the result statement of comprehension
793 -- e.g. the 'e' in [ e | ... ]
794 -- or the 'r' in f x = r
795 pprStmtResultContext (PatGuard ctxt) = pprMatchRhsContext ctxt
796 pprStmtResultContext other = ptext SLIT("the result of") <+> pprStmtContext other
799 -- Used to generate the string for a *runtime* error message
800 matchContextErrString (FunRhs fun) = "function " ++ showSDoc (ppr fun)
801 matchContextErrString CaseAlt = "case"
802 matchContextErrString PatBindRhs = "pattern binding"
803 matchContextErrString RecUpd = "record update"
804 matchContextErrString LambdaExpr = "lambda"
805 matchContextErrString (StmtCtxt (ParStmtCtxt c)) = matchContextErrString (StmtCtxt c)
806 matchContextErrString (StmtCtxt (PatGuard _)) = "pattern guard"
807 matchContextErrString (StmtCtxt DoExpr) = "'do' expression"
808 matchContextErrString (StmtCtxt MDoExpr) = "'mdo' expression"
809 matchContextErrString (StmtCtxt ListComp) = "list comprehension"
810 matchContextErrString (StmtCtxt PArrComp) = "array comprehension"