[Haskell] Control.Monad.Writer as Python generator
Derek Elkins
ddarius at hotpop.com
Fri Apr 15 15:18:19 EDT 2005
On Fri, 15 Apr 2005 12:03:01 -0400
ChrisK <chrisk at MIT.EDU> wrote:
> You are correct. Moand.Cont yield even runs without -O optimizing,
> just slower:
>
> Monad.Writer counts 10^9 zeros in 99 seconds (user time)
> Monad.Cont counts 10^8 zero in 35 seconds user time.
> So the writer is 3.5 times faster without '-O'
>
> With -O
> Monad.Writer counts 10^9 zeros in 105 seconds
> Monad.Cont counts 10^8 zeros in 11 seconds, 10^9 zeros in 110 seconds.
>
> So with '-O' they are the same speed. Nice.
>
> Anyone have an idea why ghci can't garbage collect it?
> Is this an actual bug or an innate quirk of the REPL ?
GHCi does not "compile" with optimizations, without -O the strictness analyzer
isn't run. The difference is most likely due to strictness analysis. A well
placed strictness annotation or two should be able to make it work in GHCi as
well. A similar situation occurs with sum: in GHCi for large inputs it
overflows the stack, but when compiled with -O it works correctly, this is
because sum is defined with foldl and not foldl' in GHC.
More information about the Haskell
mailing list