This is the standard type class approach. Haskell does the same thing.