I was about to post about multiple dispatch, and your idea above sounds like the next level: predicate dispatch.