Make 'length' into a good consumer, fixing Trac #876

Trac #876 is the oldest ticket I have fixed in a long time.
I finally figured out how to make foldr behave in a non
space-leaky way for length.

Thanks to Andy for re-opening.