
To me, it seems that something like this should be possible -- am i being naive? does it already exist? During the compilation process GHC optimizes the code by performing successive transformations of the program. These transformations are known to preserve meaning of the program - they are based on some already proved facts and properties. I've written a blog post recently on this:
http://lambda.jstolarek.com/2013/01/taking-magic-out-of-ghc-or-tracing-compi... Now, you might be asking why does GHC transform the Core representation of a program and not the original Haskell code itself? The answer is simplicity. Core is equivalent to Haskell, but it's much easier to work with since there are few language constructs and it's easier to design transformations and prove them correct. I hope this at least partially answers your question. Whether there automated ways of transforming Haskell programs into more efficient Haskell programs I don't know. Janek