+{-
+ Error messages from unifyFunTys
+ The first line is passed in as error_herald
+
+ The abstraction `\Just 1 -> ...' has two arguments
+ but its type `Maybe a -> a' has only one
+
+ The equation(s) for `f' have two arguments
+ but its type `Maybe a -> a' has only one
+
+ The section `(f 3)' requires 'f' to take two arguments
+ but its type `Int -> Int' has only one
+
+ The function 'f' is applied to two arguments
+ but its type `Int -> Int' has only one
+-}
+
+unifyFunTys error_herald arity ty
+ -- error_herald is the whole first line of the error message above
+ = do { (ok, args, res) <- unify_fun_ty True arity ty
+ ; if ok then return (args, res)
+ else failWithTc (mk_msg (length args)) }
+ where
+ mk_msg n_actual
+ = error_herald <> comma $$
+ sep [ptext SLIT("but its type") <+> quotes (pprType ty),
+ ptext SLIT("has only") <+> speakN n_actual]
+
+unify_fun_ty :: Bool -> Arity -> TcRhoType
+ -> TcM (Bool, -- Arity satisfied?
+ [TcSigmaType], -- Arg types found; length <= arity
+ TcRhoType) -- Result type