There's quite a few examples of code generators (e.g. for GUI's, database access, write test fixtures/setup/teardown, etc) in ocaml. It is one of Harrop's success stories. The Manning Code Generation book by Harrington is from 2003, uses ruby 1.6, but i remember it being an excellent book
http://www.amazon.com/Code-Generation-Action-Jack-Herrington...