Can type theory be viewed as an alternative to model theory?

While type theory certainly has traditionally been used for different purposes than model theory, as noted in this Philosophy SE post, I wonder to what extent type theory could model model theory itself.

My motivation for this question is based on an observation that we can view the typing relation in type theory as analagous to the "is a model of" relation in model theory. For example, one might regard the Sigma type $Magma(A) :\equiv\Sigma_{a:A} A \rightarrow A \rightarrow A$ as the theory of magmas over a type A, and components of said type models of the theory.

Now certainly, model theory has more structure to it than a simple "x is a model of y" relation between theories and models of those theories, but I think the idea of interpreting types and terms as a theory/model relation begs the question: Can we develop a richer language in type theory to deal with this types as theories, terms as models interpretation in order to interpret traditional (i.e. ZFC-based) model theory within a type theoretic framework? And, if full interpretation with classical model theory is not possible, is there still some meaningful type-based model theory that we could develop?

• The theory of magmas is not really interesting, since it has no axioms! Can you describe how you would handle theories with axioms? (Even so, I'm not sure I understand your example. Isn't $\Pi_{a:A}A$ normally just a way to write $A\to A$? Why are you using both that and $\to$ in your expression?) – Henning Makholm Mar 14 '16 at 16:52
• Not quite. Pi types are more general than function types. But I believe I actually should have used a sigma type in this instance, so I will edit my post. You can basically read $\Pi$ as $\forall$, and $\Sigma$ as $\exists$. One could express the theory of semigroups as: $Semigroup(A) :\equiv \Sigma_{m:A \rightarrow A \rightarrow A}\Pi_{a,b,c:A}Id(m(a,m(b,c)),(m(m(a,b),c))$ Where $Id$ is the identity type of proofs that two terms are equal, for a more interesting example. Similarly, you could describe the theory of groups, or rings. – Nathan BeDell Mar 14 '16 at 17:08
• x @Sintrastes: My understanding (but it's a long time since I worked with dependent types) is that $\Pi$ reduces to a function arrow when the bound variable isn't free in the body, as in $\Pi_{a:A} A$ -- and similarly $\Sigma_{a:A}A$ would be the same as $A\times A$. – Henning Makholm Mar 14 '16 at 17:15
• I think you are asking whether, rather than studying model theory using set theory, you could study model theory using type theory as your metatheory. Sure, you could do that. – Carl Mummert Mar 14 '16 at 17:16
• @Carl Mummert Could you elaborate? I assume the question is implicitly, "would you get some interesting insight or a different view of model theory in doing so?". – Graffitics Mar 15 '16 at 9:47

Denoting $\mathcal{U}$ as a type universe, one usualy one writes $\mathsf{MagmaStr} : \mathcal{U} \to \mathcal{U}$ for the magma structure over some type. As allready noted the magma structure of $A$ is just a map $A \times A \to A$ so it should be $\mathsf{MagmaStr}(A) = A \times A \to A$.
For a type theoretical definition of $\mathsf{Magma} : \mathcal{U_1}$ itself I would write $\mathsf{Magma} = \sum_{A : \mathcal{U}} A \times A \to A$ note that this type, the magmas in a the universe $\mathcal{U}$, lives in a higher universe level. Then a member of $\mathsf{Magma}$ is a pair of of a type $A$ and a binary operator on $A$ living in $\mathcal{U}$. In that way the type $\mathsf{Magma}$ can be seen as a theory and the members of this type as its models.
Ofcourse the $\mathsf{Magma}$ answer is somewhat simplistic but the above readily generalizes to for example a $\mathsf{SemiGroup} = \sum_{G : \mathcal{U}} \sum_{* : G \times G \to G} \prod_{a b c : M} (a * b) * c = a * (b * c)$. Which is a bit more involved as you can see.