Use a monad to track the constraint generation etc.
Added basic support for evaluating terms.