A Theory of Modules Based on Second-Order Logic