> On the other hand, you might define a function as a triple (D, R, f)
That's also the approach in Functional Analysis. Depending on how you choose D and R, some fundamental properties of the function change, e.g. bijectivity. Therefore specifying the sets is strictly speaking not optional.
The proper function definition in the other formalism would be rather:
f: D -> R: ...