Discriminator-based sorting.