Or "generics". That's what I was trying to say in my last line; you can do that, but only if you think to use them when you originally write the function.
Which is not far-fetched... E.g. when adding type signatures to functions in Haskell, one generally uses the most general possible types/typeclasses.