Syntax and typeclass for first order theories