[Haskell-cafe] Noob error: Type b -> c b Does not match IO a
daniel.is.fischer at web.de
Mon Jun 27 12:12:25 EDT 2005
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.
> foldr m 1 [a,b,c]
> 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.
Try a list like [1 .. 20000] ++ [0 .. 50000], compile for profiling and see.
I'm not sure why, but upTo eats much more memory than foldr m 1.
More information about the Haskell-Cafe