59

EDIT: I've now asked a similar question about the difference between categories and sets.

Every time I read about type theory (which admittedly is rather informal), I can't really understand how it differs from set theory, concretely.

I understand that there is a conceptual difference between saying "x belongs to a set X" and "x is of type X", because intuitively, a set is just a collection of objects, while a type has certain "properties". Nevertheless, sets are often defined according to properties as well, and if they are, then I am having trouble understanding how this distinction matters in any way.

So in the most concrete way possible, what exactly does it imply about $x$ to say that it is of type $T$, compared to saying that it is an element in the set $S$?

(You may pick any type and set that makes the comparison most clarifying).

user56834
  • 3,722
  • 4
  • 18
  • 32
  • What's the context in which you're using/hearing the word "type"? Is it, as your name suggests, programming languages? Because I think the answers below assume otherwise. – einpoklum Apr 30 '18 at 12:30
  • @einpoklum, I'm not 100% sure how to describe what the "context" is, but basically something like: I'm trying to understand the role of types in mathematics. Essentially, sets (as I see it) have two contexts: firstly they are used as collections of objects to do everyday mathematics in. Secondly, they are objects in axiomatic set theory, where they are mostly used as a very weird but helpful tool to talk about mathematics in first order logic, by letting sets correspond to functions and numbers and so forth. I'm mainly interested in the relation between "set" in the first sense and "type". – user56834 Apr 30 '18 at 12:42
  • The role of which types? The types you see in math papers/textbooks, or the types of variables in computer programs? – einpoklum Apr 30 '18 at 12:43
  • 1
    @einpoklum, this question is about the ones in math papers. (Though I'm actually also interested to know the fundamental difference between types in math and types in programming languages, if there is any. But that was not what this question is about). – user56834 Apr 30 '18 at 13:04
  • 1
    What I understood in summary: types are abstract (intensional) descriptions of a collection/selection of objects. Sets (not to be confused with set expressions) are concrete (extensional) descriptions of all its elements. There exists at most one extensional description of a collection but several intensional descriptions are possible,

    Difference between math and programming mostly is that most languages use types in restricted way. In OOP, classes are blueprints of objects. Classes are types but unlike in math, the "extensions" of equal but separate class definitions is considered distinct

    – ChrisoLosoph Oct 06 '22 at 19:08

4 Answers4

59

To understand the difference between sets and types, ones has to go back to pre-mathematical ideas of "collection" and "construction", and see how sets and types mathematize these.

There is a spectrum of possibilities on what mathematics is about. Two of these are:

  1. We think of mathematics as an activity in which mathematical objects are constructed according to some rules (think of geometry as the activity of constructing points, lines and circles with a ruler and a compass). Thus mathematical objects are organized according to how they are constructed, and there are different types of construction. A mathematical object is always constructed in some unique way, which determines its unique type.

  2. We think of mathematics as a vast universe full of pre-existing mathematical objects (think of the geometric plane as given). We discover, analyze and think about these objects (we observe that there are points, lines and circles in the plane). We collect them into set. Usually we collect elements that have something in common (for instance, all lines passing through a given point), but in principle a set may hold together an arbitrary selection of objects. A set is specified by its elements, and only by its elements. A mathematical object may belong to many sets.

We are not saying that the above possibilities are the only two, or that any one of them completely describes what mathematics is. Nevertheless, each view can serve as a useful starting point for a general mathematical theory that usefully describes a wide range of mathematical activities.

It is natural to take a type $T$ and imagine the collection of all things that we can construct using the rules of $T$. This is the extension of $T$, and it is not $T$ itself. For instance, here are two types that have different rules of construction, but they have the same extension:

  1. The type of pairs $(n, p)$ where $n$ is constructed as a natural number, and $p$ is constructed as a proof demonstrating that $n$ is an even prime number larger than $3$.

  2. The type of pairs $(m, q)$ where $m$ is constructed as a natural number, and $q$ is constructed as a proof demonstrating that $m$ is an odd prime smaller than $2$.

Yes, these are silly trivial examples, but the point stands: both types have nothing in their extension, but they have different rules of construction. In contrast, the sets $$\{ n \in \mathbb{N} \mid \text{$n$ is an even prime larger than $3$} \}$$ and $$\{ m \in \mathbb{N} \mid \text{$m$ is an odd prime smaller than $2$} \}$$ are equal because they have the same elements.

Note that type theory is not about syntax. It is a mathematical theory of constructions, just like set theory is a mathematical theory of collections. It just so happens that the usual presentations of type theory emphasize syntax, and consequently people end up thinking type theory is syntax. This is not the case. To confuse a mathematical object (construction) with a syntactic expression that represents it (a term former) is a basic category mistake that has puzzled logicians for a long time, but not anymore.

Andrej Bauer
  • 30,396
  • 1
  • 70
  • 117
  • 2
    Beautiful, thank you! Could you clarify one detail? when you list the two types whose extension are both empty, you say that "the type whose elements are ...". Purely for my clarity, is this a 100% correct way of saying it? You said in the previous sentence that a type is not a collection, so it seems like it cannot have "elements" (which I associate with sets). Essentially, the way you've written it now, it is as if you're defining the Type according to the set that is its extention. If you didn't intend this, could you rephrase them more precisely to capture their idea as types? – user56834 Apr 30 '18 at 13:07
  • 1
    The extension of a type is a very useful concept, and since it is a kind of collection, we can say "element of the extension of a type". This is cumbersome so it often gets abbreviated to just "element of a type". I removed the phrasing to decrease the possibility of confusion, but beware, it's common terminology. – Andrej Bauer Apr 30 '18 at 13:16
  • Thank you, this clarifies. So to follow up, is it correct to say the following? To say that an object is "of type T" means the same thing as, the object is "an element of the extension of T", so that there is a natural surjection from types to sets. But the converse does not hold, because any set can be constructed in multiple ways. Essentially, the difference between set and type is not important from the perspective of a particular object $x$, in the sense that $x:T$ and $x\in X_T$ (where $X_T$ is the extension of $T$) give us the exact same information about $x$. However, – user56834 Apr 30 '18 at 13:25
  • The difference is relevant when we want to talk about types and sets, and their properties and relations. So in other words, the information that we lose when we say $x\in X_T$ rather than $x:T$ does not tell us anything relevant about $x$, but the same may not hold if we e.g. want to talk about superset-subset or type-subtype relations? Is that correct? – user56834 Apr 30 '18 at 13:28
  • Sure, as a first approximation of how things stand, that will do. Eventually you want to look into the fact that type theory stands on its own, without any logic. Set theory is built on top of logic. So you have to be quite "meta-level" to compare the two in a precise way. – Andrej Bauer Apr 30 '18 at 13:28
  • 1
    Do you know of any articles/books that describe these more advanced things as clearly as your answer to this question? – user56834 Apr 30 '18 at 13:31
  • 7
    Yeah, one wonders where these books are. Someone should write them. – Andrej Bauer Apr 30 '18 at 13:33
  • If I were to ask a similar question about the difference between Categories and Sets/Types, would you give a similarly clear answer? Also, should I conclude from your answer that type theory is inherently a part of constructive mathematics? – user56834 Apr 30 '18 at 15:08
  • The first two incarnations of type theory were classical (Russell's theory of types and Church's simple type theory). Martin-Löf type theory arose in connection with constructive mathematics, and is well-suited for a constructive treatment. However, it can be made into a classical theory, one just loses certain comptuational properties as a consequence. – Andrej Bauer Apr 30 '18 at 15:36
  • Andrej Bauer, you should write "these books". When are you gonna do it? – user56834 May 29 '19 at 07:59
  • 2
    @user56834: Sure, I just stop sleeping and eating to create some extra time. – Andrej Bauer May 29 '19 at 09:45
16

In practice, claiming that $x$ being of type $T$ usually is used to describe syntax, while claiming that $x$ is in set $S$ is usually used to indicate a semantic property. I will give some examples to clarify this difference in usage of types and sets. For the difference in what types and sets actually are, I refer to Andrej Bauer's answer.

An example

To clarify this distinction, I will use the example given in Herman Geuvers' lecture notes. First, we look at an example of inhabiting a type:

$$3+(7*8)^5:\mathrm{Nat},$$ and an example of being member of a set: $$3\in \{n\in\mathbb{N}\mid \forall x,y,z\in\mathbb{N}^+ (x^n+y^n\neq z^n)\}$$

The main difference here is that to test whether the first expression is a natural number, we don't have to compute some semantic meaning, we merely have to 'read off' the fact that all literals are of type Nat and that all operators are closed on the type Nat.

However, for the second example of the set, we have to determine the semantic meaning of the $3$ in the context of the set. For this particular set, this is quite hard: the membership of $3$ for this set is equivalent to proving Fermat's last theorem! Do note that, as stated in the notes, the distinction between syntax and semantics cannot always be drawn that clearly. (and you might even argue that even this example is unclear, as Programmer2134 mentions in the comments)

Algorithms vs Proofs

To summarize, types are often used for 'simple' claims on the syntax of some expression, such that membership of a type can be checked by an algorithm, while to test membership of a set, we would in usually require a proof.

To see why this distinction is useful, consider a compiler of a typed programming language. If this compiler has to create a formal proof to 'check types', the compiler is asked to do an almost impossible task (automated theorem proving is, in general, hard). If on the other hand the compiler can simply run an (efficient) algorithm to check the types, then it can realistically perform the task.

A motivation for a strict(er) interpretation

There are multiple interpretations of the semantic meaning of sets and types. While under the distinction made here extensional types and types with undecidable type-checking (such as those used in NuPRL, as mentioned in the comments) would not be 'types', others are of course free to call them as such (just as free as they are as to call them something else, as long as their definitions fit).

However, we (Herman Geuvers and I), prefer to not throw this interpretation out of the window, for which I (not Herman, although he might agree) have the following motivation:

First of all, the intention of this interpretation isn't that far from that of Andrej Bauer. The intention of a syntax is usually to describe how to construct something and having an algorithm to actually construct it is generally useful. Furthermore, the features of a set are usually only needed when we want a semantic description, for which undecidability is allowed.

So, the advantage of our more stricter description is to keep the separation simpler, to get a distinction more directly related to common practical usage. This works well, as long as you don't need or want to loosen your usage, as you would for, e.g. NuPRL.

Discrete lizard
  • 8,248
  • 3
  • 24
  • 53
  • 3
    Type checking doesn't need to be decidable (though it is certainly desirable). NuPRL, for instance, does require the user to provide a proof that a term inhabits a type. – Derek Elkins left SE Apr 30 '18 at 09:12
  • 3
    Thank you. Things are becoming more clear. Heres what I'm wondering still: isn't there a semantic element to type theory and a syntactic element to set theory? For example, we can instead of seeing your "$3\in ...$" statement as a semantic statement, see it as a proposition in axiomatic set theory, no? Also, doesn't the type "Nat" have a semantic meaning, namely that whatever precedes it is a natural number? So it still confuses me to say rhat sets are semantic and types syntactic properties. – user56834 Apr 30 '18 at 09:33
  • To further clarify my confusion, couldn't we define a type "Fermat", and say that any element $n$ is of type Fermat if for any 3 natural numbers $x,y,z$ fermat's equation holds? What would be the difference to say that 3 is of Type Fermat, and saying it belongs to the set you defined? – user56834 Apr 30 '18 at 09:35
  • @DerekElkins No, it doesn't have to, but it is generally very useful that it is. In a sense, as we can at least 'emulate' types with sets, it is technically true that we can consider types no different. As said in the notes I reference: "the distinction between syntactical and semantical information [of sets vs types] can’t always be drawn that clearly" However, usually, the idea is very much that 'checking types' is easy and that is IMO the main distinctive feature, if any. – Discrete lizard Apr 30 '18 at 09:46
  • @Programmer2134 The main difference is that to check the 'Fermat type', we have to use the semantic meaning of '3'. But you may ask, why is this usage semantic? In principle, you could define the difference between syntax and semantics however you wish. However, there are standard definitions for expressions over naturals. $\mathrm{Nat}$ is explicitly the syntactic domain of (expressions over) the naturals. Then, if we want to check the 'Fermat type' of an expression (say $2+1$), we have to do more than test the syntax of the expression (as defined) and hence this 'type' is semantic. – Discrete lizard Apr 30 '18 at 09:58
  • 1
    @DerekElkins I'm not familiar with NuPRL, but e.g. the proof assistant Coq most certainly does type checking by itself (i.e, is the provided term of the 'type of my theorem'). How does NuPRL verify the proof if the user has to 'prove' the fact that a term of a certain type? (in other words, this sounds like NuPRL doesn't use the Curry-Howard correspondence, so what does it use?) – Discrete lizard Apr 30 '18 at 10:09
  • 1
    @Discretelizard I'm not saying NuPRL is typical. It is definitely the usual case for type checking to be decidable. I highly recommend becoming familiar with it just because it takes a fairly different path. NuPRL is a Curry-style rather than Church-style calculus which makes it more of a type refinement system. At any rate, instead of just writing terms (or tactics that produce terms), you have essentially an LCF-style proof system for typing derivations themselves. Arguably, the derivations are what's important, and it's a bit of a "fluke" that we can infer them from terms. – Derek Elkins left SE Apr 30 '18 at 10:48
  • Typing derivations readily provide the terms while a term often uniquely (enough) determines the typing derivation, and so we tend to treat them as equivalent (as I do in my answer). But, via CH, proofs correspond more naturally to typing derivations than to the terms themselves. – Derek Elkins left SE Apr 30 '18 at 10:55
  • It is false that types are only a syntactic entity. – Andrej Bauer Apr 30 '18 at 12:09
  • @AndrejBauer What does 'syntactic entity' mean here? Do you mean that the statement of '$x$ is of type $y$' can be a statement about the semantics of $x$? It probably can. However, I think that this most commonly is not the case and that difference in type and set can be seen in this differing common usage. Can you elaborate on what statement I made (in this comment or in my answer) you disagree with and why? – Discrete lizard Apr 30 '18 at 12:27
  • 3
    I elaborated in my answer why it is detrimental to think of type theory as "syntactic". Your first sentence is the offeding one, when you say that "inhabiting a type is a syntactic property". There's as much truth in that as in saying that "being an element of a set is to stand on the left of the symbol $\in$". – Andrej Bauer Apr 30 '18 at 12:53
  • @AndrejBauer After reading your answer, I agree with that my statement that types need to describe syntax is erroneous. However, I do think that the usual usage of types and sets is related to the syntax/semantics distinction (or often the easy/hard to check distinction), so I think most of my answer is a useful discussion on the common usage of the objects. – Discrete lizard Apr 30 '18 at 13:14
  • Well, it may be usual to misuse types and sets like that, but I find that to be a poor reason for prolonging the misuse. – Andrej Bauer Apr 30 '18 at 13:20
  • @AndrejBauer It would be poor if that is the only reason. I must say that I'm mostly relaying the explanation from Herman Geuvers' lecture notes. Some artifacts are that he mainly considers intensional types and types where type checking is decidable. (likely because this is essential for the proof assistant Coq). But perhaps this perspective shouldn't be extended to the context of this question. I think I'll ask him personally whether (and why!) this is or isn't a good idea. (although it will take a few of days before I have the opportunity to ask him, unfortunately) – Discrete lizard Apr 30 '18 at 13:38
  • I'll have a chat with Herman the next time I see him :-) I'll buy him a beer to lure him into a false sense of security. – Andrej Bauer Apr 30 '18 at 13:43
  • @AndrejBauer, I just read a part of Geuver's lecture notes, and he states "Membership is undecidable in set theory, as it requires a proof to establish $a\in A$." Do you agree with this? I don't see how this makes membership undedicable, unless he means "decidable for all sets". But lets say $A$ is the empty set. Surely, membership in $A$ is decidable? We simply always say: not a member. – user56834 Apr 30 '18 at 15:06
  • What he means is that there are sets that are so complicated that their membership is undecidable. But the same goes for many versions of type theory. You have to carefully craft your type theory to make sure type-checking is decidable. – Andrej Bauer Apr 30 '18 at 15:38
  • @AndrejBauer I've briefly discussed this with Herman and added a motivation (not necessarily shared with Herman) for the value of this interpretation. Do note that Herman stressed that this interpretation is (at most?) equally valid as others (such as yours), on which I agree. Oh and I've warned him of any potential plotting from your side, so I'm afraid you'll have to approach him on even terms (or use more beer ;) ) – Discrete lizard May 06 '18 at 17:23
  • My opening line will be: "Has discrete lizard been talking to you?" – Andrej Bauer May 06 '18 at 18:16
  • @AndrejBauer I'm not sure if he would remember my pseudonym here, but I guess you'll see. – Discrete lizard May 06 '18 at 18:18
10

To start, sets and types aren't even in the same arena. Sets are the objects of a first-order theory, such as ZFC set theory. While types are like overgrown sorts. To put it a different way, a set theory is a first-order theory within first-order logic. A type theory is an extension of logic itself. Martin-Löf Type Theory, for example, is not presented as a first-order theory within first-order logic. It's not that common to talk about sets and types at the same time.

As Discrete lizard states, types (and sorts) serve a syntactic function. A sort/type behaves as a syntactic category. It lets us know what expressions are well-formed. For a simple example using sorts, let's say we described the theory of vector spaces over an arbitrary field as a 2-sorted theory. We have a sort for scalars, $\mathsf S$, and a sort for vectors, $\mathsf V$. Among many other things, we'd have an operation for scaling: $\mathsf{scale}:\mathsf S\times \mathsf V\to \mathsf V$. This lets us know that $\mathsf{scale}(\mathsf{scale}(s,v),v)$ is simply not a well-formed term. In a type theoretic context, an expression like $f(x)$ requires $f$ to have a type $X\to Y$ for some types $X$ and $Y$. If $f$ does not have the type of a function, then $f(x)$ is simply not a well-formed expression. Whether an expression is of some sort or has some type is a meta-logical statement. It makes no sense to write something like: $(x:X)\implies y=3$. First, $x : X$ is simply not a formula, and second, it doesn't even conceptually make sense as sorts/types are what let us know which formulas are well-formed. We only consider the truth value of well-formed formulas, so by the time we're considering whether some formula holds, we better already know that it is well-formed!

In set theory, and particularly ZFC, the only non-logical symbol at all is the relation symbol for set membership, $\in$. So $x\in y$ is a well-formed formula with a truth value. There are no terms other than variables. All the usual notation of set theory is a definitional extension to this. For example, a formula like $f(x)=y$ is often taken to be shorthand for $(x,y)\in f$ which itself may be taken as shorthand for $\exists p.p\in f\land p=(x,y)$ which is shorthand for $$\exists p.p\in f\land(\forall z.z\in p\iff [z = x\lor(\forall w.w\in z\Leftrightarrow w = y)])$$ At any rate, any set can take the place of $f$ and everything is a set! As I pointed out in a different question recently, $\pi(7)=3$ where $\pi$ is the real number is a completely legitimate and meaningful (and potentially even true) set theoretic expression. Basically, anything you write that parses in set theory can be given some meaning. It may be a completely spurious meaning, but it has one. Sets are also "first-class" objects in set theory. (They better be as they are the only objects usually.) A function like $$f(x)=\begin{cases}\mathbb N, &\text{if }x=1\\7,&\text{if }x=\mathbb Q\\x\cap \mathbb R^\mathbb R,&\text{if }x=(\mathbb Z,\mathbb N)\end{cases}$$ is a completely legitimate function in set theory. There is nothing even remotely analogous to this in type theory. The closest would be to use codes for a Tarskian universe. Sets are the objects of set theory; types are not the object of type theory.

A type is not a collection of things (neither is a set for that matter...), and it is not defined by a property. A type is a syntactic category that lets you know what operations are applicable to terms of that type and which expressions are well-formed. From a propositions-as-types perspective, what types are classifying are the valid proofs of the proposition to which the type corresponds. That is, the well-formed (i.e. well-typed) terms of a given type correspond to the valid proofs (which are also syntactic objects) of the corresponding proposition. Nothing like this is happening in set theory.

Set theory and type theory are really not anything alike.

Derek Elkins left SE
  • 12,049
  • 1
  • 29
  • 43
  • 2
    It is false that types are only syntactic entities. – Andrej Bauer Apr 30 '18 at 12:10
  • 2
    This is very helpful, but one main point in your answer bugs me. It seems to me that it is a mistake (which many people make, or alternatively it is not a mistake and I'm wrong), to say that "a set is not a collection of things". I would say that a set IS a collection of things. That is the most basic essential property of a set. In fact, how would we possibly know that e.g. ZFC are the right axioms to choose (rather than completely arbitrary formulas), without being able to tell that they are true given that sets are collections of objects? Of course, I understand that ... – user56834 Apr 30 '18 at 12:28
  • Axiomatic set theory treats sets as objects, and $\in$ as just a symbol, because axiomatic set theory is not a mathematical structure in the mathematical logic sense. – user56834 Apr 30 '18 at 12:30
  • And that functions and so forth can be REPRESENTED in set theory, by essentially linking every function and other mathematical objects, to a set. Then we can use the ZFC axioms and first order logic to derive true statements about those objects. In THAT sense, sets are "objects of set theory". But sets are also simply what they originally and have always meant, namely collections of objects, and not objects of a theory, but a framework to talk about other theory. Similarly, you could formulate an axiomatic first order theory in which types are objects. – user56834 Apr 30 '18 at 12:37
  • 1
    @Programmer2134 To answer that, we would have to get into the semantic meaning of the word "collection." We can't be sure they are "right" unless you take the time to precisely define what "right" means. However, what we can say is that "set" is the result of over a hundred years of mathematicians beating on the concept of a collection, seeking a consistent system which matches the intuitive concept of a collection. To achieve that consistency, they had to make decisions. For example, sets aren't the only collection in mathematics. A "class" also describes a collection. – Cort Ammon Apr 30 '18 at 19:58
  • But sets are so much better behaved than classes that mathematicians find them applicable in all sorts of places. For example, the phrase "The set of all sets" is invalid. It's simply a construction that's not allowed in set theory. It causes all sorts of problems. You can define a type theory such that similar phrasings are valid. – Cort Ammon Apr 30 '18 at 20:00
  • 2
    @AndrejBauer I'm taking a (mostly) non-philosophical stance and not trying to explain what types "really" are but more how they're used. (I say "serves as" and "behaves as" at the beginning but I did slip into an "is" at the end.) There is a risk of thinking that a variable $x$ being of type $T$ means that the only "values" that $x$ can "take" are the (presumably closed) terms of type $T$. This isn't true and is not implied by anything I say above. I agree that you can see types as more than syntactic entities, but I think the different syntactic role types play makes a clear contrast to sets. – Derek Elkins left SE Apr 30 '18 at 21:13
4

I believe that one of the most concrete differences about sets and types is the difference in the way the "things" in your mind are encoded into the formal language.

Both sets and types allow you to speak about things, and collections of things. The main difference is that with sets, you can ask any question you want about things and it will maybe be true, maybe not; while with types, you first have to prove that the question makes sense.

For example, if you have booleans $\mathbb B=\{\operatorname{true},\operatorname{false}\}$ and natural numbers $\mathbb N=\{0, 1,\dots \}$, with types, you can not ask if $\operatorname{true}=1$ which you can with sets.

One way to interpret this is that with sets, everything is encoded into a single collection: the collection of all sets. $0$ is encoded as $[0]=\{\}$, $n+1$ is encoded as $[n+1]=\{[n]\}\cup [n]$ and $\operatorname{true}$ and $\operatorname{false}$ can be encoded by any two distinct sets. So that it actually makes sense to ask if $\operatorname{true}=1$, as it can be understood as asking if "the encoding chosen for $\operatorname{true}$ is the same as the encoding chosen for $1$". But the answer to this question could change if we chose another encoding: it is about the encodings and not really about the things.

You can then think of types as describing the encoding of the things inside it. With types, to ask the question of whether $a=b$, you first have to show that $a$ and $b$ have the same type, i.e. that they were encoded in the same way, which prohibits questions such as $\operatorname{true}=1$. You could still want to have a big type $S$ in which both $\mathbb B$ and $\mathbb N$ could be encoded, and then given two encodings $\iota_\mathbb B:\mathbb B\to S$ and $\iota_\mathbb N:\mathbb N\to S$, you could ask whether $\iota_\mathbb B(\operatorname{true})=\iota_\mathbb N(1)$ but the fact that this question depends on the encodings (and the choice of encodings) is now explicit.

Note that in those cases, whether the question made sense was actually easy to see but it could be much harder as in, for example, $(\operatorname{if} \text{very_hard_question} \operatorname{then} 1 \operatorname{else} \operatorname{true})=1$.

In summary, sets let you ask any question you want, but types force you to make encodings explicit when the answer may depend on them.

xavierm02
  • 1,255
  • 6
  • 14
  • You are probably thinking of one specific kind of set theory (something along a single-sorted theory a la ZFC). However, there are other kinds of set theory which require lots of checking that it makes sense. And the way set theory is used in practice is much closer to these other set theories. Do you think a student could ask "Is $\mathbb{R}$ an element of $\sin(\sqrt{2})$?" without being scolded? The distinction between type theory and set theory is not in the formalism, it's in the meaning. – Andrej Bauer Apr 30 '18 at 13:23
  • @AndrejBauer Right. Would you agree that this answer gives a differences between single-sorted theories (including most set theories, or at least the most common ones), and multi-sorted theories (including all (?) type theories)? – xavierm02 Apr 30 '18 at 13:28
  • Even in a single-sorted theory you have to distinguish terms from formulas... – Andrej Bauer Apr 30 '18 at 13:31
  • @AndrejBauer I don't understand your second comment. – xavierm02 Apr 30 '18 at 13:40
  • A single-sorted first-order theory has two syntactic categories: logical formulas and terms. One has to make sure they're not mixed up, or else you could end up writing "$\emptyset \implies (\forall x \in X . \phi(x)) \in \mathbb{N}$". – Andrej Bauer Apr 30 '18 at 13:42
  • @AndrejBauer Yes. You will most likely describe a single-sorted first-order theory in a multi-sorted meta-theory but I fail to see how this contradicts my answer to your first comment. I'm basically saying that if the theory is single-sorted and the meta-theory is multi-sorted, and you encode some of the meta-theory in the theory, then you may be able to ask questions in the theory that would not make sense (as is, but would make sense modulo encodings) in the meta-theory because some encodings are invisible for the theory. – xavierm02 Apr 30 '18 at 13:52