Restructure typing system.

This should cause recompiles to run faster, I think.