Damn it... Forget my last email. I confused iterate with replicate for a second...

On Thu, May 19, 2011 at 1:01 PM, Alex Rozenshteyn <rpglover64@gmail.com> wrote:
You're not applying the operation 1000000 times, you're traversing to the 1000000th node in the list and applying the operation once. Laziness never evaluates the other thunks.


On Thu, May 19, 2011 at 12:15 PM, Ertugrul Soeylemez <es@ertes.de> wrote:
Daniel Fischer <daniel.is.fischer@googlemail.com> wrote:

> However, since you're asking about cost, which indicates that you care
> for performance, the above would be better written as
>
> [x*x*x | x <- list]
>
> unless you depend on the small differences in the outcome [I'm not
> quite sure how many bits may be affected, not many, typically none or
> one].  Functions like (**), exp, log, sin, cos, ... are slow, very
> slow.  If the exponent is a small (positive) integer, specifically
> giving a sequence of multiplication steps is much faster, also using
> (^) instead of (**) is faster for small exponents (but slower than an
> explicit multiplication sequence).

Neither does this really match my intuition, nor can I confirm it with
an experiment.  Applying (** 3) a million times to a Double takes a
second and gives me the expected Infinity.  Applying (^3) or (\x ->
x*x*x) a million times to the same value, well, I didn't want to wait
for it to finish.

The experiment was ran with the following codes in GHCi:

   iterate (** 3) 1.000000001 !! 1000000
   iterate (^3) 1.000000001 !! 1000000
   iterate (\x -> x*x*x) 1.000000001 !! 1000000

Note that exponentiation is a cheap operation on Double.


Greets
Ertugrul


--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/



_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners



--
          Alex R




--
          Alex R