In this paper we present two type inference systems for detecting useless-code in higher-order typed functional programs. Type inference can be performed in an efficient and complete way, by reducing it to the solution of a system of constraints. We also give a useless-code elimination algorithm which is based on a combined use of these type inference systems. The main application of the technique is the optimization of programs extracted from proofs in logical frameworks, but it could be used as well in the elimination of useless-code determined by program transformations. Capsule Review Dead code is a subterm M of a term t = C[M] which does not matter to computation, that is, which may be replaced by any other term of the same type without altering the observational behaviour of the program: C[M] =obs C[N] for any N with the type of M. Dead-code may be replaced by dummy variable, or even completely removed, in order to optimize a program. The interest in dead-code by the authors sta...