+mkOpAppRn :: RenamedHsExpr -> RenamedHsExpr -> Fixity -> RenamedHsExpr
+ -> RnMS RenamedHsExpr
+
+mkOpAppRn e1@(OpApp e11 op1 fix1 e12)
+ op2 fix2 e2
+ | nofix_error
+ = addErrRn (precParseErr (get op1,fix1) (get op2,fix2)) `thenRn_`
+ returnRn (OpApp e1 op2 fix2 e2)
+
+ | rearrange_me
+ = mkOpAppRn e12 op2 fix2 e2 `thenRn` \ new_e ->
+ returnRn (OpApp e11 op1 fix1 new_e)
+ where
+ (nofix_error, rearrange_me) = compareFixity fix1 fix2
+
+mkOpAppRn e1@(NegApp neg_arg neg_op)
+ op2
+ fix2@(Fixity prec2 dir2)
+ e2
+ | nofix_error
+ = addErrRn (precParseErr (get neg_op,fix_neg) (get op2,fix2)) `thenRn_`
+ returnRn (OpApp e1 op2 fix2 e2)
+
+ | rearrange_me
+ = mkOpAppRn neg_arg op2 fix2 e2 `thenRn` \ new_e ->
+ returnRn (NegApp new_e neg_op)
+ where
+ fix_neg = Fixity 6 InfixL -- Precedence of unary negate is wired in as infixl 6!
+ (nofix_error, rearrange_me) = compareFixity fix_neg fix2
+
+mkOpAppRn e1 op fix e2 -- Default case, no rearrangment
+ = ASSERT( if right_op_ok fix e2 then True
+ else pprPanic "mkOpAppRn" (vcat [ppr e1, text "---", ppr op,
+ text "---", ppr fix, text "---", ppr e2])
+ )
+ returnRn (OpApp e1 op fix e2)
+
+get (HsVar n) = n
+
+-- Parser left-associates everything, but
+-- derived instances may have correctly-associated things to
+-- in the right operarand. So we just check that the right operand is OK
+right_op_ok fix1 (OpApp _ _ fix2 _)
+ = not error_please && associate_right
+ where
+ (error_please, associate_right) = compareFixity fix1 fix2
+right_op_ok fix1 other
+ = True