1. A computer implemented method of minimizing code duplication in a statically typed language program comprising: receiving a plurality of trees of functional instructions for a program, each of said plurality of trees including at least one functional node; comparing said plurality of trees of functional instructions for a program; merging said trees of functional instructions to eliminate similar function nodes if a set of instruction nodes are locally equivalent; dividing the instructions into subsets of locally equivalent instructions; merging subsets of locally equivalent instructions into a result instruction; folding the result instruction together with a switch on a runtime program index, with a merged tree branch being the result of one of the subset merges; and producing a combined module from results of said merging, said combined module having code duplication removed therefrom.