Can you explain to me what you think “translate this dynamically typed program into a statically typed one” means as concerns your fragment of pseudocode? And are you assuming that the “halts” function is a halting oracle?
To convert this to a statically typed program, the compiler has to determine what eval(input) returns at compile time, so it knows whether the function has a type signature of int or String.
In general, this is impossible, since eval(input) may not halt.
The way to type this would be: String -> Int | String (or, if the bottom type is part of your type system, String -> Int | String | Bottom)
And assuming that "eval" is typed as String -> Any, there should be no problem automatically inferring the type signature of this function. I certainly didn't have to solve the halting problem to generate that signature.
In that case you are relying on generics or the equivalent of dynamic typing. My point is that if the language is just static typing without these extra facilities, you cannot translate without knowing the outcome at runtime.
In general, this is impossible, since eval(input) may not halt.