correctly implement compareTo for type hierarchies