On Mon, 27 Jun 2005, Daniel Fischer wrote: > Am Sonntag, 26. Juni 2005 21:02 schrieben Sie: > > On Sun, 26 Jun 2005, Daniel Fischer wrote: > > > > m x y = if x==0 then 0 else x*y > > > > > > Plain > > > > > > foldr m 1 > > > > > > does fine, in fact much better than > > > > > > foldl' (*) 1 . upTo (== 0), > > > > > > both in hugs and ghc, regarding speed and memory usage. > > > > E.g. > > foldr m 1 [a,b,c] > > > > means > > m a (m b (m c 1))) > > > > That is, it is not possible for the runtime system to store interim > > numeric results, it can only accumulate function calls. > > Well, yes, but since 'm' is lazy in the second argument, the list isn't > traversed past the first zero - like foldr (&&) True.
That was not the point. The point is that "m a (m b (m c..." can't be reduced immediately to, say, "(m (m a b) c) ...", since this is completely different. The computation can only start when the end of the list is reached. _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
