ArticlePDF Available

Higher Inductive Types in Programming



We propose general rules for higher inductive types with non-dependent and dependent elimination rules. These can be used to give a formal treatment of data types with laws as has been discussed by David Turner in his earliest papers on Miranda [Turner(1985)]. The non-dependent elimination scheme is particularly useful for defining functions by recursion and pattern matching, while the dependent elimination scheme gives an induction proof principle. We have rules for non-recursive higher inductive types, like the integers, but also for recursive higher inductive types like the truncation. In the present paper we only allow path constructors (so there are no higher path constructors), which is sufficient for treating various interesting examples from functional programming, as we will briefly show in the paper: arithmetic modulo, integers and finite sets.
Higher Inductive Types in Programming
Henning Basold
(Radboud University and CWI Amsterdam, The Netherlands
Herman Geuvers
(Radboud University and Technical University Eindhoven, The Netherlands
Niels van der Weide
(Radboud University, The Netherlands
Abstract: We propose general rules for higher inductive types with non-dependent
and dependent elimination rules. These can be used to give a formal treatment of data
types with laws as has been discussed by David Turner in his earliest papers on Mi-
randa [Turner(1985)]. The non-dependent elimination scheme is particularly useful for
defining functions by recursion and pattern matching, while the dependent elimina-
tion scheme gives an induction proof principle. We have rules for non-recursive higher
inductive types, like the integers, but also for recursive higher inductive types like
the truncation. In the present paper we only allow path constructors (so there are no
higher path constructors), which is sufficient for treating various interesting examples
from functional programming, as we will briefly show in the paper: arithmetic modulo,
integers and finite sets.
Key Words: Functional Programming, Homotopy Type Theory, Higher Inductive
Category: D.3.1, F.4.m
1 Introduction
Already in the early days of programming it has been observed that type systems
can help to ensure certain basic correctness properties of programs. For example,
type systems can prevent the confusion of an integer value for a string value
inside a memory cell. Much research and literature has since been devoted to
type systems that allow more and more properties of programs to be checked,
while retaining decidability of type checking, see [Pierce(2002), Pierce(2004)].
The very idea of using types to ensure some basic correctness properties
stems from the realm of logic, namely from the monumental project of Russell
and Whitehead [Whitehead and Russell(1912)] to find a logical foundation of
mathematics. Since then, type systems had not been very successful in logic
until Martin-L¨of proposed a type system, now called Martin-L¨of type theory
(MLTT), that gives a computational reading to intuitionistic higher-order logic
Journal of Universal Computer Science, vol. 23, no. 1 (2017), 63-88
submitted: 4/8/16, accepted: 3/12/16, appeared: 28/1/17 © J.UCS
[Martin-L¨of(1975), Martin-L¨of(1982), Nordstr¨om et al.(1990)] based on Russell’s
theory of types [Russell(1996)]. This turned type systems from tools to merely
ensure correctness properties into first-class logics.
The main idea underlying MLTT is that terms (i.e., programs) can be used
inside types, we say that MLTT has dependent types. For example, given two
terms s, t,onecanformatypes=t. Its inhabitants, that is terms of type s=t,
should be thought of as proofs for the identity of sand t. It was then also realized
that dependent types can be used to give even stronger correctness specifications
of programs. For instance, suppose we can form for a type Aand natural number
natypeVecAn, the elements of which are lists over Aof length n.Thistype
allows us, for instance, to write a safe function head: Vec A(n+1) Athat
returns the first element of a given list. Hence, dependent types allow us to
establish statically verifiable invariants based on runtime data.
Invariants as the one described above are very useful, but we often want to
express more sophisticated invariants through types. An example is the type
Fin(A) of finite subsets of a given type A. Finite sets are generated by the
empty set, the singleton sets and the union of two sets together with a bunch
of equations for these operations. For instance, the empty set should be neutral
with respect to the union: ∅∪X=X=X∪∅. In many programming languages
this would be implemented by using lists over Aas underlying type and exposing
Fin(A) through the three mentioned operations as interface. The implementation
of these operations then needs to maintain some invariants of the underlying
lists, such that the desired equations hold. If these equations are used to prove
correctness properties of programs, then the programmer needs to prove that
the interface indeed preserves the invariants. This is a laborious task and is thus
very often not carried out. So we may ask to what extent data types can be
specified by an interface and invariants.
A possible extension of type systems to deal with this are quotient types.
These are available in a few functional programming languages, for example
Miranda [Turner(1985)], where they are called algebraic data types with associ-
ated laws [Thompson(1986), Thompson(1990)]. On the other hand, in the proof
assistant NuPRL quotient types are implemented using squash types and non-
determinism [Nogin(2002)]. In dependent types they have been introduced in a
limited form in [Barthe and Geuvers(1995)], where they are called congruence
types, and in [Hofmann(1995)]. Quotient types are fairly easy to use but have
a major drawback: quotients of types whose elements are infinite, like general
function spaces, often require some form of the axiom of choice, see for ex-
ample [Chapman et al.(2015)]. Moreover, quotient types detach the equational
specification of a data type from its interface, thus making their specification
harder to read. This is because the type and its equality are defined separately.
Both problems can be fixed through by using of higher inductive types
64 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
[Lumsdaine and Shulman(2012), Lumsdaine(2011), Sojakova(2015)], and some
examples are given in [The Univalent Foundations Program(2013)]. A limited
form of higher inductive types has been proposed in [Altenkirch et al.(2016)]
where they are defined using dialgebras. These are inductively constructed types,
but unlike inductive types, one can also specify propositional equalities in their
definition. So, there are not just term constructors, but also path constructors,
and the elimination rule also depends on the constructors for the path.
In this paper, we propose a general scheme for higher inductive types (HITs)
with non-dependent and dependent elimination rules and associated computa-
tion rules. We demonstrate our scheme through the use of HITs as replacement
for quotient types in programming by studying some illustrative examples. We
begin with arithmetic on integers modulo a fixed number. This example serves
as an introduction to the concept of higher inductive types, and the structures
and principles that are derived from their specification. Next, we give several de-
scriptions of the integers and study their differences. Especially interesting here
is that the elements of two HITs can be the same but the equality of one type
can be decidable whereas that of the other is not. The last example we give are
finite subsets of a given type. We show how set comprehension for finite sets can
be defined. All the examples are accompanied with proofs of some basic facts
that illustrate the proof principles coming with higher inductive types.
The rest of the paper is structured as follows. We first give in Section 2 a
brief introduction to Martin-L¨of type theory and the language of homotopy type
theory, as far as it is necessary. Next, we introduce in Section 3 the syntax for
the higher inductive types we will use throughout the paper. This is based on the
Master’s thesis of the third author [van der Weide(2016)], which also discusses
the semantics of HITs that are not recursive in the equality constructors. In
the following sections we study the mentioned examples of modulo arithmetic
(Section 4), integers (Section 5) and finite sets (Section 6). We close with some
final remarks and possibilities for future work in Section 7.
The results have been formalized in Coq using the homotopy type theory
library in [Bauer et al.(2016)].
2Martin-L¨of Type Theory and Homotopy Type Theory
In this section, we introduce the variant of Martin-L¨of type theory (MLTT)
[Nordstr¨om et al.(1990)] that we are going to use throughout the paper, and we
introduce homotopy type theory [The Univalent Foundations Program(2013)].
This type theory has as type constructors dependent function spaces (also known
as Π-types), dependent binary products (aka Σ-types), binary sum types (co-
products) and identity types. Later, in Section 3, we will extend the type theory
with higher inductive types, which will give us some base types like natural
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
Next, we will restate some well-known facts about MLTT and the identity
types in particular. The properties of identity types lead us naturally towards
the terminology of homotopy theory, which we discuss at the end of the section.
2.1 Martin-L¨of Type Theory
We already argued in the introduction for the usefulness of dependent type
theories, so let us now come to the technical details of how to realize such a
theory. The most difficult part of defining such a theory is the fact that contexts,
types, terms and computation rules have to be given simultaneously, as these
rules use each other. Thus the following rules should be taken as simultaneous
inductive definition of a calculus.
We begin by introducing a notion of context. The purpose of contexts is to
capture the term variables and their types that can be used in a type, which
makes the type theory dependent, or a term. These can be formed inductively
by the following two rules.
· Ctx
ΓCtx ΓA:Type
Γ, x :ACtx
Note that in the second rule the type Amay use variables in Γ, thus the order
of variables in a context is important. We adopt the convention to leave out the
empty context ·on the left of a turnstile, whenever we give judgments for term
or type formations.
The next step is to introduce judgments for kinds, types and terms. Here,
the judgment ΓA:Type says that Ais a well-formed type in the context Γ,
while Γt:Adenotes that tis a well-formed term of type Ain context Γ.For
kinds we only have the following judgment.
ΓType :Kind
To ease readability, we adopt the following convention.
Notation 1. If we are given a type Bwith Γ, x :AB:Type and a term
Γt:A, we denote by B[t] the type in which thas been substituted for x.In
particular, we indicate that Bhas xas free variable by writing B[x].
The type formation rules for dependent function spaces, dependent binary
products and sum types, and the corresponding term formation rules are given
as follows. To avoid duplication of rules, we use to denote either Type or
66 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
Kind.Thus,wewriteΓM:whenever Mis a type or the universe Type.
Γ, x :AM:
Γ, x :AB:Type
ΓA, B :Type
Γ, x :AM:Γ, x :At:M
Γλx.t :(x:A)M
Γ, x :AM:Γt:(x:A)s:A
Γ(t, s):(x:A)×B[x]
Γ, z :A+BM:Γ, x :At:M[in1x]Γ, y :Bs:M[in2y]
Γ{in1x→ t;in
2y→ s}:(z:A+B)M
If ΓA, B :Type,thenwewriteABand A×Binstead of (x:A)B
and (x:A)×B, respectively.
Note that we can obtain two kinds of function spaces: ABfor a type
Band AType. The latter models families of types indexed by the type A.
Also note that the elimination rule for the sum type gives us what is called large
elimination, in the sense that we can eliminate a sum type to produce a new
type by case distinction. For instance, later we can define the unit type 1as an
inductive type and then a type family
X={in1x→ A;in
2y→ B}:1+1Type,
such that Xtreduces to either Aor B, depending on t.
Next, identity types and their introduction and elimination terms are given
by the following rules.
ΓA:Type Γs, t :A
Γrefl t:t=t
Γ, x :A, y :A, p :x=yY:Type Γt:(x:A)Y[x, x, refl x]
ΓJx,y,p(t):(xy:A)(p:x=y)Y[x, y, p]
Higher inductive types will allow us to add more constructors, besides refl, to
identity types. This will, surprisingly so, not affect the elimination principle
given by J.TheJ-rule does not imply uniqueness of identity proofs, so it is also
valid if there are other equality proofs. We discuss as part of the introduction to
homotopy type theory.
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
To be able to evaluate computations in MLTT, we introduce a rewriting
relation −→ on terms and types [Nordstr¨om et al.(1990)]. This rewriting relation
is given on terms as the compatible closure of the following clauses.
(λx.t)s−→ t[s/x]
2)−→ tk
{in1x1→ t1;in
2x2→ t2}(inks)−→ tk[s/xk]
Jx,y,p(t)ss(refl s)−→ ts
On types, the reduction relation is obtained as the compatible closure of
s−→ t
Ys−→ Yt
Let us denote the relation for reductions in either direction by ←→ :=←− −→ .
That is to say, we have s←→ tif either s−→ tor t−→ s.Moreover,we
obtain definitional equivalence, denoted by , as the equivalence closure of the
rewriting relation. Since definitionally equal terms are considered to carry the
same information, we use the following conversion rule that allows us to mix
rewriting steps in types with type checking.
ΓX, Y :Type Γu:XX←→ Y
By repeatedly applying this rule, we can also replace X←→ Yby XYin it.
Let us now establish some facts about identity types, which will prove very
useful later and are also relevant to the discussion of homotopy type theory.
First of all, we can prove that the identity is symmetric and transitive, thus an
equivalence relation. In type theoretical terms we establish that for each type
Athere are terms symmAand transA, as indicated below. We also say that the
corresponding types are inhabited.
transA:(xyz :A)(x=y)(y=z)(x=z)
Proof. To demonstrate a typical use of the J-rule, let us prove transitivity by
giving the corresponding term transA. We put
Y[x, y, p]:=(z:A)(y=z)(x=z)
t:=λx z q.q,
so t:(x:A)(z:A)(x=z)(x=z), hence t:(x:A)Y[x, x, refl x].
These definitions give us then that
transA:=λx y z q.Jx,y,p(t)xyqz
is of the correct type.
68 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
In a similar spirit, one can use the J-rule to also prove the following facts
about identity types.
Proposition 2. Let XType :and x:XY[x]:Type be types. There are
terms of the following types.
ap : (f:XY)(xy:X)x=yfx=fy
transport : (xy:X)x=yY[x]Y[y]
The latter we abbreviate to
p:= transport xyp.
This allows us to define a term
apd : (f:(x:X)Y[x]) (xy :X)(p:x=y)p(fx)=fy.
We also can derive the following definitional equivalences for these terms
ap ftt(refl t)refl (fx)
transport tt(refl t)srefl s
apd ftt(refl t)refl (fx)
Note that the names “ap” and “apd” stand for “apply” and “dependent
apply”, respectively. Also, note that transport is Leibniz’ law.
Since the kind of equality that occurs in the type of apd appears frequently
in the following, we use the more symmetric notation
where x:XY[x]isatype,x, y :X,s:Y[x], t:Y[y]andp:x=y,sothis
denotes an equality in the type Y[y].
Using this notation, apd has the following type.
apd : (f:(x:X)Y[x]) (xy :X)(p:x=y)fx=Y
We abbreviate ap fxypby ap(f,p) and apd fxypby apd(f, p).
2.2 Homotopy Type Theory
We have discussed several types now, and most of these have a clear meaning.
For example, product types should be seen as the type of pairs. For the identity
type, however, it is more complicated. An inhabitant p:a=bis supposed to be
a proof that aand bare equal.
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
In homotopy type theory types Tare seen as spaces X, inhabitants x:X
are seen as points of X, and inhabitants p:a=bare seen as paths between the
points aand b. The path refl ais interpreted as the constant path. For example,
the type Nis the space with points xnfor every natural number n, and the only
paths are constant paths. But we could also look at types in which there are
more paths from ato b. For example, we could look at the interval which has
two points 0 and 1 and a path seg between 0 and 1. Now there are two paths
from 0 to 0, namely the constant path, but we can also first go from 0 to 1 via
seg and then go back.
This seems rather boring now, because the most common types in type theory
just have a trivial interpretation. They just consist of points, and we cannot find
any non-constant path. However, one of the important features of homotopy
type theory is higher inductive types which allow us to add paths to types.
Even though new paths are added, the J-rule will still hold. For normal spaces
this is not strange: the J-rule says how every constant path is mapped which is
sufficient to define a map.
There are also two other features of homotopy type theory, but they do not
play a major role in this paper. These are function extensionality and univalence.
Univalence roughly says that isomorphic types are equal, and using this axiom
one can prove function extensionality.
Before studying higher inductive types in Section 3, we first need to introduce
some preliminary facts. For given s, t, u :A,p:s=tand q:t=uwe denote
the corresponding symmetry and transitivity proofs by
These can be interpreted as operations on paths. The path p1is made by
reversing p, and the path pqis the path which starts by walking along pand
then q. Again we abbreviate apd(f,x,y,p)byapd(f,p).
It is often required in homotopy type theory to compute the map pmore
concretely, and we shall do so as well. For a proof, we refer the reader to The-
orem 2.11.3 in [The Univalent Foundations Program(2013)]. It is expressed as a
composition of paths which is easier to determine in concrete situations.
Proposition 3. Let Aand Bbe types and f,g :ABbe function terms.
Furthermore, suppose that we have inhabitants a, a:Aand paths p:a=aand
q:fa=ga. There is a path of type
p(q) = ap(f,p)1qap(g, p),
where ptransports along Y:=fx=gx.
70 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
3 Higher Inductive Types
Regular inductive types are usually specified by their constructors, which then
give rise to canonical elimination principles, in the form of recursion or induction,
and the corresponding computation principles. A higher inductive type (HIT)
can additionally be equipped with path constructors for that type. The examples
discussed in this paper just require paths between points, so our syntax will be re-
stricted to this case and will not allow constructors for paths between paths. A se-
mantical justification of this syntax has been proposed in [van der Weide(2016)].
There, the semantics is given for non-recursive higher inductive types, that is,
HITs in which the path constructors do not quantify over the HIT that is being
As already mentioned, a higher inductive type Tcan have regular data con-
structors and path constructors. Data constructors can take as argument a poly-
nomial over T, which is the first notion we introduce in this section. Afterwards,
we introduce a special kind of terms, called constructor terms, that will be al-
lowed in the path constructors. These two definitions will then allow us to give
(dependent) elimination principles and well-behaved computation rules for HITs.
The syntax of higher inductive types consists of two parts. First, we have the
standard inductive type with a number of point constructors. On top of that,
higher inductive type allow the specification of paths between elements of that
type. Thus, we need to devise a syntax for adding path constructors between
two elements of the type at hand.
We begin by introducing polynomial type constructors that allow us to give
well-behaved constructor argument types. They ensure that a (higher) inductive
type given in our syntax is strictly positive. To ease readability in the following
definitions, we use the following notations for terms t:ACand s:BD.
idA:=λx.x :AA
t×s:=λx.(t(π1x),s(π2x)) : A×BC×D
t+s:={in1x→ in1(tx); in
2y→ in2(sy)}:A+BC+D
Definition 4. Let Xbe a variable. We say that Fis a polynomial (type con-
structor) if it is given by the following grammar.
F, G ::=A:Type |X|F×G|F+G
For a ty p e B,wedenotebyF[B] the type that is obtained by substituting B
for the variable Xand interpreting ×and + as type constructors. Let Hbe a
polynomial and f:BCbe a term. We define a term H[f]:H[B]H[C],
the action of Hon f, by induction in Has follows.
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
Remark. The notion of polynomial could be generalized to that of contain-
ers [Abbott et al.(2005)] or in the sense of [Gambino and Kock(2013)]. However,
we stick to the above simple definition to make the development, especially the
lifting to type families, more accessible.
To give the dependent elimination principle for higher inductive types, we
need to be able to lift polynomials to type families (predicates) and maps between
them. This is provided by the following definition.
Definition 5. Suppose Fis a polynomial type constructor. We define a lifting
of Fto type families as follows. Let U:BType be a type family, then we
can define F(U):F[B]Type by induction:
A(U):=λx. A (F×G)(U):=λx. F(U)(π1x)×G(U)(π2x)
X(U):=U(F+G)(U):={in1x→ F(U)x;in
2y→ G(U)y}
Moreover, given a term f:(b:B)UbVbwe define another term
H(f):(b:H[B]) H(U)bH(V)bagain by induction in H:
A(f):=λb. idA(F×G)(f):=λb. F(f)(π1b)×G(f)(π2b)
X(f):=f(F+G)(f):={in1x→ F(f)x;in
2y→ G(f)y}
A special case that we will use frequently is the choice U=1, which allows us
to obtain H(f):(b:H[B]) H(V)bfrom f:(b:B)Vb.
The correctness of this definition, that is, the typings announced in Defini-
tion 5 are valid, is proved by induction in the polynomial H[X].
Next, we give a preparatory definition for path constructors that allow us
to specify paths between two terms of the type at hand. To be able to give
type-correct computation rules, these terms must be, however, of a special form,
called constructor terms. Such constructor terms are built from a restricted
term syntax, possibly involving the data constructors and an argument for the
corresponding path constructor. We introduce constructor terms in the following
definition, for which we assume the type theory introduced in Section 2.1 to be
extended by the variable Xas base type.
Definition 6. Let kbe a positive natural number, and let H1,...,H
kbe poly-
nomials and c1:H1[X]X,...,c
k:Hk[X]Xbe constants. We say that r
is a constructor term (over c1,...,c
k), if there is a context Γin which no type
uses X,avariablexthat does not occur in Γ, and polynomials F[X]andG[X],
72 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
such that x:Fr:Gcan be derived using the following rules.
t:AXdoes not occur in A
x:Ft:A x :Fx:F
If xdoes not occur in r,wesaythatris a non-recursive constructor term.
Remark. We could have extended the type theory in Section 2.1 with constants
kand use restricted terms of that theory as constructor terms. Again,
to make the following development more accessible, we stick to the explicit def-
inition given above.
We now extend MLTT with higher inductive types. To this end, we devise a
scheme, whose syntax is similar to the syntax for inductive types in Coq,that
allows us to introduce a new type with data constructors and path constructors.
For this type we then have an elimination rule in form of dependent iteration
(induction) and the corresponding computation rules. Higher inductive types
that can be introduced through this scheme are of a restricted form, in that
we only allow data and path constructors, but no constructors for higher paths.
These are sufficient for the present exposition.
Definition 7. Ahigher inductive type is given according to the following scheme.
Inductive T(B1:Type)...(B:Type):=
1···B]) t1=r1
1···B]) tn=rn
Here, all Hiand Ajare polynomials that can use B1,...,B
, and all tjand rj
are constructor terms over c1,...,c
kwith x:Ajtj,r
j:T.IfXdoes not occur
in any of the Aj,thenTis called non-recursive and recursive otherwise.
We now give the rules that extend the type theory given in Section 2.1 with
higher inductive types, according to the scheme given in Definition 7.
Definition 8 (MLTT with HITs, Introduction Rules). For each instance
Tof the scheme in Definition 7, we add the following type formation rule to
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
those of MLTT.
ΓB1:Type ··· ΓB:Type
For the sake of clarity we leave the type parameters in the following out and
just write Tinstead of TB
1···B. The introduction rules for Tare given by the
following data and path constructors.
The dependent elimination rule for higher inductive types provides the in-
duction principle: it allows to construct a term of type (x:T)Yxfor
Y:TType. In the hypothesis of the elimination rule we want to assume
paths between elements of different types: the types Y(tj)andY(rj). Concretely
we will assume paths qas follows
px r
where pis the path constructor of Tmeaning that p:(x:A)t=rand
and r:Yr. We need to define
tby induction on ttostatethishypothesisinthe
elimination rule. This is done in the following definition.
Definition 9. Let ci:Hi[X]Xbe constructors for Twith 1 ikas in
Definition 7. Note that each constructor term x:Fr:Gterm immediately
givesrisetoatermx:F[T]r:G[T]. Given a type family U:TType and
terms Γfi:(x:Hi[T]) Hi(U)xU(cix) for 1 ik, we can define
Γ, x :F[T],h
by induction in ras follows.
It is straightforward to show that this definition is type correct.
Lemma 10. The definition of rin Definition 9 is type correct, that is, we indeed
have Γ, x :F[T],h
x:F(U)xr:G(U)runder the there given assumptions.
We are now in the position to give the (dependent) elimination rule for higher
inductive types.
74 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
Definition 11 (MLTT with HITs, Elimination and Computation). For
each instance Tof the scheme in Definition 7, the following dependent elimina-
tion rule is added to MLTT.
Γfi:(x:Hi[T]) Hi(Y)xY(cix)(fori=1,...,k)
Γqj:(x:Aj[T]) (hx:Aj(Y)x)
(pjx)rj(for j=1,...,n)
Note that
tjand rjin the type of qjdepend on all the fithrough Defini-
tion 9. If all the fiand qjare understood from the context, we abbreviate
For e very 1 ikwe have a term computation rule for each t:Hi[T]
T-rec (cit)−→ fitHi(T-rec) t,(2)
and for every 1 jnwe have a path computation rule for each a:Aj[T]
ja)−→ qjaAj(T-rec) a.(3)
This has to be understood in the sense that we extend the reduction relation
introduced in Section 2.1 with the clauses in (2) and (3), then take the compatible
closure, and allow this extended reduction relation in the conversion rule (1).
We can derive some simplifications of this definition for special cases of higher
inductive types. First of all, if a higher inductive type Tis non-recursive, then
the elimination rule in Definition 11 can be simplified to
Γfi:(x:Hi[T]) Hi(Y)xY(cix)(fori=1,...,k)
pjxrj(for j=1,...,n)
and the path computation rule becomes then
ja)−→ qja.
Second, if Yis also constant, that is, if there is D:Type with YtDfor all
t, then we obtain the non-dependent elimination or (primitive) recursion.
Γfi:Hi[T]Hi[D]D(for i=1,...,k)
tj=rj(for j=1,...,n)
In this case, the path computation rules simplifies even further to
ja)−→ qja.
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
An important property of reduction relations in type theories is that com-
putation steps preserve types of terms (su bjec t redu ct ion ). To be able to show
subject reduction for MLTT + HIT presented here, we need the following lemma.
Lemma 12. Let Tbe a higher inductive type and T-rec an instance of Defini-
tion 11. For all constructor terms x:Fr:Gand terms a:F[T]we have
G(T-rec) (r[a/x]) −→ r[a/x, F(T-rec) a/hx].
Proof. This is proved by induction in r.
Proposition 13. The computation rules in Definition 11 preserve types.
Proof. That the computation rules on terms preserve types can be seen by a
straightforward application of the typing rules on both sides of (2). For the
computation rules on paths, on the other hand, one can derive that
ja):T-rec (tj[a]) =Y
pjaT-rec (rj[a])
ΓqjaAj(T-rec) a:
tj[a, Aj(T-rec) a]=
pjarj[a, Aj(T-rec) a].
Using F=Ajand G=X, we obtain from Lemma 12 that
tj[a, Aj(T-rec) a]−→ T-rec (tj[a]).
Thus, by the conversion rule, we find that qjaAj(T-rec) aactually has the
same type as apd(T-rec,p
4 Modular Arithmetic
Modular arithmetic is not convenient to define using inductive types. One would
like to imitate the inductive definition of Nby means of constructors 0 for zero
and Sfor the successor. However, that will always give an infinite amount of
elements. If one instead defines N/mNby taking mcopies of the type with
just one element, then the definitions will be rather artificial. This way the usual
definitions for addition, multiplication or other operations, cannot be given in
the normal way. Instead one either needs to define them by hand, or code the
N/mNin Nand make a map mod m:NN/mN.
For higher inductive types this is different because one is able to postulate
new identities. This way we can imitate the definition N, and then add an equality
between 0 and Sm0. However, our definition for higher inductive types does not
allow dependency on terms. We can define N/2N,N/3N, and so on, but we
cannot give a definition for (m:N)N/mN. Instead of defining N/mNin
general, we thus define N/100Nwhich is not feasible to define using inductive
types. For other natural numbers we can give the same definition.
76 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
Inductive N/100N:=
|mod : 0 = S100 0
This is a nonrecursive higher inductive type, because the path 0 = Sn0doesnot
dependent on variables of type N/100N. The definition of N/100Ngives us the
constructors 0 : N/100N,S:N/100NN/100Nand mod : 0 = S100 0. Further-
more, we obtain for all type families Y:(x:N/100N)Type the following
dependent recursion principle, which we refer to as induction to emphasize the
relation to induction on natural numbers.
S100 0
S100 0 is defined by mod
S100 0 where we define the
transport modusing Proposition 2.
We note that, with this zand s,
S100 0s99 (s98 ···(s0z)···)),
where ndenotes Sn0. Finally, we have the following computation rules
N/100Nind(z,s,q)0−→ z,
N/100Nind(z,s,q)(Sx)−→ sx(N/100Nind(z, s,q)x),
apd(N/100Nind(z, s, q),mod) −→ q.
We will now demonstrate the use of the recursion principle by defining addi-
tion. To do so, we will need an inhabitant of the type (n:N/100N)n=S100 n,
which means that for every n:N/100Nwe have an equality of type n=S100 n.
This can be derived from the definition of N/100N, as we demonstrate now.
Proposition 14. There is a term gmod: (n:N/100N)n=S100 n.
Proof. We define the type family Y:N/100NType by λn.n =S100 n.
To apply induction, we first need to give an inhabitant zof type Y0whichis
0=S100 0. Since mod is of type 0 = S100 0, we can take z:=mod.
Next, we have to give a function s:(n:N)YnY(Sn), hence s
must be of type (n:N)n=S100 nSn=S100 (Sn). Thus, we can take
s:=λnλq. ap(S, q).
Finally, we need to give an inhabitant of z=Y
S100 0. To do so, we first
note that there is a path
S100 0s99 (s98 ···(s0z)···)ap(S, ap(S, ···ap(s, mod) ···))
=ap(λn.S100 n, mod),
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
where we used that for all f,g,p there is a path ap(fg, p) = ap(f,ap(g, p)).
We can now apply Proposition 3 to f:=id,g:=λn.S100 nand p:=q:=mod
to obtain a path
mod(mod) = ap(id,mod)1mod ap(λn.S100 n, mod).
Since there is a path ap(id,mod) = mod, we thus obtain a path q
mod(mod) = ap(id,mod)1mod ap(λn.S100 n, mod)
1mod ap(λn.S100 n, mod)
=ap(λn.S100 n, mod)
S100 0,
so that q:z=Y
S100 0, and gmod is given by N/100Nind(z,s,q).
Using this proposition and recursion on N/100N, we can define addition as
function term + : N/100NN/100NN/100N. The recursion principle is, as
we have shown in Section 3, a special case of induction and amounts here to
z:Ys:YYq:z=s100 z
with computation rules
N/100N-rec(z,s,q)0−→ z,
N/100N-rec(z,s,q)(Sn)−→ s(N/100N-rec(z, s,q)n)and
ap(N/100N-rec(z, s, q),p)−→ q.
To define addition, we give for every n:N/100Na function fm, which represents
λx.x+m. So, let m:N/100Nbe arbitrary, and next we define fmusing recursion.
For the inhabitant zof type N/100Nwe take m. Next we give a function s:
N/100NN/100Nwhich will be S. Lastly, we need to give a path between
mand S100 m, for which we can take gmod mby Proposition 14. This gives
us the desired function fm=N/100N(m, S, q m):N/100NN/100N.Bythe
computation rules we have
fm0=m, fm(Sx)=S(fmx),ap(fm,p)=qm.
Hence, we can define + : N/100NN/100NN/100Nby the function
λm :N/100Nλn :N/100N.fmn.
78 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
5 Integers
Another interesting data type, which we will study, are the integers. These can
be defined as a normal inductive type, but also as a higher inductive type.
Both representations have their advantages and disadvantages. To define it as
an inductive type, we can do the same as in [Licata and Shulman(2013)]. We
first need to define an inductive type for the positive natural numbers. This
type is called Pos and has a constructors one : Pos and S:PosPos.
The inductive typed definition is the same as for the natural numbers (one
constant and one unary constructor), but we interpret it differently. For example,
for the type Pos we define addition in a different where one +one would be Sone.
To clarify the distinction between the inductive types Nwe will sometimes write
SNfor the successor of Nand SPos for the successor of Pos. We have a function
i:PosNthat reflects the semantics of Pos, sending one to SN0andSPos n
to SN(in). In the reverse direction we have a function j:NPos that reflects
the semantics of Pos, sending 0 and SN0tooneandSN(SNn)toSPos (j(SNn)).
Now we can define the integers. We need a constructor for zero, and we need
constructors plus and minus which turn a positive number into an integer. All
in all, we get the following definition.
Inductive Z1:=
|plus : Pos Z1
|minus : Pos Z1
We also have a recursion rule.
If we define the integers this way, then it is possible to define functions like
addition, and show that every number has an inverse. We can also show that
equality is decidable.
Definition 15. AtypeAis said to have decidable equality,ifthetype
is inhabited, where as usual ¬T:=T0and 0is the type with no constructors.
Proposition 16. The type Z1has decidable equality.
The disadvantage of this definition is that we have to redefine everything
from the natural numbers to the positive numbers. Instead, one would like to
define the constructors plus and minus using natural numbers. This means that
we replace plus : Pos Z1 by a constructor plus:NZ2. However, if we
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
define it this way, then the number 0 will be added twice. To solve this, we use
higher inductive types, because then we can add equalities as well. We use almost
the same definition, but in addition, we add an equality plus0=minus
Inductive Z2:=
|zero : plus0 = minus0
NZ2. We also have a recursion rule.
The computation rules say that
Y,zeroY) (plusn)−→ plus
n)−→ minus
Y,zeroY),zero) −→ zeroY.
Now we have two types which should represent the integers, namely Z1and
Z2. These types are related via an isomorphism.
Theorem 17. We have an isomorphism Z1Z2.
Proof. We just show how to make the map g:Z2Z1. To make the function
g:Z2Z1, we use the map j:NPos defined before and the recursion
principle of the higher inductive type Z2. We need to say where plusnand
minusnare mapped to, and for that we define two functions. For the positive
integers, we define ϕ:NZ1whichsends0toZand SNnto plus (j(SNn)).
For the negative integers we define the map ψ:NZ1 which sends 0 to Zand
SNnto minus (j(SNn)). Finally, we need to give a path between ϕ0andψ0.
Note that by definition we have ϕ0Zand ψ0Z,andwechoosereZ.So,
we define gto be the map Z2-rec(ϕ, ψ, refl Z).
The definition of Z2 also has a disadvantage, and to illustrate it, we try
to define + : Z2×Z2Z2. To do so, we use induction on both arguments.
Now we need to give a value of +(plusn, plusm) which is plus(n+m). The
case +(minusn, minusm) is easy as well, because this is just minus(n+m).
However, defining +(plusn, minusm)and+(minus
n, plusm) requires more
work. We need to compare the values of nand min order to give this. In an
expression it would look like
+(plusn, minusm)=if n>m then plus(nm) else minus(mn),
80 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
+(minusn, plusm)=if n>m then minus(nm) else plus(mn).
There is also another way to represent the integers as a higher inductive
type, which makes defining addition easier. The previous data types encoded
the integers by partitioning them into positive and negative numbers. However,
we can try to imitate the definition of the natural numbers. These have two
constructors, namely 0 and the successor function S. The integers should instead
have three constructors, namely 0, the successor S, and predecessor P. On top,
we need to ensure that Sand Pare inverses, which can be achieved by using
a higher inductive type as follows. As a matter of fact, this is basically the
treatment of the integers that Turner gives in [Turner(1985)].
Inductive Z3:=
|inv1:(x:Z3) P(Sx)=x
|inv2:(x:Z3) S(Px)=x
Forthistypewehavethreeconstructors0:Z3, S:Z3Z3, and P:Z3
Z3 for points, and we have two constructors inv1:(x:Z3) P(Sx)=xand
inv2:(x:Z3) S(Px)=xfor paths. We also have a recursion rule
This rule is derived from dependent elimination by taking the type family Y
to be constant, see the discussion after Definition 11. We also get the following
computation rules, where we denote Z3-rec(0Y,S
Z3-rec 0 −→ 0Y,Z3-rec (Sx)−→ SY(Z3-rec x),
Z3-rec (Px)−→ PY(Z3-rec x),ap(Z3-rec,inv1x)−→ invY,1(Z3-rec x),
ap(Z3-rec,inv2x)−→ invY,2(Z3-rec x).
One of the interesting features of homotopy type theory is proof relevance: not all
proofs of equality are considered to be equal. Let us look at the term P(S(P0))
to demonstrate this. There are two ways to prove this term equal to P0. We can
use that P(Sx)=x, but we can also use that S(Px)=x. Hence, we have two
paths from P(S(P0)) to P0, namely inv1(Px) and ap(P, inv2(S(P0))). Since
higher inductive types are freely generated from the points and paths, there is no
reason why these two paths would be the same. As a matter of fact, one would
expect them to be different which is indeed the case.
Proposition 18. The paths inv1(P(S(P0))) and ap(P, inv2(S(P0))) are not
equal .
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
Before we give the proof, let us start with a proof sketch. In type theory
one can prove that the empty type 0and the type 1with just one element, are
different types. (That is, one can prove 0 1.) One can also define a type family
(n:N)Ynsending 0 to 0and Snto 1.Thisprovesthat0andSnare not
equal. More generally, this allows us to prove that different constructors of an
inductive type are indeed different.
However, for path constructors we cannot copy this argument. If we make a
family of types on Z3, then the paths inv1and inv2do not get sent to types.
Hence, the induction principle cannot be used in this way to show that inv1and
inv2are different. Instead we rely on the univalence axiom to prove this.
First we need a type for the circle. The definition can be given as a higher
inductive type.
Inductive S1:=
|base : S1
|loop : base = base
The main ingredient here is that loop and refl are unequal. One can show this
by using the univalence axiom [Licata and Shulman(2013)]. To finish the proof
of Proposition 18, we define a function f:Z3S1where the point 0 is sent
to base, the maps Sand Pare sent to the identity. Furthermore, we send the
path inv1to refl and inv2to loop. Using the elimination rule, we thus define f
as Z3-rec(base,id,id,refl,loop). Note that by the computation rules, fsatisfies
f0−→ base,f(Sx)−→ id (fx),f(Px)−→ id (fx),
ap(f,inv1)−→ refl,ap(f, inv2)−→ loop .
Now we can finish the proof of Proposition 18.
Proof. Our goal is to show that inv1(P(S(P0))) and ap(P, inv2(S(P0))) are
not equal, for which it is sufficient to show that ap(f, inv1(P(S(P0)))) and
ap(f,ap(P, inv2(S(P0)))) are not equal. From the computation rules we get
that ap(f,inv1(P(S(P0)))) refl. One can prove by path induction that there
is a path from ap(f,ap(g, p)) to ap(fg, p) for any fand g,thusthetype
ap(f,ap(P, inv2(S(P0)))) = ap(fP, inv2(S(P0)))
is inhabited. Using the computation rules, we see that fPis just f, and thus
ap(fP, inv2(S(P0))) is ap(f,inv2(S(P0))). Again we can use the computation
rules, and this time it gives that ap(f,inv2(S(P0))) loop. Hence, the paths
inv1(P(S(P0))) and ap(P, inv2(S(P0))) cannot be equal, because fsends
them to refl and loop respectively.
Proposition 18 might not seem very interesting at first, but it actually has
some surprising consequences. For that we need to use Hedberg’s Theorem which
82 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
says that in types with decidable equality there is only one proof of equality
Theorem 19 Hedberg’s Theorem. If a type Xhas decidable equality, then
we have a term
Using the contraposition from this theorem, we can thus immediately con-
clude that Z3 cannot have decidable equality.
Theorem 20. The type Z3does not have decidable equality.
This sounds odd at first sight, but all it means is that we cannot decide
equality just by using the induction scheme of Z3. There are two, quite similar
ways, to deal with this. We can either weaken the notion of decidable equal-
ity or we enforce that all the HITs, that are introduced through our scheme,
are sets [The Univalent Foundations Program(2013)]. Let us start with the first
possibility: weakening the notion of decidable equality. In (homotopy) type the-
ory, proofs of propositions are in general relevant, in the sense that we do not
just care about the existence of a proof but we are actually interested in the
witness. Recall from Proposition 18 that there are two different proofs of equal-
ity between P(S(P0)) and P0. Thus, proof relevance prevents equality to be
decidable on Z3. However, if we reason in a proof irrelevant way by neglecting
the fact that there might be several proofs for the same equality, then we obtain
merely decidable equality. To do so, we need the so-called truncation,whichis
given by the following higher inductive type.
Inductive || || (A:Type):=
|p:(xy :||A||)x=y
The truncation comes with the recursion rule
Y:(x, y :Y)x=y
Y):||A|| → Y
and computation rules
Y)(ιx)−→ ιYx,
Y),pxy)−→ pY(|A||-rec(ιY,p
In the truncation every element is equal, because we add for each x, y a path
pxy between them. Instead of the proposition x=y, we can now talk about
||x=y||. In the first type there are different proofs of equality, but in the second
every element is considered to be the same. We can solve the fact that Z3does
not have decidable equality by truncating the identity type for Z3, as in the
following theorem.
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
Theorem 21. The type Z3has a merely decidable equality, that is: the following
type is inhabited:
(xy:Z3) →||x=y|| +||¬(x=y)||.
Thus, if we want to consider the proofs of identities in Z3 to be irrelevant, we
have to replace the type s=tby its truncation ||s=t|| everywhere. There are
two problems with that. First, this is very verbose, in that we need to introduce
the truncation everywhere, and maps out of Z3 with the truncated identity types
are given in terms of the recursion principles of both Z3 and the truncation.
Second, if we want to map Z3 with the truncated identity type to another type
A, then that type must also be a set, that is, also the identity types of Amay
have at most one inhabitant.
Let us now study a different approach to solve the problem of decidability for
Z3. Since we do not consider higher inductive types with higher path constructors
in the present setting, we are morally just dealing with quotients. However, this
is not quite true, due to the fact that two paths might not be the same. For
example, Theorem 20 tells us that Z3andZ2 are not isomorphic. To obtain
actual quotients, we need to require that each HIT definable in our setting is a
set, c.f. [The Univalent Foundations Program(2013), Sec. 11.3.1]. Thus, for every
HIT Tdefined by the scheme in Definition 7, we add a constructor
isSetT:(xy:T)(pq:x=y)p=q. (4)
Note that we would also need to extend the recursion scheme for HIT in Defini-
tion 11 to account for this new constructor, since the constructor isSetTneeds
to be mapped to a corresponding term in the target type. If we add for each
HIT a constructor isSetTthough, then every type is a set and we can keep the
original recursion scheme.
Lemma 22. If for every higher inductive type Tintroduced by the scheme in
Definition 7 there is a constructor isSetTas in (4), then every type is a set.
Proof. The important property of sets is that they are preserved under the type
constructors in Section 2.1, see [The Univalent Foundations Program(2013), Sec
3.1 & Exerc. 3.2].
Forcing every HIT to be a set allows us to show that Z3 has decidable equality.
This theorem has been proved in the Coq formalization [van der Weide(2016)].
Theorem 23. If every type is a set, then Z3Z2and Z3has decidable equality.
6 Finite Sets
The last type we study here is a data type for finite sets. In functional pro-
gramming it is difficult to work with finite sets. Often one represents them as
84 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
lists on which special operations can be defined. This gives some issues in the
implementation, because different lists represent the same set and the definition
of a set-operation depends on the choice of the representative. For example, one
could remove the duplicates or not, and depending on that choice, functions on
the type will be different.
The use of higher inductive types allows to abstract from representation
details. The difference between sets and lists is that in a list the order of the
elements and the number of occurrences of an element matter, which does not
matter for sets. Higher inductive types offer the possibility to add equalities that
ignore the order of the elements and the number of occurrences. To demonstrate
this, let us start by defining Fin(A) in a similar way as [Bauer(2016)].
Inductive Fin( )(A:Type):=
|assoc : (x, y, z :Fin(A)) x(yz)=(xy)z
|neut1:(x:Fin(A)) x∪∅=x
|neut2:(x:Fin(A)) →∅∪x=x
|com : (x, y :Fin(A)) xy=yx
|idem : (x:A)LxLx=Lx
Summarizing, the type of finite sets on Ais defined as the free join-semilattice
on A. We abbreviate La to {a}. The constructors can be read from the definition,
but we give the recursion rule and the computation rules.
aY:(x, y, z :Y)xY(yYz)=(xYy)Yz
cY:(x, y :Y)xYy=yYx
In the following, we abbreviate Fin(A)-rec(Y,L
Fin(A)-rec. The computation rules are as follows.
Fin(A)-rec ∅−→∅
Y,Fin-rec (La)−→ LYa,
Fin-rec (xy)−→ Y(Fin-rec x) (Fin-rec x).
To demonstrate the possibilities of this definition, we define the comprehen-
sion and intersection of sets. We first define “element of a set” as a relation
:A×Fin(A)Bool. For this relation, we need to be able to compare el-
ements of A. This means that Amust have decidable equality, so we assume
that there is a term of type (xy :A)x=y+¬x=y. By sending every
inhabitant of x=yto True and every inhabitant of ¬x=yto False, we get a
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
function ==: A×ABool which decides the equality. Using this notation we
can define (a, s)fora:Aand s: Fin(A).
Definition 24. Let Abe a type with decidable equality. We define the function
:A×Fin(A)Bool by recursion on Fin(A) as follows.
(a, )False,(a, {b})a== b,
(a, x y)≡∈(a, x)∨∈(a, y)
In the notation of the recursion principle, given a:Awe define the function
Fin-rec : Fin(A)Bool, where we use in the recursion scheme the auxiliary
functions Bool := False, Bool :=,andLBool :=λb.a == b.
To finish the recursion, we need to give images of the paths assoc, neut1,
neut2, com, and idem. This is not difficult to do, and we demonstrate how to do
it for neut1. We need to give an inhabitant of type (x:Bool)xFal s e = x.
That term can be given by using properties of Bool, and thus the path we choose
is refl. For neut2we can do the same thing, and for the images of assoc, com, and
idem we use that on Bool is associative, commutative, and idempotent.
We will denote (a, x)byax. As seen in Definition 24, to make a map
Fin(A)Y, we need to give images of ,L,and, and then verify some
equations. Briefly said, we need to give a join semilattice Yand a map AY.
This way we also define the comprehension.
Definition 25. We define {| } : Fin(A)×(ABool)Fin(A). Let
ϕ:ABool. We define {S|ϕ}: Fin(A) by recursion on S: Fin(A).
{∅ | ϕ}≡∅,{{a}|ϕ}≡if ϕa then {a}else ,
Thus we use the recursion rule with Y:=,LYa:=if ϕa then {a}else ,
and Y:=. Moreover, we to check that Y≡∪is associative, commutative,
has Y≡∅as neutral element, and is idempotent. This is not difficult to check,
because we have all these equalities from the constructors.
Using the comprehension, we can define more operators. For example, we can
define xyas {x|λa.a y},andx\y:={x|λa.¬(ay)}.
7 Conclusion
We have given general rules for higher inductive types, both non-recursive and
recursive, where we have limited ourselves to higher inductive types with path
constructors. This provides a mechanism for adding data-types-with-laws to
86 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
functional programming, as it provides a function definition principle, a proof
(by induction) principle and computation rules. This fulfills at least partly the
desire set out in [Turner(1987)] to have a constructive type theory where compu-
tation rules can be added. The use of higher inductive types and their principles
was then demonstrated for typical examples that occur in functional program-
ming. Especially the case of finite sets usually requires a considerable amount of
book-keeping, which is lifted by the use of higher inductive types.
We believe that our system can be extended to include higher path construc-
tors. This requires extending the notion of constructor term and extending the
construction. It would be interesting to see which examples that arise naturally
in functional programming could be dealt with using higher paths. Furthermore,
it also remains to establish whether these rules are strongly normalizing, satisfy
Church-Rosser and canonicity. The current definition defines HITs in type the-
ory rather than languages like Haskell and Miranda. Hence, an open problem is
incorporating HITs in Turing complete functional programming languages.
The system we have may seem limited, because we only allow constructor
terms tand rin the types of equalities t=qfor path constructors. On the
other hand, for these constructor terms we can formulate the elimination rules
in simple canonical way, which we do not know how to do in general. Also, the
examples we have treated (and more examples we could think of) all rely on
constructor terms for path equalities, so these might be sufficient in practice.
We thank Ralf Hinze for the idea to link Turner’s work and higher inductive
types, and the anonymous referees for their suggestions.
[Abbott et al.(2005)] Abbott, M., Altenkirch, T., Ghani, N.: “Containers: Construct-
ing strictly positive types”; Theoretical Computer Science; 342 (2005), 1, 3–27.
[Altenkirch et al.(2016)] Altenkirch, T., Capriotti, P., Dijkstra, G., Forsberg, F. N.:
“Quotient inductive-inductive types”; arXiv preprint arXiv:1612.02346; (2016).
[Barthe and Geuvers(1995)] Barthe, G., Geuvers, H.: “Congruence types”; CSL; vol-
ume 1092 of Lecture Notes in Computer Science; 36–51; Springer, 1995.
[Bauer(2016)] Bauer, A.: “The Real Numbers in Homotopy Type Theory”; (2016);
computability and Complexity in Analysis, 2016.
[Bauer et al.(2016)] Bauer, A., Gross, J., Lumsdaine, P. L., Shulman, M., Sozeau, M.,
Spitters, B.: “The HoTT Library: A Formalization of Homotopy Type Theory in
Coq”; arXiv preprint arXiv:1610.04591; (2016).
[Chapman et al.(2015)] Chapman, J., Uustalu, T., Veltri, N.: “Quotienting the Delay
Monad by Weak Bisimilarity”; ICTAC; volume 9399 of LNCS; 110–125; Springer,
[Gambino and Kock(2013)] Gambino, N., Kock, J.: “Polynomial functors and polyno-
mial monads”; Math. Proc. Cambridge Phil. Soc.; 154 (2013), 01, 153–192.
Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
[Hedberg(1998)] Hedberg, M.: “A Coherence Theorem for Martin-L¨of’s Type Theory”;
Journal of Functional Programming; 8 (1998), 04, 413–436.
[Hofmann(1995)] Hofmann, M.: “A simple model for quotient types”; TLCA; volume
902 of Lecture Notes in Computer Science; 216–234; Springer, 1995.
[Licata and Shulman(2013)] Licata, D. R., Shulman, M.: “Calculating the Fundamen-
tal Group of the Circle in Homotopy Type Theory”; LICS; 223–232; IEEE Com-
puter Society, 2013.
[Lumsdaine(2011)] Lumsdaine, P. L.: “Higher Inductive Types: A Tour of the
Menagerie”; (2011); post on the Homotopy Type Theory Blog.
[Lumsdaine and Shulman(2012)] Lumsdaine, P. L., Shulman, M.: “Semantics of
Higher Inductive Types”; Preprint; (2012).
[Martin-L¨of(1975)] Martin-L¨of, P.: “An Intuitionistic Theory of Types: Predicative
Part”; Studies in Logic and the Foundations of Mathematics; 80 (1975), 73–118.
[Martin-L¨of(1982)] Martin-L¨of, P.: “Constructive Mathematics and Computer Pro-
gramming”; Studies in Logic and the Foundations of Mathematics; 104 (1982),
[Nogin(2002)] Nogin, A.: “Quotient Types: A Modular Approach”; International Con-
ference on Theorem Proving in Higher Order Logics; 263–280; Springer, 2002.
[Nordstr¨om et al.(1990)] Nordstr¨om, B., Petersson, K., Smith, J.: Programming in
Martin-L¨of ’s Type Theory, An Introduction; Oxford University Press (out of print
now available via, 1990.
[Pierce(2002)] Pierce, B. C.: Types and Programming Languages; The MIT Press,
[Pierce(2004)] Pierce, B. C.: Advanced Topics in Types and Programming Languages;
The MIT Press, 2004.
[Russell(1996)] Russell, B.: The Principles of Mathematics; WW Norton & Company,
[Sojakova(2015)] Sojakova, K.: “Higher Inductive Types as Homotopy-Initial Alge-
bras”; POPL; 31–42; ACM, 2015.
[The Univalent Foundations Program(2013)] The Univalent Foundations Program:
Homotopy Type Theory: Univalent Foundations of Mathematics; http://, Institute for Advanced Study, 2013; accessed: 2
January 2017, 10:20 am.
[Thompson(1986)] Thompson, S.: “Laws in Miranda”; Proceedings of the 1986 ACM
conference on LISP and functional programming; 1–12; ACM, 1986.
[Thompson(1990)] Thompson, S.: “Lawful Functions and Program Verification in Mi-
randa”; Science of Computer Programming; 13 (1990), 2-3, 181–218.
[Turner(1985)] Turner, D.: “Miranda: A non-strict functional language with polymor-
phic types”; J. Jouannaud, ed., Proceedings FPCA; volume 201 of LNCS; 1–16;
[Turner(1987)] Turner, D. N.: A new formulation of constructive type theory; Univer-
sity of Kent at Canterbury, Computing Laboratory, 1987.
[van der Weide(2016)] van der Weide, N.: Higher Inductive Types; Master’s thesis;
Radboud University; Nijmegen (2016).
[van der Weide(2016)] van der Weide, N.: “Implementation of the HIT Examples in
Coq”; (2016);
[Whitehead and Russell(1912)] Whitehead, A. N., Russell, B.: Principia Mathematica;
volume 2; University Press, 1912.
88 Basold H., Geuvers H., van der Weide N.: Higher Inductive Types ...
... This contrasts with the more convenient schema for regular inductive types in Agda, which allows parameters and arguments in any order. Building on these two works, we provide a schema for infinitary, non-conditional QITs combining the arbitrarily ordered parameters and arguments of the former [BGvdW17] with the curried constructors of the latter [DM18]. ...
... QWI-types are a general form of indexed quotient inductive type that capture many examples, including simple 1-cell complexes and non-recursive QITs [BGvdW17], non-structural QITs [Soj15], W-types with reductions [Swa18] and also infinitary QITs (e.g. unordered infinitely branching trees [AK16] and the F-type of Lumsdaine and Shulman [LS19]). ...
Full-text available
This paper introduces an expressive class of indexed quotient-inductive types, called QWI types, within the framework of constructive type theory. They are initial algebras for indexed families of equational theories with possibly infinitary operators and equations. We prove that QWI types can be derived from quotient types and inductive types in the type theory of toposes with natural number object and universes, provided those universes satisfy the Weakly Initial Set of Covers (WISC) axiom. We do so by constructing QWI types as colimits of a family of approximations to them defined by well-founded recursion over a suitable notion of size, whose definition involves the WISC axiom. We developed the proof and checked it using the Agda theorem prover.
... We are not the first to consider applications of univalence and HITs to programming languages. Angiuli et al. [2016] model Darcs-style patch theories as HITs; HoTTSQL [Chu et al. 2017] uses a univalent universe to define the semantics of a query language and prove optimizations correct; and Basold et al. [2017] discuss HITs for types often used in programming, including modular arithmetic, integers and finite sets. These examples predate implementations of Cubical Type Theory, and would likely be significantly easier to formalize in Cubical Agda. ...
... Countless variations of finite (multi)sets have been considered in all the main proof assistants for HoTT/UF; we limit our comparisons to those closest to our own. The finite sets of Basold et al. [2017] have been further studied by Frumin et al. [2018], and are defined by encoding finite subsets of A as the free join-semilattice on A. If one drops idempotency of the union operation, one obtains a HIT equivalent to List A / R ← . They also discuss a variation called listed finite sets which are almost exactly List A / R ← , except that they have a path constructor equating lists with duplicate elements. ...
In their usual form, representation independence metatheorems provide an external guarantee that two implementations of an abstract interface are interchangeable when they are related by an operation-preserving correspondence. If our programming language is dependently-typed, however, we would like to appeal to such invariance results within the language itself, in order to obtain correctness theorems for complex implementations by transferring them from simpler, related implementations. Recent work in proof assistants has shown that Voevodsky's univalence principle allows transferring theorems between isomorphic types, but many instances of representation independence in programming involve non-isomorphic representations. In this paper, we develop techniques for establishing internal relational representation independence results in dependent type theory, by using higher inductive types to simultaneously quotient two related implementation types by a heterogeneous correspondence between them. The correspondence becomes an isomorphism between the quotiented types, thereby allowing us to obtain an equality of implementations by univalence. We illustrate our techniques by considering applications to matrices, queues, and finite multisets. Our results are all formalized in Cubical Agda, a recent extension of Agda which supports univalence and higher inductive types in a computationally well-behaved way.
... Sojakova extended their result to various higher inductive types, among which are the groupoid quotient, W-suspensions, and the torus [56,57]. Basold et al. define a scheme for HITs allowing for both point and path constructors, but no higher constrtuctors [15], and a similar scheme is given by Moenclaey [53]. Dybjer and Moenclaey extended this scheme by allowing homotopy constructors and they give semantics in the groupoid model [27]. ...
... In addition, algebraic theories can be modeled as HITs, which allows one to define finite sets as a higher inductive type [32]. Other applications of HITs include homotopical patch theory, which provides a way to model version control systems [12], and modeling data types such as the integers [15,10]. Besides, quotient inductive-inductive types can be used to define the partiality monad [6]. ...
Full-text available
In this paper, we show that all finitary 1-truncated higher inductive types (HITs) can be constructed from the groupoid quotient. We start by defining internally a notion of signatures for HITs, and for each signature, we construct a bicategory of algebras in 1-types and in groupoids. We continue by proving initial algebra semantics for our signatures. After that, we show that the groupoid quotient induces a biadjunction between the bicategories of algebras in 1-types and in groupoids. We finish by constructing a biinitial object in the bicategory of algebras in groupoids. From all this, we conclude that all finitary 1-truncated HITs can be constructed from the groupoid quotient. All the results are formalized over the UniMath library of univalent mathematics in Coq.
... Various schemas for defining HITs have been proposed [35,14,11,22,23]. HITs have also been used in other computer science applications [5,24,6,4]. ...
Full-text available
We develop a constructive theory of finite multisets, defining them as free commutative monoids in Homotopy Type Theory. We formalise two algebraic presentations of this construction using 1-HITs, establishing the universal property for each and thereby their equivalence. These presentations correspond to equational theories including a commutation axiom. In this setting, we prove important structural combinatorial properties of singleton multisets arising from concatenations and projections of multisets. This is done in generality, without assuming decidable equality on the carrier set. Further, as applications, we present a constructive formalisation of the relational model of differential linear logic and use it to characterise the equality type of multisets. This leads us to the introduction of a novel conditional equational presentation of the finite-multiset construction.
... Cavallo [Cav18] verified that Z b ≃ Z w in RedTT. Higher inductive representations of the integers are discussed in [BGvdW17] and it is shown there that Z h without the last constructor is not a set. [Kv19] also discuss [AP18] and note that it is a corollary of their higher Seifert-van Kampen theorem -however, they derive it from initiality not from the induction principle. ...
Full-text available
We consider the problem of defining the integers in Homotopy Type Theory (HoTT). We can define the type of integers as signed natural numbers (i.e., using a coproduct), but its induction principle is very inconvenient to work with, since it leads to an explosion of cases. An alternative is to use set-quotients, but here we need to use set-truncation to avoid non-trivial higher equalities. This results in a recursion principle that only allows us to define function into sets (types satisfying UIP). In this paper we consider higher inductive types using either a small universe or bi-invertible maps. These types represent integers without explicit set-truncation that are equivalent to the usual coproduct representation. This is an interesting example since it shows how some coherence problems can be handled in HoTT. We discuss some open questions triggered by this work. The proofs have been formally verified using cubical Agda.
... [18] describes a syntax for higher inductive-inductive types using a theory of signatures similar to ours, but it does not construct categories of algebras and initial algebras. Semantics for different subclasses of HITs are given by [8,24,25,26,27]. Cubical type theories were shown to support some HITs in a computational way [28,29]. ...
Full-text available
Quotient inductive-inductive types (QIITs) are generalized inductive types which allow sorts to be indexed over previously declared sorts, and allow usage of equality constructors. QIITs are especially useful for algebraic descriptions of type theories and constructive definitions of real, ordinal and surreal numbers. We develop new metatheory for large QIITs, large elimination, recursive equations and infinitary constructors. As in prior work, we describe QIITs using a type theory where each context represents a QIIT signature. However, in our case the theory of signatures can also describe its own signature, modulo universe sizes. We bootstrap the model theory of signatures using self-description and a Church-coded notion of signature, without using complicated raw syntax or assuming an existing internal QIIT of signatures. We give semantics to described QIITs by modeling each signature as a finitely complete CwF (category with families) of algebras. Compared to the case of finitary QIITs, we additionally need to show invariance under algebra isomorphisms in the semantics. We do this by modeling signature types as isofibrations. Finally, we show by a term model construction that every QIIT is constructible from the syntax of the theory of signatures.
This paper introduces an expressive class of quotient-inductive types, called QW-types. We show that in dependent type theory with uniqueness of identity proofs, even the infinitary case of QW-types can be encoded using the combination of inductive-inductive definitions involving strictly positive occurrences of Hofmann-style quotient types, and Abel’s size types. The latter, which provide a convenient constructive abstraction of what classically would be accomplished with transfinite ordinals, are used to prove termination of the recursive definitions of the elimination and computation properties of our encoding of QW-types. The development is formalized using the Agda theorem prover.
Conference Paper
Full-text available
We report on the development of the HoTT library, a formalization of homotopy type theory in the Coq proof assistant. It formalizes most of basic homotopy type theory, including univalence, higher inductive types, and significant amounts of synthetic homotopy theory, as well as category theory and modalities. The library has been used as a basis for several independent developments. We discuss the decisions that led to the design of the library, and we comment on the interaction of homotopy type theory with recently introduced features of Coq, such as universe polymorphism and private inductive types.
Full-text available
In type theory one usually defines data types inductively. Over the years, many principles have been invented, such as inductive families, and inductive-recursive and inductive-inductive definitions. More recently, higher inductive types have been proposed in the context of homotopy type theory. Specific instances of higher inductive types have been successfully used in formalisations of homotopy theory and in formalising type theory in type theory. However, a general definition and theory of higher inductive types is still lacking. As an intermediate goal, we give a principle which unifies ordinary, indexed and inductive-inductive definitions, extended with path constructors from higher inductive types, but with no non-trivial structure between paths, i.e. we consider sets only. For this reason, we call these types quotient inductive-inductive types. We give an initial algebra semantics for these definitions, give the induction principle, and show that these two interpretations coincide.
Full-text available
It is now 10 years ago that two of us took the train to Stockholm to meet Per Martin-Löf and discuss his ideas on the connection between type theory and computing science. This book describes different type theories (theories of types, polymorphic and monomorphic sets, and subsets) from a computing science perspective. It is intended for researchers and graduate students with an interest in the foundations of computing science, and it is mathematically self-contained. We started writing this book about six years ago. One reason for this long time is that our increasing experience in using type theory has made several changes of the theory necessary. We are still in this process, but have nevertheless decided to publish the book now. We are, of course, greatly indebted to Per Martin-L¨of; not only for creating the subject of this book, but also for all the discussions we have had with him. Beside Martin-Löf, we have discussed type theory with many people and we in particular want to thank Samson Abramsky, Peter Aczel, Stuart Anderson, Roland Backhouse, Bror Bjerner, Robert Constable, Thierry Coquand, Peter Dybjer, Roy Dyckhoff, Gerard Huet, Larry Paulson, Christine Paulin-Mohring, Anne Salvesen, Björn von Sydow, and Dan Synek. Thanks to Dan Synek also for his co-authorship of the report which the chapter on trees is based on. Finally, we would like to thank STU, the National Swedish Board For Technical Development, for financial support.
The delay datatype was introduced by Capretta ( Logical Methods in Computer Science , 1(2), article 1, 2005) as a means to deal with partial functions (as in computability theory) in Martin-Löf type theory. The delay datatype is a monad. It is often desirable to consider two delayed computations equal, if they terminate with equal values, whenever one of them terminates. The equivalence relation underlying this identification is called weak bisimilarity. In type theory, one commonly replaces quotients with setoids. In this approach, the delay datatype quotiented by weak bisimilarity is still a monad–a constructive alternative to the maybe monad. In this paper, we consider the alternative approach of Hofmann ( Extensional Constructs in Intensional Type Theory , Springer, London, 1997) of extending type theory with inductive-like quotient types. In this setting, it is difficult to define the intended monad multiplication for the quotiented datatype. We give a solution where we postulate some principles, crucially proposition extensionality and the (semi-classical) axiom of countable choice. With the aid of these principles, we also prove that the quotiented delay datatype delivers free ω-complete pointed partial orders (ωcppos). Altenkirch et al. (Lecture Notes in Computer Science, vol. 10203, Springer, Heidelberg, 534–549, 2017) demonstrated that, in homotopy type theory, a certain higher inductive–inductive type is the free ωcppo on a type X essentially by definition; this allowed them to obtain a monad of free ωcppos without recourse to a choice principle. We notice that, by a similar construction, a simpler ordinary higher inductive type gives the free countably complete join semilattice on the unit type 1. This type suffices for constructing a monad, which is isomorphic to the one of Altenkirch et al. We have fully formalized our results in the Agda dependently typed programming language.
Conference Paper
The delay datatype was introduced by Capretta [3] as a means to deal with partial functions (as in computability theory) in Martin-Löf type theory. It is a monad and it constitutes a constructive alternative to the maybe monad. It is often desirable to consider two delayed computations equal, if they terminate with equal values, whenever one of them terminates. The equivalence relation underlying this identification is called weak bisimilarity. In type theory, one commonly replaces quotients with setoids. In this approach, the delay monad quotiented by weak bisimilarity is still a monad. In this paper, we consider Hofmann’s alternative approach [6] of extending type theory with inductive-like quotient types. In this setting, it is difficult to define the intended monad multiplication for the quotiented datatype. We give a solution where we postulate some principles, crucially proposition extensionality and the (semi-classical) axiom of countable choice. We have fully formalized our results in the Agda dependently typed programming language.
Conference Paper
Recent work on homotopy type theory exploits an exciting new correspondence between Martin-Lof's dependent type theory and the mathematical disciplines of category theory and homotopy theory. The mathematics suggests new principles to add to type theory, while the type theory can be used in novel ways to do computer-checked proofs in a proof assistant. In this paper, we formalize a basic result in algebraic topology, that the fundamental group of the circle is the integers. Our proof illustrates the new features of homotopy type theory, such as higher inductive types and Voevodsky's univalence axiom. It also introduces a new method for calculating the path space of a type, which has proved useful in many other examples.
The theory of types is intended to be a full-scale system for formalizing intuitionistic mathematics as developed. The language of the theory is richer than the languages of traditional intuitionistic systems in permitting proofs to appear as parts of propositions so that the propositions of the theory can express properties of proofs. There are axioms for universes that link the generation of objects and types and play somewhat the same role for the present theory as does the replacement axiom for Zermelo–Fraenkel set theory. The present theory is based on a strongly impredicative axiom that there is a type of all types in symbols. This axiom has to be abandoned, however, after it has been shown to lead to a contraction. This chapter discusses Normalization theorem, which can be strengthened in two ways: it can be made to cover open terms and it can be proved that every reduction sequence starting from an arbitrary term leads to a unique normal term after a finite number of steps. The definition of the notion of convertibility and the proof that an arbitrary term is convertible can no longer be separated because the type symbols and the terms are generated simultaneously.
We introduce the notion of a Martin-Löf category—a locally cartesian closed category with disjoint coproducts and initial algebras of container functors (the categorical analogue of W-types)—and then establish that nested strictly positive inductive and coinductive types, which we call strictly positive types, exist in any Martin-Löf category.Central to our development are the notions of containers and container functors. These provide a new conceptual analysis of data structures and polymorphic functions by exploiting dependent type theory as a convenient way to define constructions in Martin-Löf categories. We also show that morphisms between containers can be full and faithfully interpreted as polymorphic functions (i.e. natural transformations) and that, in the presence of W-types, all strictly positive types (including nested inductive and coinductive types) give rise to containers.