Looks like a use-case for typeclasses, e.g. those in Haskell. A typeclass is like a Java interface, except the method lookup can use the return type as well.
For example, we could make "plus" depend on the return type:
-- "plus" takes two instances of "Number" and returns an "a"
class Additive a where
plus :: (Number b) => b -> b -> a
-- Take two Numbers and return an Int
instance Additive Int where
plus x y = intPlus (toInt x) (toInt y)
-- Take two Numbers and return a Float
instance Additive Float where
plus x y = floatPlus (toFloat x) (toFloat y)
We can even abuse this to do ugly hacks, like making "plus x y" return a list of "[x + y]" when the return type requires a list:
-- Take two Numbers and return a list containing their sum
instance (Additive a) => Additive (List a) where
plus x y = [plus x y]
Alternatively, we could have returned "[plus x 0, plus y 0]" to make things even uglier ;)