Commit 98a74c9d authored by simonpj's avatar simonpj
Browse files

[project @ 2001-07-20 10:05:37 by simonpj]

--------------------------
	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.
parent 9d978426
......@@ -790,15 +790,17 @@ And in any case it seems more robust to have exprArity be a bit more intelligent
\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}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment