1 \documentclass[article, a4paper]{article}
2 \usepackage[T1]{fontenc}
5 \usepackage[normalem]{ulem}
7 \usepackage{subcaption}
9 %% -----------------------------------------------------------------------------
11 %% \usepackage[osf]{libertine}
12 %% \usepackage{helvet}
13 %% \usepackage{lmodern}
14 %% \IfFileExists{microtype.sty}{\usepackage{microtype}}{}
16 %% -----------------------------------------------------------------------------
19 % \usetikzlibrary{positioning}
20 %% \usetikzlibrary{shapes}
21 %% \usetikzlibrary{arrows}
22 %% \usepackage{tikz-cd}
23 %% \usepackage{pgfplots}
26 %% -----------------------------------------------------------------------------
28 \usepackage{amssymb,amsmath}
30 \usepackage{turnstile}
31 \usepackage{centernot}
33 %% -----------------------------------------------------------------------------
35 \usepackage{bussproofs}
37 \usepackage[export]{adjustbox}
40 %% -----------------------------------------------------------------------------
45 %% \setcounter{secnumdepth}{0}
47 %% -----------------------------------------------------------------------------
48 % We will generate all images so they have a width \maxwidth. This means
49 % that they will get their normal width if they fit onto the page, but
50 % are scaled down if they would overflow the margins.
53 \ifdim\Gin@nat@width>\linewidth\linewidth
54 \else\Gin@nat@width\fi
58 %% -----------------------------------------------------------------------------
61 setpagesize=false, % page size defined by xetex
62 unicode=false, % unicode breaks when used with xetex
69 pdfauthor={Francesco Mazzoli <fm2209@ic.ac.uk>},
70 pdftitle={The Paths Towards Observational Equality},
75 % Make links footnotes instead of hotlinks:
76 % \renewcommand{\href}[2]{#2\footnote{\url{#1}}}
78 % avoid problems with \sout in headers with hyperref:
79 \pdfstringdefDisableCommands{\renewcommand{\sout}{}}
81 \title{The Paths Towards Observational Equality}
82 \author{Francesco Mazzoli \href{mailto:fm2209@ic.ac.uk}{\nolinkurl{<fm2209@ic.ac.uk>}}}
89 \setlength{\tabcolsep}{12pt}
91 The marriage between programming and logic has been a very fertile one. In
92 particular, since the simply typed lambda calculus (STLC), a number of type
93 systems have been devised with increasing expressive power.
95 In the next sections I will give a very brief overview of STLC, and then
96 describe how to augment it to reach the theory I am interested in,
97 Inutitionistic Type Theory (ITT), also known as Martin-L\"{o}f Type Theory after
98 its inventor. The exposition is quite dense since there is a lot of material to
99 cover, for a more complete treatment of the material the reader can refer to
100 \citep{Thompson1991, Pierce2002}.
102 I will then explain why equality has been a tricky business in these theories,
103 and talk about the various attempts have been made to make the situation better.
104 One interesting development has recently emerged: Observational Type theory. I
105 propose to explore the ways to turn these ideas into useful practices for
106 programming and theorem proving.
108 \section{Simple and not-so-simple types}
110 \subsection{Untyped $\lambda$-calculus}
112 Along with Turing's machines, the earliest attempts to formalise computation
113 lead to the $\lambda$-calculus \citep{Church1936}. This early programming
114 language encodes computation with a minimal sintax and most notably no ``data''
115 in the traditional sense, but just functions.
117 The syntax of $\lambda$-terms consists of just three things: variables,
118 abstractions, and applications:
120 \newcommand{\appspace}{\hspace{0.07cm}}
121 \newcommand{\app}[2]{#1\appspace#2}
122 \newcommand{\absspace}{\hspace{0.03cm}}
123 \newcommand{\abs}[2]{\lambda #1\absspace.\absspace#2}
124 \newcommand{\termt}{t}
125 \newcommand{\termm}{m}
126 \newcommand{\termn}{n}
127 \newcommand{\termp}{p}
128 \newcommand{\termf}{f}
129 \newcommand{\separ}{\ \ |\ \ }
130 \newcommand{\termsyn}{\mathit{term}}
131 \newcommand{\axname}[1]{\textbf{#1}}
132 \newcommand{\axdesc}[2]{\axname{#1} \fbox{$#2$}}
137 \termsyn & ::= & x \separ (\abs{x}{\termsyn}) \separ (\app{\termsyn}{\termsyn}) \\
138 x & \in & \text{Some enumerable set of symbols, e.g.}\ \{x, y, z, \dots , x_1, x_2, \dots\}
143 % I will omit parethesis in the usual manner. %TODO explain how
145 I will use $\termt,\termm,\termn,\dots$ to indicate a generic term, and $x,y$
146 for variables. I will also assume that all variable names in a term are unique
147 to avoid problems with name capturing. Intuitively, abstractions
148 ($\abs{x}{\termt}$) introduce functions with a named parameter ($x$), and
149 applications ($\app{\termt}{\termm}$) apply a function ($\termt$) to an argument
152 The ``applying'' is more formally explained with a reduction rule:
154 \newcommand{\bred}{\leadsto}
155 \newcommand{\bredc}{\bred^*}
158 \axdesc{reduction}{\termsyn \bred \termsyn}
159 $$\app{(\abs{x}{\termt})}{\termm} \bred \termt[\termm / x]$$
162 Where $\termt[\termm / x]$ expresses the operation that substitutes all
163 occurrences of $x$ with $\termm$ in $\termt$. In the systems presented, the
164 $\bred$ relation also includes reduction of subterms, for example if $\termt
165 \bred \termm$ then $\app{\termt}{\termn} \bred \app{\termm}{\termn}$, and so on.
167 % % TODO put the trans closure
169 These few elements are of remarkable expressiveness, and in fact Turing
170 complete. As a corollary, we must be able to devise a term that reduces forever
171 (``loops'' in imperative terms):
173 \app{(\abs{x}{\app{x}{x}})}{(\abs{x}{\app{x}{x}})} \bred \app{(\abs{x}{\app{x}{x}})}{(\abs{x}{\app{x}{x}})} \bred \dots
175 Terms that can be reduced only a finite number of times (the non-looping ones)
176 are said to be \emph{normalising}, and the ``final'' term is called \emph{normal
177 form}. These concepts (reduction and normal forms) will run through all the
180 \subsection{The simply typed $\lambda$-calculus}
186 One way to ``discipline'' $\lambda$-terms is to assign \emph{types} to them, and
187 then check that the terms that we are forming make sense given our typing rules
190 We wish to introduce rules of the form $\Gamma \vdash \termt : \tya$, which
191 reads ``in context $\Gamma$, term $\termt$ has type $\tya$''.
193 The syntax for types is as follows:
195 \newcommand{\tyarr}{\to}
196 \newcommand{\tysyn}{\mathit{type}}
197 \newcommand{\ctxsyn}{\mathit{context}}
198 \newcommand{\emptyctx}{\cdot}
202 $$\tysyn ::= x \separ \tysyn \tyarr \tysyn$$
205 I will use $\tya,\tyb,\dots$ to indicate a generic type.
207 A context $\Gamma$ is a map from variables to types. We use the notation
208 $\Gamma; x : \tya$ to augment it, and to ``extract'' pairs from it.
210 Predictably, $\tya \tyarr \tyb$ is the type of a function from $\tya$ to
211 $\tyb$. We need to be able to decorate our abstractions with
212 types\footnote{Actually, we don't need to: computers can infer the right type
213 easily, but that is another story.}:
216 $$\termsyn ::= x \separ (\abs{x : \tysyn}{\termsyn}) \separ (\app{\termsyn}{\termsyn})$$
218 Now we are ready to give the typing judgements:
221 \axdesc{typing}{\Gamma \vdash \termsyn : \tysyn}
225 \begin{tabular}{c c c}
227 \UnaryInfC{$\Gamma; x : \tya \vdash x : \tya$}
230 \AxiomC{$\Gamma; x : \tya \vdash \termt : \tyb$}
231 \UnaryInfC{$\Gamma \vdash \abs{x : \tya}{\termt} : \tya \tyarr \tyb$}
238 \AxiomC{$\Gamma \vdash \termt : \tya \tyarr \tyb$}
239 \AxiomC{$\Gamma \vdash \termm : \tya$}
240 \BinaryInfC{$\Gamma \vdash \app{\termt}{\termm} : \tyb$}
245 This typing system takes the name of ``simply typed lambda calculus'' (STLC),
246 and enjoys a number of properties. Two of them are expected in most type
247 systems: %TODO add credit to pierce
249 \item[Progress] A well-typed term is not stuck - either it is a value or it can
250 take a step according to the evaluation rules. With ``value'' we mean a term
251 whose subterms (including itself) don't appear to the left of the $\bred$
253 \item[Preservation] If a well-typed term takes a step of evaluation, then the
254 resulting term is also well typed.
257 However, STLC buys us much more: every well-typed term
258 is normalising. It is easy to see that we can't fill the blanks if we want to
259 give types to the non-normalising term shown before:
261 \app{(\abs{x : ?}{\app{x}{x}})}{(\abs{x : ?}{\app{x}{x}})}
264 \newcommand{\lcfix}[2]{\mathsf{fix} \appspace #1\absspace.\absspace #2}
266 This makes the STLC Turing incomplete. We can recover the ability to loop by
267 adding a combinator that recurses:
269 \termsyn ::= \dots \separ \lcfix{x : \tysyn}{\termsyn}
273 \AxiomC{$\Gamma;x : \tya \vdash \termt : \tya$}
274 \UnaryInfC{$\Gamma \vdash \lcfix{x : \tya}{\termt} : \tya$}
278 \lcfix{x : \tya}{\termt} \bred \termt[(\lcfix{x : \tya}{\termt}) / x]
281 However, we will keep STLC without such a facility. In the next section we shall
282 see why that is preferable for our needs.
284 \subsection{The Curry-Howard correspondence}
285 \label{sec:curry-howard}
287 \newcommand{\lcunit}{\mathsf{()}}
289 It turns out that the STLC can be seen a natural deduction system for
290 propositional logic. Terms are proofs, and their types are the propositions
291 they prove. This remarkable fact is known as the Curry-Howard correspondence,
294 The ``arrow'' ($\to$) type corresponds to implication. If we wished to
295 prove that $(\tya \tyarr \tyb) \tyarr (\tyb \tyarr \tyc) \tyarr (\tya
296 \tyarr \tyc)$, all we need to do is to devise a $\lambda$-term that has the
299 \abs{f : (\tya \tyarr \tyb)}{\abs{g : (\tyb \tyarr \tyc)}{\abs{x : \tya}{\app{g}{(\app{f}{x})}}}}
301 That is, function composition. We might want extend our bare lambda calculus
302 with a couple of terms to make our natural deduction more pleasant to use. For
303 example, tagged unions (\texttt{Either} in Haskell) are disjunctions, and tuples
304 (or products) are conjunctions. We also want to be able to express falsity, and
305 that is done by introducing a type inhabited by no terms. If evidence of such a
306 type is presented, then we can derive any type, which expresses absurdity.
307 Conversely, $\top$ is the type with just one trivial element, $\lcunit$.
309 \newcommand{\lcinl}{\mathsf{inl}\appspace}
310 \newcommand{\lcinr}{\mathsf{inr}\appspace}
311 \newcommand{\lccase}[3]{\mathsf{case}\appspace#1\appspace#2\appspace#3}
312 \newcommand{\lcfst}{\mathsf{fst}\appspace}
313 \newcommand{\lcsnd}{\mathsf{snd}\appspace}
314 \newcommand{\orint}{\vee I_{1,2}}
315 \newcommand{\orintl}{\vee I_{1}}
316 \newcommand{\orintr}{\vee I_{2}}
317 \newcommand{\orel}{\vee E}
318 \newcommand{\andint}{\wedge I}
319 \newcommand{\andel}{\wedge E_{1,2}}
320 \newcommand{\botel}{\bot E}
321 \newcommand{\lcabsurd}{\mathsf{absurd}\appspace}
326 \termsyn & ::= & \dots \\
327 & | & \lcinl \termsyn \separ \lcinr \termsyn \separ \lccase{\termsyn}{\termsyn}{\termsyn} \\
328 & | & (\termsyn , \termsyn) \separ \lcfst \termsyn \separ \lcsnd \termsyn \\
330 \tysyn & ::= & \dots \separ \tysyn \vee \tysyn \separ \tysyn \wedge \tysyn \separ \bot \separ \top
334 \axdesc{typing}{\Gamma \vdash \termsyn : \tysyn}
336 \AxiomC{$\Gamma \vdash \termt : \tya$}
337 \RightLabel{$\orint$}
338 \UnaryInfC{$\Gamma \vdash \lcinl \termt : \tya \vee \tyb$}
340 \UnaryInfC{$\Gamma \vdash \lcinr \termt : \tyb \vee \tya$}
343 \AxiomC{$\Gamma \vdash \termt : \tya \vee \tyb$}
344 \AxiomC{$\Gamma \vdash \termm : \tya \tyarr \tyc$}
345 \AxiomC{$\Gamma \vdash \termn : \tyb \tyarr \tyc$}
347 \TrinaryInfC{$\Gamma \vdash \lccase{\termt}{\termm}{\termn} : \tyc$}
351 \AxiomC{$\Gamma \vdash \termt : \tya$}
352 \AxiomC{$\Gamma \vdash \termm : \tyb$}
353 \RightLabel{$\andint$}
354 \BinaryInfC{$\Gamma \vdash (\tya , \tyb) : \tya \wedge \tyb$}
357 \AxiomC{$\Gamma \vdash \termt : \tya \wedge \tyb$}
358 \RightLabel{$\andel$}
359 \UnaryInfC{$\Gamma \vdash \lcfst \termt : \tya$}
361 \UnaryInfC{$\Gamma \vdash \lcsnd \termt : \tyb$}
368 \AxiomC{$\Gamma \vdash \termt : \bot$}
369 \RightLabel{$\botel$}
370 \UnaryInfC{$\Gamma \vdash \lcabsurd \termt : \tya$}
374 \RightLabel{$\top I$}
375 \UnaryInfC{$\Gamma \vdash \lcunit : \top$}
380 \axdesc{reduction}{\termsyn \bred \termsyn}
382 \lccase{(\lcinl \termt)}{\termm}{\termn} & \bred & \app{\termm}{\termt} \\
383 \lccase{(\lcinr \termt)}{\termm}{\termn} & \bred & \app{\termn}{\termt} \\
384 \lcfst (\termt , \termm) & \bred & \termt \\
385 \lcsnd (\termt , \termm) & \bred & \termm
389 With these rules, our STLC now looks remarkably similar in power and use to the
390 natural deduction we already know. $\neg A$ can be expressed as $A \tyarr
391 \bot$. However, there is an important omission: there is no term of the type $A
392 \vee \neg A$ (excluded middle), or equivalently $\neg \neg A \tyarr A$ (double
393 negation), or indeed any term with a type equivalent to those.
395 This has a considerable effect on our logic and it's no coincidence, since there
396 is no obvious computational behaviour for laws like the excluded middle.
397 Theories of this kind are called \emph{intuitionistic}, or \emph{constructive},
398 and all the systems analysed will have this characteristic since they build on
399 the foundation of the STLC\footnote{There is research to give computational
400 behaviour to classical logic, but we will not touch those subjects.}.
402 Finally, going back to our $\mathsf{fix}$ combinator, it's now easy to see how
403 we would want to exclude such a thing if we want to use STLC as a logic, since
404 it allows us to prove everything: $(\lcfix{x : \tya}{x}) : \tya$ clearly works
405 for any $A$! This is a crucial point: in general we wish to have systems that
406 do not let the user devise a term of type $\bot$, otherwise our logic will be
407 unsound\footnote{Obviously such a term can be present under a $\lambda$.}.
409 \subsection{Extending the STLC}
411 \newcommand{\lctype}{\mathsf{Type}}
412 \newcommand{\lcite}[3]{\mathsf{if}\appspace#1\appspace\mathsf{then}\appspace#2\appspace\mathsf{else}\appspace#3}
413 \newcommand{\lcbool}{\mathsf{Bool}}
414 \newcommand{\lcforallz}[2]{\forall #1 \absspace.\absspace #2}
415 \newcommand{\lcforall}[3]{\forall #1 : #2 \absspace.\absspace #3}
416 \newcommand{\lcexists}[3]{\exists #1 : #2 \absspace.\absspace #3}
418 The STLC can be made more expressive in various ways. Henk Barendregt
419 succinctly expressed geometrically how we can expand our type system:
423 & \lambda\omega \ar@{-}[rr]\ar@{-}'[d][dd]
424 & & \lambda C \ar@{-}[dd]
426 \lambda2 \ar@{-}[ur]\ar@{-}[rr]\ar@{-}[dd]
427 & & \lambda P2 \ar@{-}[ur]\ar@{-}[dd]
429 & \lambda\underline\omega \ar@{-}'[r][rr]
430 & & \lambda P\underline\omega
432 \lambda{\to} \ar@{-}[rr]\ar@{-}[ur]
433 & & \lambda P \ar@{-}[ur]
436 Here $\lambda{\to}$, in the bottom left, is the STLC. From there can move along
439 \item[Terms depending on types (towards $\lambda{2}$)] In other words, we can
440 quantify over types in our type signatures: $(\abs{A : \lctype}{\abs{x : A}{x}}) : \lcforallz{A}{A \tyarr A}$. The first and most famous instance of this idea
441 has been System F. This gives us a form of polymorphism and has been wildly
442 successful, also thanks to a well known inference algorithm for a restricted
443 version of System F known as Hindley-Milner. Languages like Haskell and SML
444 are based on this discipline.
445 \item[Types depending on types (towards $\lambda{\underline{\omega}}$)] In other
446 words, we have type operators: $(\abs{A : \lctype}{\abs{R : \lctype}{(A \to R) \to R}}) : \lctype \to \lctype \to \lctype$.
447 \item[Types depending on terms (towards $\lambda{P}$)] Also known as ``dependent
448 types'', give great expressive power: $(\abs{x : \lcbool}{\lcite{x}{\mathbb{N}}{\mathbb{Q}}}) : \lcbool \to \lctype$.
451 All the systems preserve the properties that make the STLC well behaved (some of
452 which I haven't mentioned yet). The system we are going to focus on,
453 Intuitionistic Type Theory, has all of the above additions, and thus would sit
454 where $\lambda{C}$ sits in the ``$\lambda$-cube'' above.
456 \section{Intuitionistic Type Theory}
458 \newcommand{\lcset}[1]{\mathsf{Type}_{#1}}
459 \newcommand{\lcsetz}{\mathsf{Type}}
460 \newcommand{\defeq}{\equiv}
462 \subsection{A Bit of History}
464 Logic frameworks and programming languages based on type theory have a long
465 history. Per Martin-L\"{o}f described the first version of his theory in 1971,
466 but then revised it since the original version was too impredicative and thus
467 inconsistent\footnote{In the early version $\lcsetz : \lcsetz$, see section
468 \ref{sec:core-tt} for an explanation on why this causes problems.}. For this
469 reason he gave a revised and consistent definition later \citep{Martin-Lof1984}.
471 A related development is the one of the polymorphic $\lambda$-calculus, and
472 specifically the previously mentioned System F, which was invented independently
473 by Girard and Reynolds. An can be found in \citep{Reynolds1994}. The
474 surprising fact is that while System F is impredicative it is still consistent
475 and strongly normalising. Coquand and Huet further extended this line of work
476 with the Calculus of Constructions (CoC) \citep{Coquand1986}.
478 \subsection{A Core Type Theory}
481 The calculus I present follows the exposition in \citep{Thompson1991}, and as
482 said previously is quite close to the original formulation of predicative ITT as
483 found in \citep{Martin-Lof1984}.
488 \termsyn & ::= & x \\
489 & | & \lcforall{x}{\termsyn}{\termsyn} \separ \abs{x : \termsyn}{\termsyn} \separ \app{\termsyn}{\termsyn} \\
490 & | & \lcexists{x}{\termsyn}{\termsyn} \separ (\termsyn , \termsyn) \separ \lcfst \termsyn \separ \lcsnd \termsyn \\
491 & | & \bot \separ \lcabsurd \termt \\
496 \axdesc{typing}{\Gamma \vdash \termsyn : \termsyn}
500 \begin{tabular}{c c c}
503 \UnaryInfC{$\Gamma;x : \tya \vdash x : \tya$}
506 \AxiomC{$\Gamma \vdash \termt : \bot$}
507 \RightLabel{$\bot E$}
508 \UnaryInfC{$\Gamma \vdash \lcabsurd \termt : A$}
511 \AxiomC{$\Gamma \vdash \termt : \tya$}
512 \AxiomC{$\tya \defeq \tyb$}
513 \RightLabel{$\defeq$ type}
514 \BinaryInfC{$\Gamma \vdash \termt : \tyb$}
521 \AxiomC{$\Gamma;x : \tya \vdash \termt : \tya$}
522 \RightLabel{$\forall I$}
523 \UnaryInfC{$\Gamma \vdash \abs{x : \tya}{\termt} : \lcforall{x}{\tya}{\tyb}$}
526 \AxiomC{$\Gamma \vdash \termt : \lcforall{x}{\tya}{\tyb}$}
527 \AxiomC{$\Gamma \vdash \termm : \tya$}
528 \RightLabel{$\forall E$}
529 \BinaryInfC{$\Gamma \vdash \app{\termt}{\termm} : \tyb[\termm / x]$}
536 \AxiomC{$\Gamma \vdash \termt : \tya$}
537 \AxiomC{$\Gamma \vdash \termm : \tyb[\termt / x]$}
538 \RightLabel{$\exists I$}
539 \BinaryInfC{$\Gamma \vdash (\termt, \termm) : \lcexists{x}{\tya}{\tyb}$}
542 \AxiomC{$\Gamma \vdash \termt: \lcexists{x}{\tya}{\tyb}$}
543 \RightLabel{$\exists E_{1,2}$}
544 \UnaryInfC{$\hspace{0.7cm} \Gamma \vdash \lcfst \termt : \tya \hspace{0.7cm}$}
546 \UnaryInfC{$\Gamma \vdash \lcsnd \termt : \tyb[\lcfst \termt / x]$}
555 \UnaryInfC{$\Gamma \vdash \lcset{n} : \lcset{n + 1}$}
558 \AxiomC{$\Gamma \vdash \tya : \lcset{n}$}
559 \AxiomC{$\Gamma; x : \tya \vdash \tyb : \lcset{m}$}
560 \RightLabel{$\forall, \exists$ type}
561 \BinaryInfC{$\Gamma \vdash \lcforall{x}{\tya}{\tyb} : \lcset{n \sqcup m}$}
563 \UnaryInfC{$\Gamma \vdash \lcexists{x}{\tya}{\tyb} : \lcset{n \sqcup m}$}
569 \axdesc{reduction}{\termsyn \bred \termsyn}
571 \app{(\abs{x}{\termt})}{\termm} & \bred & \termt[\termm / x] \\
572 \lcfst (\termt, \termm) & \bred & \termt \\
573 \lcsnd (\termt, \termm) & \bred & \termm
577 I will abbreviate $\lcset{0}$ as $\lcsetz$.
579 There are a lot of new factors at play here. The first thing to notice is that
580 the separation between types and terms is gone. All we have is terms, that
581 include both values (terms of type $\lcset{0}$) and types (terms of type
582 $\lcset{n}$, with $n > 0$). This change is reflected in the typing rules.
583 While in the STLC values and types are kept well separated (values never go
584 ``right of the colon''), in ITT types can freely depend on values.
586 This relation is expressed in the typing rules for $\forall$ and $\exists$: if a
587 function has type $\lcforall{x}{\tya}{\tyb}$, $\tyb$ can depend on $x$.
588 Examples will make this clearer once some base types are added in the next
591 $\forall$ and $\exists$ are at the core of the machinery of ITT:
594 \item[``forall'' ($\forall$)] is a generalisation of $\tyarr$ in the STLC and
595 expresses universal quantification in our logic. In the literature this is
596 also known as ``dependent product'' and shown as $\Pi$, following the
597 interpretation of functions as infinitary products. We will just call it
598 ``dependent function'', reserving ``product'' for $\exists$.
600 \item[``exists'' ($\exists$)] is a generalisation of $\wedge$ in the extended
601 STLC of section \ref{sec:curry-howard}, and thus we will call it ``dependent
602 product''. Like $\wedge$, it is formed by providing a pair of things. In our
603 logic, it represents existential quantification.
605 For added confusion, in the literature that calls $\forall$ $\Pi$, $\exists$
606 is often named ``dependent sum'' and shown as $\Sigma$. This is following the
607 interpretation of $\exists$ as a generalised, infinitary $\vee$, where the
608 first element of the pair is the ``tag'' that decides which type the second
612 Another thing to notice is that types are very ``first class'': we are free to
613 create functions that accept and return types. For this reason we $\defeq$ as
614 the smallest equivalence relation extending $\bredc$, where $\bredc$ is the
615 reflexive transitive closure of $\bred$; and we treat types that are equal
616 according to $\defeq$ as the same. Another way of seeing $\defeq$ is this: when
617 we want to compare two types for equality, we reduce them as far as possible and
618 then check if they are equal\footnote{Note that when comparing terms we do it up
619 to $\alpha$-renaming. That is, we do not consider relabelling of variables as
620 a difference - for example $\abs{x : A}{x} \defeq \abs{y : A}{y}$.}. This
621 works since not only each term has a normal form (ITT is strongly normalising),
622 but the normal form is also unique; or in other words $\bred$ is confluent (if
623 $\termt \bredc \termm$ and $\termt \bredc \termn$, then $\termm \bredc \termp$
624 and $\termn \bredc \termp$). This measure makes sure that, for instance,
625 $\app{(\abs{x : \lctype}{x})}{\lcbool} \defeq \lcbool$. The theme of equality
626 is central and will be analysed better later.
628 The theory presented is \emph{stratified}. We have a hierarchy of types
629 $\lcset{0} : \lcset{1} : \lcset{2} : \dots$, so that there is no ``type of all
630 types'', and our theory is predicative. The layers of the hierarchy are called
631 ``universes''. $\lcsetz : \lcsetz$ ITT is inconsistent due to Girard's paradox
632 \citep{Hurkens1995}, and thus loses its well-behavedness. Some impredicativity
633 sometimes has its place, either because the theory retain good properties
634 (normalization, consistency, etc.) anyway, like in System F and CoC; or because
635 we are at a stage at which we do not care - we will see instances of the last
636 motivation later. Moreover, universes can be inferred mechanically
637 \citep{Pollack1990}. It is also convenient to have a \emph{cumulative} theory,
638 where $\lcset{n} : \lcset{m}$ iff $n < m$. We eschew these measures to keep the
641 Lastly, the theory I present is fully explicit in the sense that the user has to
642 specify every type when forming abstractions, products, etc. This can be a
643 great burden if one wants to use the theory directly. Complete inference is
644 undecidable (which is hardly surprising considering the role that types play)
645 but partial inference (also called ``bidirectional type checking'' in this
646 context) in the style of \citep{Pierce2000} will have to be deployed in a
647 practical system. When showing examples obvious types will be omitted.
649 Note that the Curry-Howard correspondence runs through ITT as it did with the
650 STLC with the difference that ITT corresponds to an higher order propositional
653 \subsection{Base Types}
655 While the ITT presented is a fairly complete logic, it is not that useful for
656 programming. If we wish to make it better, we can add some base types to
657 represent the data structures we know and love, such as numbers, lists, and
660 \newcommand{\lctrue}{\mathsf{true}}
661 \newcommand{\lcfalse}{\mathsf{false}}
666 \termsyn & ::= & ... \\
667 & | & \lcbool \separ \lctrue \separ \lcfalse
670 \axdesc{typing}{\Gamma \vdash \termsyn : \termsyn}
674 \begin{tabular}{c c c}
677 \UnaryInfC{$\Gamma;x : \tya \vdash x : \tya$}
680 \AxiomC{$\Gamma \vdash \termt : \bot$}
681 \RightLabel{$\bot E$}
682 \UnaryInfC{$\Gamma \vdash \lcabsurd \termt : A$}
685 \AxiomC{$\Gamma \vdash \termt : \tya$}
686 \AxiomC{$\tya \defeq \tyb$}
687 \RightLabel{$\defeq$ type}
688 \BinaryInfC{$\Gamma \vdash \termt : \tyb$}
695 \AxiomC{$\Gamma;x : \tya \vdash \termt : \tya$}
696 \RightLabel{$\forall I$}
697 \UnaryInfC{$\Gamma \vdash \abs{x : \tya}{\termt} : \lcforall{x}{\tya}{\tyb}$}
700 \AxiomC{$\Gamma \vdash \termt : \lcforall{x}{\tya}{\tyb}$}
701 \AxiomC{$\Gamma \vdash \termm : \tya$}
702 \RightLabel{$\forall E$}
703 \BinaryInfC{$\Gamma \vdash \app{\termt}{\termm} : \tyb[\termm / x]$}
710 \AxiomC{$\Gamma \vdash \termt : \tya$}
711 \AxiomC{$\Gamma \vdash \termm : \tyb[\termt / x]$}
712 \RightLabel{$\exists I$}
713 \BinaryInfC{$\Gamma \vdash (\termt, \termm) : \lcexists{x}{\tya}{\tyb}$}
716 \AxiomC{$\Gamma \vdash \termt: \lcexists{x}{\tya}{\tyb}$}
717 \RightLabel{$\exists E_{1,2}$}
718 \UnaryInfC{$\hspace{0.7cm} \Gamma \vdash \lcfst \termt : \tya \hspace{0.7cm}$}
720 \UnaryInfC{$\Gamma \vdash \lcsnd \termt : \tyb[\lcfst \termt / x]$}
729 \UnaryInfC{$\Gamma \vdash \lcset{n} : \lcset{n + 1}$}
732 \AxiomC{$\Gamma \vdash \tya : \lcset{n}$}
733 \AxiomC{$\Gamma; x : \tya \vdash \tyb : \lcset{m}$}
734 \RightLabel{$\forall, \exists$ type}
735 \BinaryInfC{$\Gamma \vdash \lcforall{x}{\tya}{\tyb} : \lcset{n \sqcup m}$}
737 \UnaryInfC{$\Gamma \vdash \lcexists{x}{\tya}{\tyb} : \lcset{n \sqcup m}$}
743 \axdesc{reduction}{\termsyn \bred \termsyn}
745 \app{(\abs{x}{\termt})}{\termm} & \bred & \termt[\termm / x] \\
746 \lcfst (\termt, \termm) & \bred & \termt \\
747 \lcsnd (\termt, \termm) & \bred & \termm
752 \bibliographystyle{authordate1}
753 \bibliography{background}