--------------------------
Correct a bug in exprArity
--------------------------
This long-standing bug meant that exprArity gave over-pessimistic
answers. e.g.
\x -> f x
where nothing is known about f. We were getting
0 (for f)
-1 (for the argument)
+1 (for the lambda)
-----
0
The right answer is of course 1.
\begin{code}
exprArity :: CoreExpr -> Int
-exprArity e = go e `max` 0
+exprArity e = go e
where
go (Lam x e) | isId x = go e + 1
| otherwise = go e
go (Note _ e) = go e
go (App e (Type t)) = go e
- go (App f a) | exprIsCheap a = go f - 1
+ go (App f a) | exprIsCheap a = (go f - 1) `max` 0
-- Important! f (fac x) does not have arity 2,
-- even if f does!
+ -- NB: `max 0`! (\x y -> f x) has arity 2, even if f is
+ -- unknown, hence arity 0
go (Var v) = idArity v
go _ = 0
\end{code}