Let's say we have a program like this :
list = [1..10000000]
main = print $ sum list
I want this to be compiled such that the executable just prints 50000005000000, without taking as much time and effort.
Basically, any expression that will be surely computed (maybe the strictness analysis can help here) can be pre-computed during compilation time (ie we use referential-transparency to say it doesn't really matter when we compute the value).
In short : "has to be computed" + referential-transparency = can be pre-computed
This would be like running the program till we hit something that depends upon the input (i.e. the core of the program, that which is common across all inputs, will be pre-computed)
Is there an existing mechanism to achieve this currently (in Haskell or any other language)? [Please don't point to something like templates in C++ as it doesn't have referential-transparency in the first place.]
If not, how tough is this problem ? [What are the accompanying technical (and theoretical) issues ?]