Generalize to support arbitrary theories.

The theory of natural numbers is defined in TcTypeNats.