+checkPrecMatch True op (Match _ (p1:p2:_) _ _)
+ -- True indicates an infix lhs
+ = getModeRn `thenRn` \ mode ->
+ -- See comments with rnExpr (OpApp ...)
+ if isInterfaceMode mode
+ then returnRn ()
+ else checkPrec op p1 False `thenRn_`
+ checkPrec op p2 True
+
+checkPrecMatch True op _ = panic "checkPrecMatch"
+
+checkPrec op (ConOpPatIn _ op1 _ _) right
+ = lookupFixityRn op `thenRn` \ op_fix@(Fixity op_prec op_dir) ->
+ lookupFixityRn op1 `thenRn` \ op1_fix@(Fixity op1_prec op1_dir) ->
+ let
+ inf_ok = op1_prec > op_prec ||
+ (op1_prec == op_prec &&
+ (op1_dir == InfixR && op_dir == InfixR && right ||
+ op1_dir == InfixL && op_dir == InfixL && not right))
+
+ info = (ppr_op op, op_fix)
+ info1 = (ppr_op op1, op1_fix)
+ (infol, infor) = if right then (info, info1) else (info1, info)
+ in
+ checkRn inf_ok (precParseErr infol infor)
+
+checkPrec op pat right
+ = returnRn ()
+
+-- Check precedence of (arg op) or (op arg) respectively
+-- If arg is itself an operator application, its precedence should
+-- be higher than that of op
+checkSectionPrec left_or_right section op arg
+ = case arg of
+ OpApp _ op fix _ -> go_for_it (ppr_op op) fix
+ NegApp _ -> go_for_it pp_prefix_minus negateFixity
+ other -> returnRn ()
+ where
+ HsVar op_name = op
+ go_for_it pp_arg_op arg_fix@(Fixity arg_prec _)
+ = lookupFixityRn op_name `thenRn` \ op_fix@(Fixity op_prec _) ->
+ checkRn (op_prec < arg_prec)
+ (sectionPrecErr (ppr_op op_name, op_fix) (pp_arg_op, arg_fix) section)
+\end{code}
+
+Consider
+\begin{verbatim}
+ a `op1` b `op2` c
+\end{verbatim}
+@(compareFixity op1 op2)@ tells which way to arrange appication, or
+whether there's an error.
+
+\begin{code}
+compareFixity :: Fixity -> Fixity
+ -> (Bool, -- Error please
+ Bool) -- Associate to the right: a op1 (b op2 c)
+compareFixity (Fixity prec1 dir1) (Fixity prec2 dir2)
+ = case prec1 `compare` prec2 of
+ GT -> left
+ LT -> right
+ EQ -> case (dir1, dir2) of
+ (InfixR, InfixR) -> right
+ (InfixL, InfixL) -> left
+ _ -> error_please
+ where
+ right = (False, True)
+ left = (False, False)
+ error_please = (True, False)