sum, perfomance?

Adrian Hey ahey@iee.org
Mon, 05 Jun 2000 17:00:50 +0100 (BST)


On Mon 05 Jun, Igor V. Artelnykh wrote:
> sum:: !.[a] -> a |  + , zero  a
> sum xs = accsum zero xs
> where
>         accsum n [x:xs] = accsum (n + x) xs
>         accsum n []     = n

I would guess 1 reason for doing it this way is that this form is an easily
optimised tail call, so resulting code resembles an imperative loop rather
than recursive procedure calls. But this will only be efficient if strictness
analyser detects that accsum is strict in its first argument (otherwise loads
of thunks will be produced).

Actually, now I come to think about this, maybe the overloaded form of this
means that strictness can't be inferred, it depends on the definition of
the + instance??? No doubt a Clean developer can correct/clarify.

> P.S. How to subscribe to _both_ clean-announce and clean-list mailing
> lists?

I thought all announcements went to clean-list also, so you don't need
to subscribe to both.

Regards
-- 
Adrian Hey