Olaf suggests

> Hence I suggest that part (b) of rule 1 of the MR should
> be deleted, i.e. simple
> pattern bindings are just treated as function bindings. As I have said in a
> previous email, the recomputation issue could be handled by warnings from the
> compiler.

That would indeed not fall foul of the ambiguity problem, but
it doesn't deal with the unexpected efficiency problem.

Consider:

        f xs = if len > 3 then len else 0
             where
                len = length xs

You are a first year undergraduate.  Quick, how many times is the
length of xs computed?

Correct!  Twice!  I'm assuming here that we've made the change
to length to give it the sensible type

        length :: Num b => [a] -> b

(And it's not length's fault; it's easy to write functions with
similar types.)

Here the effect is arguably minor: taking the length of a list
twice.  But it's not hard to come up with examples that are
exponentially worse.

Some people say "of course len is computed twice", but many find
it puzzling.  We have debated this point endlessly.  Frankly, I'm
very reluctant to make incremental changes to the MR.  Let's either
fix it or leave it alone.  Since we don't know how to fix it, let's
leave it alone.

Simon


Reply via email to