A generating extension of a program specializes it with respect tosome specified part of the input. A generating extension of a programcan be formed trivially by applying a partial evaluator to the program;the second Futamura projection describes the automatic generationof non-trivial generating extensions by applying a partial evaluator toitself with respect to the programs.We derive an ML implementation of the second Futamura projection for Type-Directed Partial Evaluation (TDPE). Due to the differences between `traditional', syntax-directed partial evaluation andTDPE, this derivation involves several conceptual and technical steps.These include a suitable formulation of the second Futamura projection and techniques for making TDPE amenab...