Inspired by a number of things:
Thanks to Joseph Abrahamson for working up an abstract binding trees implementation for OCaml. I have inlined it here, but once I learn how to do so, I'll simply depend upon it as a library.
What I have here is a (fragment of) a modular type checker. Each theory is implemented in separate functor, and then they are all composed together at the very end into a type checker. Because of the modular way I have set this up, it is literally impossible for code from one theory to interfere with code from another; yet they are cooperate seamlessly.