This is a really good introduction to the ideas with the historical context that takes you from deforestation all the way to the stream fusion: http://www.ccs.neu.edu/home/amal/course/7480-s12/deforestation-notes.pdf
Type-safe modeling for optimization: https://github.com/McMasterU/HashedExpression