In the following example, why any optimization that evaluates to 1 would be considered incorrect?
foldl (*) 1 (repeat 1)
^CInterrupted.
In the following example, why any optimization that evaluates to 1 would be considered incorrect?
foldl (*) 1 (repeat 1)
^CInterrupted.
The intention of optimizations is to make a program faster without changing what answer it gets at the end of the (now faster) calculation.
Since foldl (*) 1 (repeat 1) starts out as an infinite loop, after optimizations, while it may go through each iteration of the loop body more quickly, it still must go through infinitely many iterations to avoid changing what answer it gets.
Daniel Wagner gave a great answer, yet I wanted to add a little bit on infinite multiplication.
In a way, what you are trying to do matches the following expression in the language (the mechanism is, of course, different - see the definition of fix: we have no accumulated product - only the sequence of applications; I just wanted to give an answer from the other perspective, which is kind of not there):
fix (1*)
Data.Function.fix's description:
fix fis the least fixed point of the functionf, i.e. the least definedxsuch thatf x = x.
fix f = let x = f x in x
So, (1*) has a whole Int of fixed points, and the fix (1*) gets reduced to the least defined, that is to the bottom (infinite loop in this case).
In your definition, same happens, yet the programme is ready to put 1 (a well-defined fixed point) in the end of the multiplication. This does not happen as it reaches bottom - the least defined fixed point.