arXiv is now an independent nonprofit! Learn more
License: arXiv.org perpetual non-exclusive license
arXiv:2104.13675v5 [cs.LO] 11 Aug 2022

Apr. 29, 2021Aug. 12, 2022

Typability and Type Inference in Atomic PolymorphismThanks: The second author acknowledges the support of FCT — Fundação para a Ciência e a Tecnologia under the projects UIDB/04561/2020, UIDB/00408/2020 and UIDP/00408/2020, and she is also grateful to CMAFcIO — Centro de Matemática, Aplicações Fundamentais e Investigação Operacional and to LASIGE — Computer Science and Engineering Research Centre (Universidade de Lisboa).

M. Clarence Protin\rsupera Address: Rua Defensores da Liberdade 10 2o2^{o} Esq.
7050-230 Montemor-o-Novo, Portugal
Email address: cprotin@sapo.pt
and Gilda Ferreira\rsuperb Address: Universidade Aberta, 1269-001 Lisboa, Portugal; Centro de Matemática, Aplicações Fundamentais e Investigação Operacional — Faculdade de Ciências da Universidade de Lisboa, 1749-016 Lisboa, Portugal Email address: gmferreira@fc.ul.pt
Abstract.

It is well-known that typability, type inhabitation and type inference are undecidable in the Girard-Reynolds polymorphic system 𝐅\mathbf{F}. It has recently been proven that type inhabitation remains undecidable even in the predicative fragment of system 𝐅\mathbf{F} in which all universal instantiations have an atomic witness (system 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}). In this paper we analyze typability and type inference in Curry style variants of system 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} and show that typability is decidable and that there is an algorithm for type inference which is capable of dealing with non-redundancy constraints.

Key words and phrases: 
Lambda calculus; atomic polymorphism; typability; type inference; intuitionistic logic
lmcs-doi: Volume 18, Issue 3, Paper 22

Introduction

Type inhabitation, typability and type inference in Girard-Reynolds polymorphic system 𝐅\mathbf{F} (also known as the second-order polymorphically typed lambda calculus) [Gir71, Rey74, GLT89] are known to be undecidable [Lö76, DR19, Wel99].

Type inhabitation is the following problem: given a type AA, is there a term having that type? I.e. is there a term MM such that M:A\vdash M:A? Via the Curry-Howard isomorphism it corresponds to asking if a formula is provable.

Typability goes in the other way around:

(Typ) Given a term MM is there a type AA and a type environment Γ\Gamma such that ΓM:A\Gamma\vdash M:A?

Via the Curry-Howard isomorphism typability corresponds to asking if a construction is a proof of a formula, i.e. is there AA such that MM is the proof of AA?

What about being able to find the actual types (and type environments) which satisfy the condition above if the answer is affirmative? In this paper by the problem of type inference we mean the following:

(Ti) Given a term MM such that (Typ) admits an affirmative answer find a procedure to generate types AA and type environments Γ\Gamma such that ΓM:A\Gamma\vdash M:A.

Having an effective procedure for (Typ) the formulation above is readily seen to be equivalent to the standard formulation.

It has recently been proven [Pro21] that type inhabitation remains undecidable even in a very weak fragment of system 𝐅\mathbf{F} (known as system 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} or atomic polymorphism [Fer06, FF13]) where only atomic instantiations are allowed.

What about typability and type inference for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}? Is typability decidable? Can we obtain an algorithm for type inference? In this paper we show that typability is decidable and we give a procedure for type inference.

In analyzing the typing properties of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}, the system is considered not in its original Church style formulation (in which case they are trivial) but in Curry style variants where terms do not come with full type annotation.

The paper is structured as follows. In the next section we recall the system involved in the present study: system 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}.

In Section 2 we show that typability is decidable for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} in Curry style (according to the terminology of [Wel99][p.122] for 𝐅\mathbf{F}). In Section 3 we show that typability for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} in the Polymorphic Curry style (in which terms contain additional polymorphic typing information) is also decidable, the proof also furnishing a procedure for type inference restricted to redundant typings. In Section 4 we analyze non-redundant typability, show how we can check for such typings and generate them if they exist. In Section 5 it is remarked that the results of Section 4 yield as a particular case a method for type inference for Polymorphic Curry style 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}. This section also contains various other remarks and considerations about future work.

1. System 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}

The atomic polymorphic system 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} [FF13] is the fragment of Girard/Reynolds system 𝐅\mathbf{F} [Gir71, Rey74] induced by restricting to atomic instances the elimination inference rule for \forall, and the corresponding proof term constructor. System 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} was originally proposed as a natural and appealing framework for full intuitionistic propositional calculus (𝐈𝐏𝐂\mathbf{IPC}[Fer06, SF20]. 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} expresses the connectives of 𝐈𝐏𝐂\mathbf{IPC} in a uniform way avoiding bad connectives (according to Girard [GLT89], page 74) and avoiding commuting conversions. This explains the usefulness of the system in proof theoretical studies [Fer17a, Fer17b]. For related work in the topic see [PTP22], where the authors investigate predicative translations of 𝐈𝐏𝐂\mathbf{IPC} into system 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} using the equational framework presented in [TPP19] and giving an elegant semantic explanation (relying on parametricity) of the syntactic results on atomic polymorphism. Originally system 𝐅\mathbf{F} and system 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} were presented in Church style where types are embedded in terms. The questions of typability and type inference, mentioned in the Introduction, are meaningful only when we are in (variants of) Curry style, i.e., terms are untyped and the type information is kept apart. Each term has a set (which may be empty) of possible types. In what follows we present 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} in Polymorphic Curry style.

The types/formulas in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} are exactly the ones of system 𝐅\mathbf{F}:

A,B::=X|AB|X.AA,B\,::=\,X\,|\,A\to B\,|\,\forall X.A

The terms in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} are given by

M,N::=x|MN|λx.M|MX|ΛX.MM,N\,::=\,x\,|\,MN\,|\,\lambda x.M\,|\,MX\,|\,\Lambda X.M

having the following typing/inference rules

         (VAR)(\textup{VAR}) xdom(Γ)x\in dom(\Gamma)     Γx:Γ(x)\Gamma\vdash x:\Gamma(x)                     Γ{x:A}M:B\Gamma\cup\{x:A\}\vdash M:B (ABS)      Γλx.M:AB\Gamma\vdash\lambda x.M:A\to B         ΓM:AB\Gamma\vdash M:A\to B   ΓN:A\Gamma\vdash N:A (APP)           ΓMN:B\Gamma\vdash MN:B                                     

         ΓM:A\Gamma\vdash M:A (GENX)  XFTV(Γ)X\notin FTV(\Gamma)       ΓΛX.M:X.A\Gamma\vdash\Lambda X.M:\forall X.A          ΓM:X.A\Gamma\vdash M:\forall X.A (INST)        ΓMY:A[Y/X]\Gamma\vdash MY:A[Y/X]                             

where a type environment Γ\Gamma is a finite set x1:A1,,xn:Anx_{1}:A_{1},\ldots,x_{n}:A_{n} where xix_{i} are assumption (term) variables and AiA_{i} are types. We denote the set {x1,,xn}\{x_{1},\ldots,x_{n}\} by dom(Γ)dom(\Gamma), the set {A1,,An}\{A_{1},\ldots,A_{n}\} by ran(Γ)ran(\Gamma) and write Γ(x)=A\Gamma(x)=A whenever x:AΓx:A\in\Gamma. We denote the free variables in the types in ran(Γ)ran(\Gamma) by FTV(Γ)FTV(\Gamma).

Note that, as stressed in the beginning of this section, the difference between system 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} and system 𝐅\mathbf{F} lies in the restriction of the universal instantiation rule to type variables.

We can drop some of the information in the terms and present 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} alternatively in Curry style (see [Wel99], page 122 in the context of system 𝐅\mathbf{F}) which differs from the Polymorphic Curry style in the terms allowed

M,N::=x|MN|λx.MM,N\,::=\,x\,|\,MN\,|\,\lambda x.M

having the following type inference rules

         (VAR)(\textup{VAR}) xdom(Γ)x\in dom(\Gamma)     Γx:Γ(x)\Gamma\vdash x:\Gamma(x)                     Γ{x:A}M:B\Gamma\cup\{x:A\}\vdash M:B (ABS)      Γλx.M:AB\Gamma\vdash\lambda x.M:A\to B         ΓM:AB\Gamma\vdash M:A\to B   ΓN:A\Gamma\vdash N:A (APP)           ΓMN:B\Gamma\vdash MN:B                                     

      ΓM:A\Gamma\vdash M:A (GENX)  XFTV(Γ)X\notin FTV(\Gamma)       ΓM:X.A\Gamma\vdash M:\forall X.A          ΓM:X.A\Gamma\vdash M:\forall X.A (INST)        ΓM:A[Y/X]\Gamma\vdash M:A[Y/X]                           

In what follows, we use A{Y/X}A\{Y/X\} to denote a type that results from AA by replacing some (possibly all) free occurrences of XX by YY. Observe that if we have ΓM:A\Gamma\vdash M:A in Curry style derived using the (INST) rule then we have ΓM:X.A{X/Y}\Gamma\vdash M:\forall X.A\{X/Y\} for some type variables XX and YY. Likewise if we have ΓMY:A\Gamma\vdash MY:A in Polymorphic Curry style then ΓM:X.A{X/Y}\Gamma\vdash M:\forall X.A\{X/Y\} for some type variable XX.

2. Typability for the Curry system

In this Section we show that the typability problem for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}, considering the system in Curry style, is decidable. The strategy will be to reduce the typability problem to the corresponding problem in the simply typed lambda-calculus λ\lambda^{\to} which is known to be decidable. To do this, although not strictly necessary, we will employ a theorem which holds more generally for Polymorphic Curry style terms.

Fix a type variable \circ. Given a type AA of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} we define A\langle A\rangle as the type of λ\lambda^{\rightarrow} given by X:=\langle X\rangle:=\circ, BC:=BC\langle B\rightarrow C\rangle:=\langle B\rangle\rightarrow\langle C\rangle and X.A:=A\langle\forall X.A\rangle:=\langle A\rangle. Let MM be a term of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} in Polymorphic Curry style (or in Curry style). We define [M][M] as the term of λ\lambda^{\to} given by [x]:=x[x]:=x, [MN]:=[M][N][MN]:=[M][N], [λx.M]:=λx.[M][\lambda x.M]:=\lambda x.[M], [MX]:=[M][MX]:=[M], [ΛX.M]:=[M][\Lambda X.M]:=[M]. Finally for a type environment Γ\Gamma for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} we define the environment Γ\langle\Gamma\rangle such that dom(Γ):=dom(Γ)dom(\langle\Gamma\rangle):=dom(\Gamma) and Γ(x):=Γ(x)\langle\Gamma\rangle(x):=\langle\Gamma(x)\rangle.

The following lemma is easily proved by induction on the structure of the type.

Lemma 1.

Let AA be an arbitrary type and XX and YY be type variables. Then

X.A=A{Y/X}=A.\langle\forall X.A\rangle~=~\langle A\{Y/X\}\rangle~=~\langle A\rangle.
Theorem 2.

Given a term MM in Polymorphic Curry style, a type environment Γ\Gamma and a type AA in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}},

ifΓ𝐅𝐚𝐭M:AthenΓλ[M]:A.~\textup{if}~\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:A~\textup{then}~\langle\Gamma\rangle~\vdash_{\lambda^{\to}}[M]:~\langle A\rangle.
Proof 2.1.

The proof is done by induction on the complexity of MM. Let MM be a variable xx. Then it is typed with (VAR) Γ𝐅𝐚𝐭x:Γ(x)\Gamma~\vdash_{{\mathbf{F}}_{\mathbf{at}}}x:\Gamma(x) and obviously Γλx:Γ(x)=Γ(x)\langle\Gamma\rangle~\vdash_{\lambda^{\to}}x:~\langle\Gamma\rangle(x)=~\langle\Gamma(x)\rangle. Consider an application Γ𝐅𝐚𝐭MN:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}MN:A. Then Γ𝐅𝐚𝐭M:BA\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:B\rightarrow A and Γ𝐅𝐚𝐭N:B\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}N:B for some BB. By induction hypothesis Γλ[M]:BA\langle\Gamma\rangle~\vdash_{\lambda^{\to}}[M]:~\langle B\rangle\rightarrow\langle A\rangle and Γλ[N]:B\langle\Gamma\rangle~\vdash_{\lambda^{\to}}[N]:~\langle B\rangle hence Γλ[M][N]=[MN]:A\langle\Gamma\rangle~\vdash_{\lambda^{\to}}[M][N]=[MN]:~\langle A\rangle. If we have an abstraction Γ𝐅𝐚𝐭λx.M:AB\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}\lambda x.M:A\rightarrow B then Γ{x:A}𝐅𝐚𝐭M:B\Gamma\cup\{x:A\}\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:B. By induction hypothesis Γ{x:A}λ[M]:B\langle\Gamma\cup\{x:A\}\rangle~\vdash_{\lambda^{\to}}[M]:~\langle B\rangle hence

Γ{x:A}λ[M]:B\langle\Gamma\rangle\cup~\{x:~\langle A\rangle\}\vdash_{\lambda^{\to}}[M]:~\langle B\rangle

Using (ABS) we get

Γλλx.[M]:AB\langle\Gamma\rangle~\vdash_{\lambda^{\to}}\lambda x.[M]:~\langle A\rangle~\rightarrow~\langle B\rangle

Which by definition of [][\cdot] yields

Γλ[λx.M]:AB\langle\Gamma\rangle~\vdash_{\lambda^{\to}}[\lambda x.M]:~\langle A\rightarrow B\rangle

In the case of universal application we have Γ𝐅𝐚𝐭MX:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}MX:A. But then Γ𝐅𝐚𝐭M:Y.A{Y/X}\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:\forall Y.A\{Y/X\}. By induction hypothesis Γλ[M]:Y.A{Y/X}=Lemma1\langle\Gamma\rangle~\vdash_{\lambda^{\to}}[M]:~\langle\forall Y.A\{Y/X\}\rangle~\stackrel{{\scriptstyle\textup{Lemma}~~\ref{subsX1}}}{{=}} A\langle A\rangle and since [MX]=[M][MX]=[M] we get

Γλ[MX]:A.\langle\Gamma\rangle~\vdash_{\lambda^{\to}}[MX]:~\langle A\rangle.

Finally the case of universal abstraction, Γ𝐅𝐚𝐭ΛX.M:X.A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}\Lambda X.M:\forall X.A follows from [ΛX.M]=[M][\Lambda X.M]=[M] and X.A=A\langle\forall X.A\rangle~=~\langle A\rangle and the induction hypothesis for Γ𝐅𝐚𝐭M:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:A.

Corollary 3.

If MM is Curry typable then MM is λ\lambda^{\to} typable.

Proof 2.2.

Immediate by Theorem 2, noticing that being MM a term of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} in Curry style, [M]=M[M]=M.

Note that, given a λ\lambda^{\to}-term, the inverse implication is also valid, not only for the Curry system but for the Polymorphic Curry system.

Corollary 4.

The typability problem is decidable in Curry system 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}.

Proof 2.3.

From the previous note and Corollary 3 we have that Curry typability is equivalent to λ\lambda^{\to} typability and the latter is known to be decidable.

3. Typability for Polymorphic Curry terms

In this section we address the more complex question of typability of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} presented in Polymorphic Curry style.

Let \circ and \bullet be two fixed different type variables in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}.

We define the subsystem 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet} of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} whoses types are given by

A,B:=|AB|.AA,B:=\circ|A\rightarrow B|\forall\bullet.A

and terms by

M,N:=x|MN|λx.M|M|Λ.MM,N:=x|MN|\lambda x.M|M\bullet|\Lambda\bullet.M

The type inference rules for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet} are the same as the ones for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} except for the universal inference rules that are given by

   ΓM:A\Gamma\vdash M:A   (GEN) ΓΛ.M:.A\Gamma\vdash\Lambda\bullet.M:\forall\bullet.A     ΓM:.A\Gamma\vdash M:\forall\bullet.A   (INST) ΓM:A\Gamma\vdash M\bullet:A            

Given a type AA of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} we define [A][A] as the type of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet} given by [X]=[X]=\circ, [AB]=[A][B][A\rightarrow B]=[A]\rightarrow[B] and [X.A]=.[A][\forall X.A]=\forall\bullet.[A]. For a type environment Γ\Gamma for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} we define the type environment [Γ][\Gamma] for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet} such that dom([Γ])=dom(Γ)dom([\Gamma])=dom(\Gamma) and [Γ](x)=[Γ(x)][\Gamma](x)=[\Gamma(x)].

We define a map from the terms of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} to the terms of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet} given by |x|=x|x|=x, |MN|=|M||N||MN|=|M||N|, |λx.M|=λx.|M||\lambda x.M|=\lambda x.|M|, |MX|=|M||MX|=|M|\bullet and |ΛX.M|=Λ.|M||\Lambda X.M|=\Lambda\bullet.|M|.

Analogously to Lemma 1 we have the following result:

Lemma 5.

Let AA be an arbitrary type in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} and XX and YY be type variables. Then [A{Y/X}]=[A][A\{Y/X\}]~=~[A].

3.1. Reduction to 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet}

Proposition 6.

Let MM be a term in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}. If there are a type environment Γ\Gamma and a type AA in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} such that Γ𝐅𝐚𝐭M:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:A then [Γ]𝐅𝐚𝐭|M|:[A][\Gamma]\vdash_{{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}}|M|:[A].

Proof 3.1.

The proof is done by induction on the structure of MM. Let MM be a variable xx. Then it is typed with (VAR) Γ𝐅𝐚𝐭x:Γ(x)\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}x:\Gamma(x) and, since |x|=x|x|=x, obviously [Γ]𝐅𝐚𝐭|x|:[Γ](x)=[Γ(x)][\Gamma]\vdash_{{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}}|x|:[\Gamma](x)=[\Gamma(x)].

Consider an application Γ𝐅𝐚𝐭MN:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}MN:A. Then Γ𝐅𝐚𝐭M:BA\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:B\rightarrow A and Γ𝐅𝐚𝐭N:B\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}N:B for some type BB. By induction hypothesis [Γ]𝐅𝐚𝐭|M|:[BA]=[B][A][\Gamma]\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}|M|:[B\to A]=[B]\rightarrow[A] and [Γ]𝐅𝐚𝐭|N|:[B][\Gamma]\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}|N|:[B] hence, since |MN|=|M||N||MN|=|M||N|, we have [Γ]𝐅𝐚𝐭|MN|:[A][\Gamma]\vdash_{{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}}|MN|:[A].

If we have an abstraction Γ𝐅𝐚𝐭λx.M:AB\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}\lambda x.M:A\rightarrow B then Γ{x:A}𝐅𝐚𝐭M:B\Gamma\cup\{x:A\}\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:B. By induction hypothesis [Γ{x:A}]𝐅𝐚𝐭|M|:[B][\Gamma\cup\{x:A\}]\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}|M|:[B] hence

[Γ]{x:[A]}𝐅𝐚𝐭|M|:[B][\Gamma]\cup\{x:[A]\}\vdash_{{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}}|M|:[B]
[Γ]𝐅𝐚𝐭λx.|M|:[A][B][\Gamma]\vdash_{{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}}\lambda x.|M|:[A]\rightarrow[B]
[Γ]𝐅𝐚𝐭|λx.M|:[AB][\Gamma]\vdash_{{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}}|\lambda x.M|:[A\rightarrow B]

In the case of INST we have Γ𝐅𝐚𝐭MX:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}MX:A. But then Γ𝐅𝐚𝐭M:Y.A{Y/X}\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:\forall Y.A\{Y/X\}. By induction hypothesis [Γ]𝐅𝐚𝐭|M|:[Y.A{Y/X}]=.[A{Y/X}]=Lemma 5.[A][\Gamma]\vdash_{{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}}|M|:[\forall Y.A\{Y/X\}]=\forall\bullet.[A\{Y/X\}]\stackrel{{\scriptstyle\textup{Lemma~\ref{subsX}}}}{{=}}\forall\bullet.[A] and applying |M|=|MX||M|\bullet=|MX| we get

[Γ]𝐅𝐚𝐭|MX|:[A].[\Gamma]\vdash_{{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}}|MX|:[A].

Finally consider the case of (GENX), Γ𝐅𝐚𝐭ΛX.M:A=X.B\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}\Lambda X.M:A=\forall X.B. We have Γ𝐅𝐚𝐭M:B\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:B with XX not belonging to the free type variables in Γ\Gamma. By induction [Γ]𝐅𝐚𝐭|M|:[B][\Gamma]\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}|M|:[B]. Then since \bullet does not belong to the free type variables in [Γ][\Gamma], using (GEN) we get [Γ]𝐅𝐚𝐭Λ.|M|:.[B]=[X.B][\Gamma]\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}\Lambda\bullet.|M|:\forall\bullet.[B]=[\forall X.B]. Since Λ.|M|=|ΛX.M|\Lambda\bullet.|M|=|\Lambda X.M|, the result follows.

Note that we work modulo α\alpha-equivalence for type variables, in particular we assume the name of the bound variables is always appropriately chosen. Since in 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet}, the type variable \bullet does not occur in the scope of any quantifier it is clear that if we substitute occurrences of \bullet in a type AA of 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet} by any type variables other \circ, then we obtain a α\alpha-equivalent type AA^{\prime} in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}.

Lemma 7.

Assume that Γ𝐅𝐚𝐭M:A\Gamma\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}M:A. Let MM^{\prime} be the term of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} which results from substituting some occurrences of subterms of the form Λ.N\Lambda\bullet.N in MM by ΛX.N\Lambda X.N with XX some type variable different from \circ and NN\bullet in MM by NYNY with YY any type variable (different occurrences of the subterms may be replaced using different type variables). Then Γ𝐅𝐚𝐭M:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M^{\prime}:A^{\prime} where AA^{\prime} is α\alpha-equivalent to AA.

Proof 3.2.

The proof is done by induction on the structure of MM.

If MM is an assumption variable xx and Γ𝐅𝐚𝐭x:A\Gamma\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}x:A then x=xx^{\prime}=x and the result follows immediately since Γ𝐅𝐚𝐭x:A\Gamma\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}x:A implies Γ𝐅𝐚𝐭x:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}x:A.

If MM is NSNS and Γ𝐅𝐚𝐭NS:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}}NS:A then it comes from (APP).

Thus we have Γ𝐅𝐚𝐭N:BA\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}}N:B\to A and Γ𝐅𝐚𝐭S:B\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}}S:B for some type BB.

Let us write M=(NS)=NSM^{\prime}=(NS)^{\prime}=N^{\prime}S^{\prime} where NN^{\prime} and SS^{\prime} are the result of applying restrictions of the substitution defining MM^{\prime}. Then by induction hypothesis Γ𝐅𝐚𝐭N:(BA)\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}N^{\prime}:(B\to A)^{\prime} and Γ𝐅𝐚𝐭S:B\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}S^{\prime}:B^{\prime} for some type BB^{\prime} α\alpha-equivalent to BB and some type (BA)(B\to A)^{\prime} α\alpha-equivalent to BAB\to A. Thus (BA)(B\to A)^{\prime} is of the form CDC\to D where CC is α\alpha-equivalent to BB, and thus α\alpha- equivalent to BB^{\prime}, and DD is α\alpha-equivalent to AA. Applying (APP) we obtain Γ𝐅𝐚𝐭NS=(NS):D\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}N^{\prime}S^{\prime}=(NS)^{\prime}:D with DD α\alpha-equivalent to AA.

If MM is λx.N\lambda x.N then Γ𝐅𝐚𝐭λx.N:AB\Gamma\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}\lambda x.N:A\to B which comes from (ABS) and we have Γ{x:A}𝐅𝐚𝐭N:B\Gamma\cup\{x:A\}\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}N:B. Let us write M=λx.NM^{\prime}=\lambda x.N^{\prime}. Then by induction hypothesis Γ{x:A}𝐅𝐚𝐭N:B\Gamma\cup\{x:A\}\vdash_{{\mathbf{F}}_{\mathbf{at}}}N^{\prime}:B^{\prime} with BB^{\prime} α\alpha-equivalent to BB. But using (ABS) we obtain Γ𝐅𝐚𝐭λx.N:AB\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}\lambda x.N^{\prime}:A\to B^{\prime}. Then the result follows since M=λx.NM^{\prime}=\lambda x.N^{\prime} and ABA\to B^{\prime} is α\alpha-equivalent to ABA\to B.

If MM is NN\bullet then Γ𝐅𝐚𝐭N:A\Gamma\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}N\bullet:A comes from (INST) and we have Γ𝐅𝐚𝐭N:.A\Gamma\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}N:\forall\bullet.A.

Let M=NXM^{\prime}=N^{\prime}X (where XX may be \bullet). By induction hypothesis Γ𝐅𝐚𝐭N:(.A)\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}N^{\prime}:(\forall\bullet.A)^{\prime} where (.A)(\forall\bullet.A)^{\prime} is α\alpha-equivalent to .A\forall\bullet.A. If we write (.A)=Y.B(\forall\bullet.A)^{\prime}=\forall Y.B (where YY can be \bullet) then it is clear that BB must be α\alpha-equivalent to AA. Applying (INST) for XX yields Γ𝐅𝐚𝐭NX:B\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}N^{\prime}X:B since YY is not free in BB. The result then follows, since M=NXM^{\prime}=N^{\prime}X and BB is α\alpha-equivalent to AA.

If MM is Λ.N\Lambda\bullet.N then Γ𝐅𝐚𝐭Λ.N:.A\Gamma\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}\Lambda\bullet.N:\forall\bullet.A comes from (GEN) and we have Γ𝐅𝐚𝐭N:A\Gamma\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}N:A. Let us write M=ΛX.NM^{\prime}=\Lambda X.N^{\prime} where XX can be \bullet but not \circ. By induction hypothesis Γ𝐅𝐚𝐭N:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}N^{\prime}:A^{\prime} with AA^{\prime} α\alpha-equivalent to AA. Applying (GENX) (since the proviso is trivially satisfied) yields Γ𝐅𝐚𝐭ΛX.N:X.A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}\Lambda X.N^{\prime}:\forall X.A^{\prime}. The result then follows since X.A\forall X.A^{\prime} is α\alpha-equivalent to .A\forall\bullet.A.

Corollary 8.

Given a Polymorphic Curry-term MM, if |M||M| is typable in 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet} then MM is typable in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}.

Proof 3.3.

Let MM be a term in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} which does not contain a subterm of the form Λ.N\Lambda\circ.N. Then MM results from |M||M| by a substitution process as in Lemma 7 and the result follows. Let MM be a term in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} which contains a subterm of the form Λ.N\Lambda\circ.N. Note that the typability of a term in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} does not change if we rename all the type variables appearing in the term. Thus renaming \circ to a fresh type variable the result follows as above.

Hence combining Proposition 6 and Corollary 8 we get

Theorem 9.

A Polymorphic Curry-term MM is typable in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} if and only if |M||M| is typable in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}.

3.2. Typability in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}

In what follows we work in 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet}.

We define the set 𝕊\mathbb{S} of type schemes by

σ,τ:=α|στ|.σ\sigma,\tau:=\alpha|\sigma\rightarrow\tau|\forall\bullet.\sigma

where α\alpha is a type scheme variable.

A generalised environment is a finite set of elements of the form x:σx:\sigma, where xx is an assumption variable and σ\sigma is a type scheme. Unlike in the usual environments xx may occur more than once.

By a multisystem we mean a finite set11 1 Or equivalently a finite sequence. {e1,,ek}\{e_{1},\ldots,e_{k}\} such that each eie_{i} is a multiequation22 2 We consider equality between type schemes as usual for types. a1==aja_{1}=\cdots=a_{j} with the aia_{i} in 𝕊\mathbb{S}. Given a generalised environment DD we get a multisystem D~\tilde{D} in the following way: let D[x]D[x] be the set of all elements σi\sigma_{i} in 𝕊\mathbb{S} such that x:σiDx:\sigma_{i}\in D. Then we form the multiequation σ1==σk\sigma_{1}=\cdots=\sigma_{k} where the σi\sigma_{i} are all the elements in D[x]D[x]. The multisystem D~\tilde{D} is defined by taking the union of such multiequations for all xx in the domain of DD.

Let MM be a term of 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet}. Assume w.l.o.g. that MM is in Barendregt form, that is, the names of all the bound assumption variables are chosen to be distinct between themselves as well as distinct from the free assumption variables33 3 For example the term M=(λx.x)(λx.x)M=(\lambda x.x)(\lambda x.x) is to be presented in the form (λx.x)(λy.y)(\lambda x.x)(\lambda y.y) for yy an assumption variable distinct from xx. The subterms λx.x\lambda x.x and λy.y\lambda y.y are considered distinct. . A tagging 𝒜\mathcal{A} for MM is a map which assigns subterms and bound assumption variables44 4 The bound variables are needed in the definition because in terms like M:=λx.yzM:=\lambda x.yz, we want to have tags not just for the subterms yy, zz, yzyz and MM but also for xx. of MM to type scheme variables in such a way that distinct subterms/bound variables are assigned distinct type scheme variables. We denote the image of the tagging of a subterm/bound variable NN by 𝒜(N)\mathcal{A}(N). Here we are using strict (typographical) equality of subterms.

{defi}

Let MM be a term of 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet} and 𝒜\mathcal{A} a tagging for MM. The associated multisystem of MM is the set {eN}N𝒯\{e_{N}\}_{N\in\mathcal{T}} where 𝒯\mathcal{T} is the set of subterms of MM which are not assumption variables and eNe_{N} are multiequations defined as follows:

  • if N:=SPN:=SP, 𝒜(N)=α1\mathcal{A}(N)=\alpha_{1}, 𝒜(S)=α2\mathcal{A}(S)=\alpha_{2} and 𝒜(P)=α3\mathcal{A}(P)=\alpha_{3} then eNe_{N} is α2=α3α1\alpha_{2}=\alpha_{3}\to\alpha_{1}

  • if N:=λx.SN:=\lambda x.S, 𝒜(N)=α1\mathcal{A}(N)=\alpha_{1}, 𝒜(x)=α2\mathcal{A}(x)=\alpha_{2} and 𝒜(S)=α3\mathcal{A}(S)=\alpha_{3} then eNe_{N} is α1=α2α3\alpha_{1}=\alpha_{2}\to\alpha_{3}

  • if N:=SN:=S\bullet, 𝒜(N)=α1\mathcal{A}(N)=\alpha_{1} and 𝒜(S)=α2\mathcal{A}(S)=\alpha_{2} then eNe_{N} is α2=.α1\alpha_{2}=\forall\bullet.\alpha_{1}

  • if N:=Λ.SN:=\Lambda\bullet.S, 𝒜(N)=α1\mathcal{A}(N)=\alpha_{1} and 𝒜(S)=α2\mathcal{A}(S)=\alpha_{2} then eNe_{N} is α1=.α2\alpha_{1}=\forall\bullet.\alpha_{2}

Lemma 10.

Let MM be a term in 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet} such that Γ𝐅𝐚𝐭M:A\Gamma\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}M:A and let \mathcal{M} be an associated multisystem of MM. Then it is possible to replace each type scheme variable in \mathcal{M} by a type in 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet} in such a way that the multiequations in \mathcal{M} hold.

Proof 3.4.

Suppose that Γ𝐅𝐚𝐭M:A\Gamma\vdash_{\mathbf{F}_{\mathbf{at}}^{\circ\bullet}}M:A. Then Γ\Gamma defines a typing for each subterm/bounded variable NN of MM, which we denote by (N)\mathcal{B}(N). Let 𝒜\mathcal{A} be a tagging for MM and \mathcal{M} be its associated multisystem. Let us prove that replacing the type scheme variables α=𝒜(N)\alpha=\mathcal{A}(N) occurring in \mathcal{M} by (N)\mathcal{B}(N) the multiequations (on 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet} types) hold.

Let ee be a multiequation in \mathcal{M}.

  • If ee is of the form α1=α2α3\alpha_{1}=\alpha_{2}\to\alpha_{3} then two situations may occur: i) there are terms SS and PP such that α1=𝒜(S)\alpha_{1}=\mathcal{A}(S), α2=𝒜(P)\alpha_{2}=\mathcal{A}(P) and α3=𝒜(SP)\alpha_{3}=\mathcal{A}(SP) or ii) there are terms xx and SS such that α2=𝒜(x)\alpha_{2}=\mathcal{A}(x), α3=𝒜(S)\alpha_{3}=\mathcal{A}(S) and α1=𝒜(λx.S)\alpha_{1}=\mathcal{A}(\lambda x.S). In case i), after the replacement, we obtain the (S)=(P)(SP)\mathcal{B}(S)=\mathcal{B}(P)\to\mathcal{B}(SP) and in case ii) we obtain (λx.S)=(x)(S)\mathcal{B}(\lambda x.S)=\mathcal{B}(x)\to\mathcal{B}(S). Hence the equations hold.

  • If ee is of the form α1=.α2\alpha_{1}=\forall\bullet.\alpha_{2} then two situations may occurs: i) there is a term SS such that α1=𝒜(S)\alpha_{1}=\mathcal{A}(S) and α2=𝒜(S)\alpha_{2}=\mathcal{A}(S\bullet) or ii) there is a term SS such that α1=𝒜(Λ.S)\alpha_{1}=\mathcal{A}(\Lambda\bullet.S) and α2=𝒜(S)\alpha_{2}=\mathcal{A}(S). In case i), after the replacement, we obtain the (S)=.(S)\mathcal{B}(S)=\forall\bullet.\mathcal{B}(S\bullet) and in case ii) we obtain (Λ.S)=.(S)\mathcal{B}(\Lambda\bullet.S)=\forall\bullet.\mathcal{B}(S). Hence the equations hold.

In general given a term MM and a tagging 𝒜\mathcal{A}, a solution to the associated multisystem E:={eN}N𝒯E:=\{e_{N}\}_{N\in\mathcal{T}} is an assignment ff of types of 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet} to the type scheme variables in EE such that the resulting set of multiequations (now in 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet}) hold.

Given a multiequation ee we denote by e[i]e[i] the iith element counting from the left. We denote by ee[i]e\setminus e[i] the multiequation which results from eliminating the iith term from ee: if ee is σ1==σi==σn\sigma_{1}=\cdots=\sigma_{i}=\cdots=\sigma_{n} then ee[i]e\setminus e[i] is σ1==σi1=σi+1==σn\sigma_{1}=\cdots=\sigma_{i-1}=\sigma_{i+1}=\cdots=\sigma_{n}. If ee is a single equation, ee[i]e\setminus e[i] consists in eliminating the equation ee. Given two multiequations e1e_{1} and e2e_{2} we denote by e1.e2e_{1}.e_{2} the result of concatenating the two multiequations into a single multiequation in the expected way.

We consider the following rules to transform (reduce) a multisystem FF.

EE   ee   ee^{\prime}   Eee[i].eE\quad e\setminus e[i].e^{\prime} (Joini,j), if e[i]=e[j]e[i]=e^{\prime}[j]

     EE   ee   Eee[i]σ=τσ=τE\quad e\setminus e[i]\quad\sigma=\tau\quad\sigma^{\prime}=\tau^{\prime} (Arri,j), if e[i]=σσe[i]=\sigma\rightarrow\sigma^{\prime} and e[j]=ττe[j]=\tau\rightarrow\tau^{\prime}, iji\neq j

   EE   ee   Eee[i]σ=τE\quad e\setminus e[i]\quad\sigma=\tau (Quanti,j), if e[i]=.σe[i]=\forall\bullet.\sigma and e[j]=.τe[j]=\forall\bullet.\tau, iji\neq j

where EE are the other multiequations in the multisystem FF.

Remark 11.

Let EE be a multisystem whose multiequations hold for a particular substitution of type scheme variables by types in 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet}. By applying the rules above, the multisystem EE^{\prime} obtained from EE is such that its multiequations still hold under the same substitution.

{defi}

Given a multisystem EE, a reduction sequence is a sequence of applications of the above rules. A multisystem is called irreducible if it is no longer possible to apply a rule to it. By a clash we mean a multiequation that contains type schemes both of the form σσ\sigma\rightarrow\sigma^{\prime} and .σ\forall\bullet.\sigma.

The following observation is immediate:

Lemma 12.

The rules (considered in both directions) are sound. More precisely, for any substitution of the type scheme variables for types of 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet} the rules are sound for the standard notion of type equality.

{defi}

The length of a type scheme is defined inductively as follows:

  • l(α)=1l(\alpha)=1

  • l(στ)=l(σ)+l(τ)+1l(\sigma\to\tau)=l(\sigma)+l(\tau)+1

  • l(.τ)=l(τ)+1l(\forall\bullet.\tau)=l(\tau)+1

Lemma 13.

All reduction sequences of a multisystem are finite.

Proof 3.5.

Given a multisystem EE we consider the sequence σ1,,σk\sigma_{1},\ldots,\sigma_{k} of all the type schemes which appear in all the multiequations of EE with any order. Take the length of these type schemes to obtain a sequence of natural numbers n1,,nkn_{1},\ldots,n_{k}. We denote this sequence by l(E)l(E). Consider the effect of the rules on the sequences l(E)l(E). (Joinij) simply removes an element from the sequence. (Arri,j) replaces an element nkn_{k} with four natural numbers m,o,p,q<nkm,o,p,q<n_{k} and (Quanti,j) replaces an element nkn_{k} with two natural numbers m,p<nkm,p<n_{k}. Thus reductions starting from a sequence σ1,,σk\sigma_{1},\ldots,\sigma_{k} terminate in at most 4n1++4nk4^{n_{1}}+\cdots+4^{n_{k}} steps.

Remark 14.

A multiequation of an irreducible multisystem contains at most one type scheme of the form στ\sigma\to\tau and at most one type scheme of the form .σ\forall\bullet.\sigma.

{defi}

A resolution of a term MM is an irreducible multisystem without clashes obtained by reducing the associated multisystem of MM.

It is immediate that a resolution of a term MM only contains multiequations of the following three forms (modulo permutations of the order):

  • 1)

    α1==αn\alpha_{1}=\cdots=\alpha_{n}

  • 2)

    α1==αn=.σ\alpha_{1}=\cdots=\alpha_{n}=\forall\bullet.\sigma

  • 3)

    α1==αn=στ\alpha_{1}=\cdots=\alpha_{n}=\sigma\to\tau

For 2) and 3) above, we call the multisystems α1==αn\alpha_{1}=\cdots=\alpha_{n} the body and .σ\forall\bullet.\sigma and στ\sigma\to\tau the head. We also refer to multisystems of type 1) as bodies.

{defi}

Given a resolution EE of a term MM, its minimisation is constructed as follows: choose a single type scheme variable from each multiequation of type 1) and from each body of multiequations of types 2) and 3). We say that these chosen type scheme variables are associated to their respective bodies. Then discard all type scheme variables in the bodies of the multiequations except for the previously selected type scheme variables. Let α\alpha be a scheme variable occurring in a head of a multiequation ee. If α\alpha occurs in the body of some multiequation, then we replace it in ee by the type scheme variable associated to that body.

{defi}

Let EE be the minimisation of a resolution of a term MM. Its associated digraph G(M)G(M) is constructed as follows. Its vertices are the type scheme variables that appear in EE and we have a directed edge (α1,α2)(\alpha_{1},\alpha_{2}) whenever there is a multiequation ee in EE such that α2\alpha_{2} is in its body and α1\alpha_{1} is in its head.

We illustrate the previous concepts with an example.

Consider the term Λ.((Λ.x1))(λx1.(x0(Λ.x2)))\Lambda\bullet.((\Lambda\bullet.x_{1})\bullet)(\lambda x_{1}.(x_{0}(\Lambda\bullet.x_{2}))). We tag the subterms and bound assumption variables:

Λ.((Λ.x1))(λx1.(x0(Λ.x2))):α0\Lambda\bullet.((\Lambda\bullet.x_{1})\bullet)(\lambda x_{1}.(x_{0}(\Lambda\bullet.x_{2}))):\alpha_{0}

((Λ.x1))(λx1.(x0(Λ.x2))):α1((\Lambda\bullet.x_{1})\bullet)(\lambda x_{1}.(x_{0}(\Lambda\bullet.x_{2}))):\alpha_{1}

((Λ.x1)):α2((\Lambda\bullet.x_{1})\bullet):\alpha_{2}

λx1.(x0(Λ.x2)):α3\lambda x_{1}.(x_{0}(\Lambda\bullet.x_{2})):\alpha_{3}

Λ.x1:α4\Lambda\bullet.x_{1}:\alpha_{4}

x0(Λ.x2):α5x_{0}(\Lambda\bullet.x_{2}):\alpha_{5}

Λ.x2:α6\Lambda\bullet.x_{2}:\alpha_{6}

x1:α7x_{1}:\alpha_{7}

x0:α8x_{0}:\alpha_{8}

x2:α9x_{2}:\alpha_{9}

The associated multisystem consists of the equations:

α0=.α1\alpha_{0}=\forall\bullet.\alpha_{1}

α2=α3α1\alpha_{2}=\alpha_{3}\rightarrow\alpha_{1}

α4=.α2\alpha_{4}=\forall\bullet.\alpha_{2}

α3=α7α5\alpha_{3}=\alpha_{7}\rightarrow\alpha_{5}

α8=α6α5\alpha_{8}=\alpha_{6}\rightarrow\alpha_{5}

α6=.α9\alpha_{6}=\forall\bullet.\alpha_{9}

α4=.α7\alpha_{4}=\forall\bullet.\alpha_{7}

Applying the rules we get the irreducible multisystem:

α0=.α1\alpha_{0}=\forall\bullet.\alpha_{1}

α4=.α2\alpha_{4}=\forall\bullet.\alpha_{2}

α7=α2=α3α1\alpha_{7}=\alpha_{2}=\alpha_{3}\rightarrow\alpha_{1}

α3=α7α5\alpha_{3}=\alpha_{7}\rightarrow\alpha_{5}

α8=α6α5\alpha_{8}=\alpha_{6}\rightarrow\alpha_{5}

α6=.α9\alpha_{6}=\forall\bullet.\alpha_{9}

Applying minimisation yields:

α0=.α1\alpha_{0}=\forall\bullet.\alpha_{1}

α4=.α2\alpha_{4}=\forall\bullet.\alpha_{2}

α2=α3α1\alpha_{2}=\alpha_{3}\rightarrow\alpha_{1}

α3=α2α5\alpha_{3}=\alpha_{2}\rightarrow\alpha_{5}

α8=α6α5\alpha_{8}=\alpha_{6}\rightarrow\alpha_{5}

α6=.α9\alpha_{6}=\forall\bullet.\alpha_{9}

There are no clashes. The associated graph has vertices

V={α0,α1,α2,α3,α4,α5,α6,α8,α9}V=\{\alpha_{0},\alpha_{1},\alpha_{2},\alpha_{3},\alpha_{4},\alpha_{5},\alpha_{6},\alpha_{8},\alpha_{9}\}

and directed edges

E={(α0,α1),(α4,α2),(α2,α1),(α2,α3),(α3,α2),(α3,α5),(α8,α6),(α8,α5),(α6,α9)}.E=\{(\alpha_{0},\alpha_{1}),(\alpha_{4},\alpha_{2}),(\alpha_{2},\alpha_{1}),(\alpha_{2},\alpha_{3}),(\alpha_{3},\alpha_{2}),(\alpha_{3},\alpha_{5}),(\alpha_{8},\alpha_{6}),(\alpha_{8},\alpha_{5}),(\alpha_{6},\alpha_{9})\}.
Lemma 15.

A term MM is typable in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet} if and only if it has a resolution with an associated digraph not containing a cycle.

Proof 3.6.

Let MM be typable in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}^{\circ\bullet}. By Lemma 10 and Remark 11 we have that MM has a resolution. Also, it cannot contain a cycle for this would imply an impossible condition on the possible types of subterms of MM. On the other hand if MM has a resolution and its associated digraph G(M)G(M) does not contain a cycle then we obtain a typing for MM as follows. We tag the terminal vertices (those with no paths leaving them) of G(M)G(M) with \circ. Since there are no cycles we can tag the rest of the vertices inductively as follows. Assume that the descendants of a vertex α\alpha have already been tagged. If it has two descendants α1\alpha_{1} and α2\alpha_{2} tagged with AA and BB then we tag α\alpha with ABA\rightarrow B. If it has a single descendant β\beta tagged with AA then we tag it with .A\forall\bullet.A. It is easy to see by the construction of the associated graph that these are the only two possible situations. Each vertex of the associated digraph is also associated to a body in the resolution of MM. Substitute all type schemes in the body by the new type associated to the vertex. With this substitution the multiequations of the resolution continue to hold. Substituting these new values in a (x:σ)(x:\sigma) of the inferred typing of MM for each xx yields an environment rendering MM typable in 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet}.

Since it is decidable if a term MM has a resolution and whether its associated digraph has a cycle we get that:

Lemma 16.

Typability in 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet} is decidable.

Hence, combining the previous lemma with Theorem 9 yields:

Theorem 17.

Typability for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} in Polymorphic Curry style is decidable.

The proof of Lemma 15 yields a method of type inference for 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet} similar to the case of simply typed calculus [Rém02][1.4.3]. The proof of Corollary 8 allow us to extend such type inference strategy to a method of type inference for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} restricted to redundant typings.

4. Non-redundant Typability

A natural question arises: when is a term MM of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} typable with non-redundant quantifiers? For example, if a term MM contains subterms N(xX)N(xX) and N(xY)N(xY), where xx is the same free or bound assumption variable (after imposing the Barendregt condition), then the type of xx must be of the form Z.A\forall Z.A and the types of xXxX and xYxY must be equal. The type of xXxX is A[X/Z]A[X/Z] and the type of xYxY is A[Y/Z]A[Y/Z]. Thus ZZ cannot occur in AA and we see that Z\forall Z is redundant.

We have seen by Corollary 2.3 that typable Curry terms coincide with the typable terms of λ\lambda^{\rightarrow}. If a term MM has a derivation yielding a typing ΓM:A\Gamma\vdash M:A in which all the quantifiers in Γ\Gamma and AA are redundant then by lemma 3.11 of [Wel99] (which carries over from 𝐅\mathbf{F} to 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}) MM has a derivation yielding a typing ΓM:A\Gamma^{\prime}\vdash M:A^{\prime} in which all the redundant quantifiers in Γ\Gamma and AA have been eliminated, that is, we obtain canonically a derivation in λ\lambda^{\rightarrow}. Clearly non-redundancy is very relevant for a meaningful notion of type inference in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}. A major advantage of the Polymorphic Curry style presentation of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} is that the second-order information present in the terms allows us to impose fine-grained non-redundancy conditions in the procedure for type inference.

In this Section we consider 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} in Polymorphic Curry style.

{defi}

Given a term MM in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} typable with a type environment Γ\Gamma, we say that it is a non-redundant typing if for any subterm of MM of the form NXNX or ΛX.N\Lambda X.N if we consider the induced typings55 5 Given a typing ΓM:A\Gamma\vdash M:A and a subterm NN of MM there is a uniquely determined type environment Γ\Gamma^{\prime} and type BB such that ΓN:B\Gamma^{\prime}\vdash N:B. We call this the induced typing on NN by ΓM:A\Gamma\vdash M:A. ΓN:Y.B\Gamma^{\prime}\vdash N:\forall Y.B in the first case or ΓN:B\Gamma^{\prime}\vdash N:B in the second, then YY occurs free in BB in the first case or XX occurs free in BB in the second.

Non-redundancy involves imposing a set of positive constraints relative to variable occurrences for the types of certain subterms (which we call polymorphic subterms). We can discard these constraints partially (i.e. only impose them on a subset of such subterms) or totally without losing typability. Typability in general requires only a set of negative constraints imposed by the proviso of rule (GENX). In this section we will address the problem of typability in the setting of positive constraints on a choice of polymorphic subterms which includes both the (empty) case corresponding to general typability and the case of non-redundancy above. Given a selection cc of occurrences of polymorphic subterms of a term MM we call a typing of MM which satisfies the positive constraints on these subterms cc-non-redundant.

We now define the set 𝕊\mathbb{S}^{\prime} of type schemes by

σ,τ:=α|σ[X/Y]|στ|X.σ\sigma,\tau:=\alpha|\sigma[X/Y]|\sigma\rightarrow\tau|\forall X.\sigma

where α\alpha is a type scheme variable and XX and YY are type variables of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}. Type schemes of the form αs\alpha s where ss is a (possibly empty) string of expressions of the form [X/Y][X/Y] are called variants of α\alpha. If a type scheme is not a variant of an α\alpha then it is called complex. We also write α[X1/Y1][Xn/Yn]\alpha[X_{1}/Y_{1}]...[X_{n}/Y_{n}] as α[X1Xn/Y1Yn]\alpha[X_{1}...X_{n}/Y_{1}...Y_{n}] or α[X¯/Y¯]\alpha[\bar{X}/\bar{Y}].

We consider that (στ)[X/Y]=σ[X/Y]τ[X/Y](\sigma\rightarrow\tau)[X/Y]=\sigma[X/Y]\rightarrow\tau[X/Y] and (Z.σ)[X/Y]=Z.σ[X/Y](\forall Z.\sigma)[X/Y]=\forall Z.\sigma[X/Y] (for XX and YY distinct from ZZ) and (Z.σ)[X/Z]=Z.σ(\forall Z.\sigma)[X/Z]=\forall Z.\sigma.

If X,Y,Z,WX,Y,Z,W are distinct type variables we consider that σ[X/Y][Z/W]=σ[Z/W][X/Y]\sigma[X/Y][Z/W]=\sigma[Z/W][X/Y]. Also we consider that σ[Y/X][W/X]=σ[Y/X]\sigma[Y/X][W/X]=\sigma[Y/X] and σ[X/X]=σ\sigma[X/X]=\sigma.

We define a generalised environment as previously. A multisystem is also defined as previously.

Given a term MM in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}, we define a tagging 𝒜\mathcal{A} exactly as before. We also have a variable tagging 𝒱\mathcal{V} which assigns to each occurrence of a subterm of the form NXNX or ΛX.N\Lambda X.N of MM a new type variable YY. We denote the value of 𝒱\mathcal{V} sometimes by XNXX_{NX} or XΛX.NX_{\Lambda X.N} when there is only one occurrence. We also use the notation NX:αNX:\alpha for α=𝒜(NX)\alpha=\mathcal{A}(NX). The associated multisystem is defined as F{eN}N𝒯F\cup\{e_{N}\}_{N\in\mathcal{T}} where 𝒯\mathcal{T} is the set of occurrences of subterms of MM which are not assumption variables and FF is as described below. When NN is an occurrence of an arrow application or an arrow abstraction eNe_{N} is defined as in the previous section (note that occurrences of the same subterm of this form give rise to the same multiequations). In the case of an occurrence of a subterm of the form NXNX we have that eNXe_{NX} is

α1=α2W[X/W]\alpha_{1}=\alpha_{2}^{W}[X/W]

where α1=𝒜(NX)\alpha_{1}=\mathcal{A}(NX), α2=𝒜(N)\alpha_{2}=\mathcal{A}(N), W=𝒱(NX)W=\mathcal{V}(NX) and α2W\alpha_{2}^{W} is a fresh type scheme variable identified uniquely by α2\alpha_{2} and WW. Also eΛX.Ne_{\Lambda X.N} is

α1=W.α2[W/X]\alpha_{1}=\forall W.\alpha_{2}[W/X]

where α1=𝒜(ΛX.N)\alpha_{1}=\mathcal{A}(\Lambda X.N), α2=𝒜(N)\alpha_{2}=\mathcal{A}(N) and W=𝒱(ΛX.N)W=\mathcal{V}(\Lambda X.N).

Finally FF consists of equations α=W.αW\alpha=\forall W.\alpha^{W} for all occurences of subterms of MM of the form NXNX, where α=𝒜(N)\alpha=\mathcal{A}(N) and WW is the value of 𝒱\mathcal{V} for each occurrence of the subterm.

Given a term MM and taggings 𝒜\mathcal{A} and 𝒱\mathcal{V} we define a solution to the associated multisystem F{eN}N𝒯F\cup\{e_{N}\}_{N\in\mathcal{T}} exactly as before.

We consider a binary predicate Occ(X,σ)Occ(X,\sigma) over the sorts of type variables and type scheme variables which will be interpreted as meaning that XX must occur free in the assignment of σ\sigma for any solution of the associated multisystem.

We associate to a term MM a set of formulas (M)\mathcal{B}(M) (called basic constraints) in the following way: for all subterms of MM of the form ΛX.S\Lambda X.S we add

αi¬Occ(X,αi)\bigwedge_{\alpha_{i}}\neg Occ(X,\alpha_{i})

where αi=𝒜(x)\alpha_{i}=\mathcal{A}(x) for the free assumption variables xx in SS. Note that these are the constraints required for typability in general.

Given a selection cc for a term MM we define a set 𝒦c(M)\mathcal{K}_{c}(M) which includes (M)\mathcal{B}(M) and a possibly empty set of positive constraints constructed as follows: for subterms of MM chosen by cc of the form ΛX.S\Lambda X.S we add

Occ(X,𝒜(S))Occ(X,\mathcal{A}(S))

and for subterms of MM chosen by cc of the form NXNX we add

Occ(W,αW)Occ(W,\alpha^{W})

with α=𝒜(N)\alpha=\mathcal{A}(N) and WW is the value of 𝒱\mathcal{V} for that occurrence of the subterm.

Note that Occ(X,𝒜(S))Occ(X,\mathcal{A}(S)) implies that Occ(W,𝒜(S)[W/X])Occ(W,\mathcal{A}(S)[W/X]) where W=𝒱(ΛX.S)W=\mathcal{V}(\Lambda X.S).

For other properties of substitution and the occurrence predicate (which will be used in the proofs ahead) see the occurrence axioms listed at the beginning of Section 4.1.

Note that if we consider the term M=λxy.y(I(xX))(I(xY))M=\lambda xy.y(I(xX))(I(xY)) where I=λz.zI=\lambda z.z then by the definition of tagging we must first ensure that the bound variables are all distinct. Thus the second occurrence of the subterm II would become I=λw.wI^{\prime}=\lambda w.w where ww is an assumption variable distinct from zz. We also take occasion to note that it can happen that for a term NN with a redundant typing ΓN:A\Gamma\vdash N:A we can still have that AA does not contain any redundant quantifiers.

When we write σ[X/Y]\sigma[X/Y] we are assuming that σ\sigma represents a possible type AA in which XX is free for YY in AA. We call such values of σ\sigma adequate for [X/Y][X/Y]. For a sequence of substitutions σs\sigma s we define AA being adequate to ss inductively. If ss is a single substitution then the definition is as previously. Otherwise let s=s[Y/X]s=s^{\prime}[Y/X]. Then a type AA is adequate for ss if AsAs^{\prime} is adequate for [Y/X][Y/X].

A partial substitution {X/Y}\{X/Y\} is formally given by two type variables XX and YY and a strictly increasing (possibly empty) sequence of natural numbers n1,,nkn_{1},\ldots,n_{k}. The interpretation is as follows. We consider the sequence of all the free occurrences of YY as they occur from the left. Then the free occurrences of YY in positions n1,,nkn_{1},\ldots,n_{k} in that sequence are substituted by XX. Obviously such a partial substitution can only be applied to types that have at least nkn_{k} free occurrences of YY.

We thus can extend the notion of adequacy to partial substitutions {Y/X}\{Y/X\} and to partial substitution sequences ss.

Note that if B=A[X/Y]B=A[X/Y] with AA adequate for [X/Y][X/Y] then A=B{Y/X}A=B\{Y/X\} for some partial substitution {Y/X}\{Y/X\} with YY free for XX in BB for the occurrences of XX which are substituted. If A=BsA=Bs then B=A𝔰B=A\mathfrak{s} where 𝔰\mathfrak{s} is some sequence of partial substitutions involving the variables in ss. We can always assume that ss represents a simultaneous substitution and likewise for 𝔰\mathfrak{s}.

Since a term has a cc-non-redundant typing if and only if it has a cc-non-redundant typing in which all the bound variables are distinct and different from the type variables that appear in the term (and if we need to rename a bound variable we can do this in such a way that this situation is preserved) we may assume that the solutions (type values) we are considering are adequate for the substitutions that appear in the associated multisystem.

Lemma 18.

Let MM be a term in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} such that Γ𝐅𝐚𝐭M:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:A is a cc-non-redundant typing and let \mathcal{M} be its associated multisystem for a given 𝒜\mathcal{A} and 𝒱\mathcal{V}. Then we can replace each type scheme variable in \mathcal{M} by a type in such a way that the multiequations in \mathcal{M} hold as well as the corresponding constraints 𝒦c(M)\mathcal{K}_{c}(M).

Proof 4.1.

This is shown in the same way as in Lemma 10. We need only consider two further cases. Consider a cc-non-redundant typing Γ\Gamma for MM and let ΓNX:A\Gamma\vdash NX:A and ΓN:B\Gamma\vdash N:B for a subterm NXNX of MM. Consider a given occurrence of NXNX with WW the value of 𝒱\mathcal{V} for that occurrence. Let α=𝒜(NX)\alpha=\mathcal{A}(NX) and β=𝒜(N)\beta=\mathcal{A}(N). Now BB must be of the form Y.C\forall Y.C and we have by (INST) that A=C[X/Y]A=C[X/Y]. Renaming the bound variable YY to WW (we can assume that there are no variable clashes) we get that B=W.C[W/Y]B=\forall W.C[W/Y]. Hence A=C[X/Y]=C[W/Y][X/W]A=C[X/Y]=C[W/Y][X/W]. Hence we put βW=C[W/Y]\beta^{W}=C[W/Y] and the equation α=βW[X/W]\alpha=\beta^{W}[X/W] holds. And also β=W.βW\beta=\forall W.\beta^{W}. The other case is similar. That the constraints hold follows from the definition of cc — non-redundancy.

Given a multiequation ee we denote by e[X¯/Y¯]e[\bar{X}/\bar{Y}] the multiequation for which

e[X¯/Y¯][i]=e[i][X¯/Y¯]e[\bar{X}/\bar{Y}][i]=e[i][\bar{X}/\bar{Y}]

Given a term MM with a variable tagging 𝒱\mathcal{V} we denote by \circ a type variable which does not occur among the variables in the substitutions of the associated multisystem of MM. Let W¯\bar{W} be the sequence of all such variables and consider the substitution sequence [/W¯][\circ/\bar{W}]. Then for any substitution ss involving variables of W¯\bar{W} we have that As[/W¯]=A[/W¯]As[\circ/\bar{W}]=A[\circ/\bar{W}]. Here, when considering AA as part of the solution to the associated multisystem, without loss of generality we can assume that the types AA never contain \circ either as a free or bound variable. Given MM and 𝒱\mathcal{V} we use the notation =[/W¯]\bigcirc=[\circ/\bar{W}].

We consider the following rules to transform a multisystem FF. We have (Arri,j) as in the previous section. In addition, we have the following two rules:

       EE   ee   Eee[i]σ=τ[X/Y]τ=σ[Y/X]E\kern 5.0pte\setminus e[i]\kern 5.0pt\sigma=\tau[X/Y]\kern 5.0pt\tau=\sigma[Y/X] (Quanti,j), e[i]=X.σe[i]=\forall X.\sigma, e[j]=Y.τe[j]=\forall Y.\tau, iji\neq j

  EE   ee   ee^{\prime}   E(ee[i]).eE\quad(e\setminus e[i])\bigcirc.e^{\prime}\bigcirc (Joini,j), e[i]=αse[i]=\alpha s, e[j]=αse^{\prime}[j]=\alpha s^{\prime}

In the above EE are the other multiequations in the multisystem FF. Note that (Arr) and (Quant) are bi-directional.

{defi}

Given a multisystem EE, a reduction sequence is a series of applications of the above rules. A multisystem is called irreducible if it is no longer possible to apply a rule to it.

Remark 19.

We can transform a reduction sequence in the above sense into a reduction sequence in 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet} by applying the translation [][\cdot] of the previous section where αs\alpha s in 𝕊\mathbb{S}^{\prime} is translated via [][\cdot] to α\alpha in 𝕊\mathbb{S}.

This guarantees the existence of an irreducible multisystem for typable terms (see Lemma 13). Alternatively, we can characterise irreducible multisystems as those which translate to irreducible multisystems in 𝐅𝐚𝐭\mathbf{F}_{\mathbf{at}}^{\circ\bullet}.

{defi}

A type scheme variable α\alpha in a multisystem is called terminal if no variant of it can be expressed in terms of complex type schemes with variants of the other type scheme variables in the multisystem. Terminals are organised into groups. Two terminals α\alpha, α\alpha^{\prime} belong to the same group iff αs=αs\alpha s=\alpha^{\prime}s^{\prime} for some s,ss,s^{\prime}.

Note that the reduction rules are sound for the standard notion of equality and the terminals are preserved by reduction.

Remark 20.

To obtain a solution to a multisystem it is not enough to give values to the terminal scheme variables. The type structure of the non-terminals is, however, determined once we have the value of the terminals, as is easily seen by Remark 19.

What happens is that the free variables of the non-terminals are not uniquely determined by the terminals. For example, consider the multisystem associated to the term (xX)y(xX)y. Let (xX)y:α1(xX)y:\alpha_{1}, y:α2y:\alpha_{2}, xX:α3xX:\alpha_{3} and x:α4x:\alpha_{4}. The associated multisystem contains α3=α2α1\alpha_{3}=\alpha_{2}\rightarrow\alpha_{1}, α3=α4W[X/W]\alpha_{3}=\alpha_{4}^{W}[X/W] and α4=W.α4W\alpha_{4}=\forall W.\alpha_{4}^{W} where W=𝒱(xX)W=\mathcal{V}(xX). Here α1\alpha_{1} and α2\alpha_{2} are the terminals. Consider the values α1=(XX)\alpha_{1}=(X\rightarrow X) and α2=\alpha_{2}=\circ. Then we have the following distinct solutions:

α3=(XX) and α4=W.(XW)\alpha_{3}=\circ\rightarrow(X\rightarrow X)\text{ and }\alpha_{4}=\forall W.\circ\rightarrow(X\rightarrow W)
α3=(XX) and α4=W.(WW)\alpha_{3}=\circ\rightarrow(X\rightarrow X)\text{ and }\alpha_{4}=\forall W.\circ\rightarrow(W\rightarrow W)

A structure is an expression built up from a “hole” symbol and X.\forall X. and \rightarrow. We say that a type AA is built up from types A1,,AnA_{1},\ldots,A_{n} if AA can be obtained by considering a certain structure in which the “holes” are filled with types among A1,,AnA_{1},\ldots,A_{n}.

Lemma 21.

Consider the associated multisystem of a term MM with a cc-non-redundant typing. Given a solution consider the values of the terminals A1,,AnA_{1},\ldots,A_{n}. Then for each non-terminal αs\alpha s (in particular α\alpha) there is a partial substitution sequence 𝔰1,,𝔰m\mathfrak{s}_{1},\ldots,\mathfrak{s}_{m} such that the value of αs\alpha s is built up from A1𝔰1,,An𝔰mA_{1}\mathfrak{s}_{1},\ldots,A_{n}\mathfrak{s}_{m}, where mnm\geq n is bounded by the length of MM and the AiA_{i} may be repeated in this list.

Remark 22.

Since the associated multisystem determines the structure for each non-terminal, to specify a solution it is enough to give values for the terminals and a sequence 𝔰1,,𝔰n\mathfrak{s}_{1},\ldots,\mathfrak{s}_{n} for each non-terminal applying to the terminals which occur in its decomposition defined by the associated multisystem.

Proof 4.2 (Proof of Lemma 21).

Consider the irreducible multisystem of MM. Each non-terminal α\alpha occurs in a unique multiequation containing a complex type scheme, an arrow or quantifier element. We call the type scheme variables that occur in this complex type scheme the descendants of α\alpha. In this way we can associate each non-terminal with a uniquely determined non-cycling digraph G(α)G(\alpha) having terminals as leaves. To prove the lemma proceed by induction on the structure of G(α)G(\alpha).

If α\alpha is non-terminal then its multiequation contains either αs=X.σ\alpha s=\forall X.\sigma or αs=στ\alpha s=\sigma\rightarrow\tau. Note that if a type AA is built up from types AiA_{i} then A𝔰A\mathfrak{s} is built up from types A𝔰iA\mathfrak{s}_{i} where 𝔰i\mathfrak{s}_{i} are restrictions of 𝔰\mathfrak{s}. If αs=στ\alpha s=\sigma\rightarrow\tau then by hypothesis σ\sigma and τ\tau are built from partial substitutions on terminals. But α=(στ)𝔰\alpha=(\sigma\rightarrow\tau)\mathfrak{s}. Decomposing 𝔰\mathfrak{s} into partial substitution sequences 𝔰\mathfrak{s^{\prime}} and 𝔰′′\mathfrak{s^{\prime\prime}} on σ\sigma and τ\tau respectively we get that α=σ𝔰τ𝔰′′\alpha=\sigma\mathfrak{s^{\prime}}\rightarrow\tau\mathfrak{s^{\prime\prime}}. The case of αs=X.σ\alpha s=\forall X.\sigma is analogous.

{defi}

An occurrence matrix of a term MM is a set of formulas which consists of Occ(X,α)Occ(X,\alpha) or ¬Occ(X,α)\neg Occ(X,\alpha) for each type variable XX and type scheme variable α\alpha occurring in the associated multisystem of MM.

Remark 23.

If a term MM has a cc-non-redundant typing then it generates a solution to its associated multisystem which in turn generates an occurrence matrix. Notice that given this matrix we can determine all the occurrences or non-occurrences of the type variables of the multisystem in substitutions αs\alpha s of type scheme variables. It is clear that 𝒦c(M)\mathcal{K}_{c}(M) has to be satisfied, since the typing is cc-non-redundant.

Lemma 24.

Let MM be a term with a cc-non-redundant type environment Γ\Gamma and let \star be a type variable not occurring in Γ\Gamma nor in the associated multisystem of MM. Then MM has a cc-non-redundant type environment Γ\Gamma^{\prime} in which the free type variables either occur in the associated multisystem of MM or are \star.

Proof 4.3.

Notice that substitution sequences preserve equality. We use the following fact: let R¯\bar{R} be all the type variables in Γ\Gamma which do not occur in the associated multisystem of MM. In particular the variables in R¯\bar{R} do not occur among the variables in ss in a reduction sequence. Consider any equation As=BtAs=Bt. Then we have that As[/R¯]=Bt[/R¯]As[\star/\bar{R}]=Bt[\star/\bar{R}] and so A[/R¯]s=B[/R¯]tA[\star/\bar{R}]s=B[\star/\bar{R}]t. Thus if we apply [/R¯][\star/\bar{R}] to the types in Γ\Gamma it is clear that we still obtain a typing and thus a solution to the associated multisystem. The typing is still cc-non-redundant because we are not altering the variables belonging to the occurrence matrix of MM.

We call such a typing adequate. Hence to look for cc-non-redundant typings for a typable term MM we need only look for adequate typings. Hence to look for solutions to a multisystem we need only look for types with free variables occurring in the multisystem or equal to a distinguished type variable \star. We call such solutions adequate solutions and the values attributed to the type scheme variables adequate values. The following obvious result is important:

Lemma 25.

Given a term MM and adequate values for the terminals of its associated multisystem there are only a finite number of possible adequate values on the non-terminals.

This follows from Lemma 21 noticing that the partial substitution sequences can involve only the finite number of variables which occur in the associated multisystem.

Given a type AA, its variable sequence is the sequence, as they occur, of all free type variables in AA66 6 For example for A:=X(YX)A:=X\rightarrow(Y\rightarrow X) the variable sequence is X,Y,XX,Y,X. . Note that given a solution to the associated multisystem of a term MM the values of terminals in the same group have the same structure.

Lemma 26.

Consider an adequate solution to the associated multisystem of a term MM which yields a cc-non-redundant typing. Then if we substitute the values of the terminals in a given group by types having a different structure with the same variable sequences we can obtain another solution which also yields a cc-non-redundant typing.

Proof 4.4.

By Lemma 21 the non-terminals are given by partial substitution sequences on terminals and since the variable sequences of the terminals are the same after altering the structure we can use the same partial substitution sequences to obtain the values of the non-terminals. Consider αs\alpha s and αs\alpha^{\prime}s^{\prime} belonging to the same multiequation in the reduced multisystem and let α\alpha and α\alpha^{\prime} have values AA and AA^{\prime}. Then As=AsAs=A^{\prime}s^{\prime}. The values AA and AA^{\prime} are built up from partial substitutions on the values of the terminals in G(α)=G(α)G(\alpha)=G(\alpha^{\prime}). Let these values be A1,,AnA_{1},\ldots,A_{n} and A1,,AnA^{\prime}_{1},\ldots,A^{\prime}_{n}. So to check if As=AsAs=A^{\prime}s^{\prime} (after changing the structure on terminals keeping the variable sequence) we only need to check if Ais=AisA_{i}s=A^{\prime}_{i}s^{\prime} for i=1,,ni=1,\ldots,n with the changes above. We do not have to worry about renamed bound variables in AA or AA^{\prime} because we are working within a fixed irreducible multisystem and thus with a fixed structure for AA and AA^{\prime}. But observe that if Bs=BsBs=B^{\prime}s^{\prime} then Cs=CsCs=C^{\prime}s^{\prime} where CC has the variable sequence as BB and CC^{\prime} the same variable sequence as BB^{\prime}. It follows that when we alter the structure of the values of terminals in the above way that αs=αs\alpha s=\alpha^{\prime}s^{\prime} still holds for the altered values. cc-non-redundancy follows by observing that the alteration of the structure does not affect the occurrence matrix.

Hence we can now assume that in our adequate solutions the terminals are given by types of the form X1X2XnX_{1}\rightarrow X_{2}\rightarrow\ldots\rightarrow X_{n}. We call this the minimal form. We refer to the position of XiX_{i} as the iith place. We call nn the size of the type. By the result of removing the iith place from a type in minimal form (of a variable sequence of size greater than 1) we mean the type X1Xi1Xi+1XnX_{1}\rightarrow\ldots\rightarrow X_{i-1}\rightarrow X_{i+1}\rightarrow\ldots\rightarrow X_{n}.

Given an adequate solution, consider the values of terminals in a group in minimal form. They will have the same length nn. A place kk is called essential if after we alter the solution in such a way that this place is removed from the values of all terminals in a group the occurrence matrix changes. The values of the other type scheme variables are given by the restrictions of their respective partial substitutions sequences on terminals. These values are a solution because if for two terminals α\alpha and α\alpha^{\prime} their values in minimal form satisfy αs=αs\alpha s=\alpha^{\prime}s^{\prime} then they continue to satisfy this equation if we remove a place from both values.

Notice that removing a place cannot alter a non-occurrence constraint.

Lemma 27.

If a term MM has a cc-non-redundant typing then it has a cc-non-redundant typing given by an adequate solution in minimal form such that the maximum length of its values on the terminals is bounded by the order 𝒪(mn)\mathcal{O}(mn), where nn is the number of type variables and mm is the number of type scheme variables in the associated multisystem of MM.

Proof 4.5.

Consider an adequate minimal solution for the associated multisystem of MM. Given a group of terminals assume that a place is not essential. Then if we remove it we obtain a solution which gives a cc-non-redundant typing. Hence we only need to study the number of essential places on values of terminals. Observe that removing two places in a given group cannot affect the occurrence condition for the same type variable and the same type scheme. For each place nn consider the set S(n)S(n) of affected pairs (X,α)(X,\alpha). Then the sets S(n)S(n) are disjoint for different nn. It follows that the number of essential places in a group of non-terminals cannot exceed the product of the number of type variables and the number of type scheme variables in the associated multisystem.

The bound in the lemma can in fact be sharpened to the order of the cardinality of 𝒦c(M)\mathcal{K}_{c}(M), for in the proof above we are in fact only interested in not affecting certain pairs (X,α)(X,\alpha) corresponding to 𝒦c(M)\mathcal{K}_{c}(M).

As a corollary we get:

Theorem 28.

Given a typable term MM in 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} it is decidable whether it has a cc-non-redundant typing.

Given a term which admits a cc-non-redundant typing, the proof of the theorem above furnishes us with a method for type inference yielding an adequate, minimal cc-non-redundant typing. In particular it furnishes us a method of type inference for typable terms.

Note that when cc chooses all the polymorphic subterms of a term MM then cc-non-redundancy coincides with non-redundancy (cf. Definition 4.1).

In the following subsection we give concrete examples on how we check for non-redundant typability and how we can find minimal typings whose values on terminals have only essential places.

4.1. Examples

In order to give some practical examples we consider a multi-sorted first-order language with equality endowed with a single binary predicate OccOcc and two sorts TypeVariableTypeVariable and TypeSchemeTypeScheme. OccOcc has signature TypeVariable×TypeSchemeTypeVariable\times TypeScheme. The occurrence theory 𝒞\mathcal{C} includes, besides the standard axioms for equality, the following occurrence axioms:

Occ(X,στ)Occ(X,σ)Occ(X,τ)Occ(X,\sigma\rightarrow\tau)\leftrightarrow Occ(X,\sigma)\vee Occ(X,\tau)
Occ(Y,X.σ)Occ(Y,σ) for YXOcc(Y,\forall X.\sigma)\leftrightarrow Occ(Y,\sigma)\text{$\kern 5.0pt$ for~$Y\neq X$}
¬Occ(X,X.σ)\neg Occ(X,\forall X.\sigma)
¬Occ(X,σ[Y/X]) for XY\neg Occ(X,\sigma[Y/X])\text{$\kern 5.0pt$ for~$X\neq Y$}
Occ(X,σ)Occ(X,σ[Z/Y]) for XY and ZX Occ(X,\sigma)\leftrightarrow Occ(X,\sigma[Z/Y])\text{$\kern 5.0pt$ for~$X\neq Y$ and $Z\neq X$ }
Occ(X,σ)Occ(Y,σ[Y/X])Occ(X,\sigma)\rightarrow Occ(Y,\sigma[Y/X])
σ[Y/X]=σ[Z/X]Occ(X,σ)Y=Z\sigma[Y/X]=\sigma[Z/X]\wedge Occ(X,\sigma)\rightarrow Y=Z

If type scheme variables are interpreted as types and we assume that for all the resulting expression A[Y/X]A[Y/X], YY is free for XX in AA, then these axioms are clearly sound for the ordinary notion of free occurrence of a variable in a type.

Consider the example of the beginning of this section: a term MM containing subterms of the form N(xX)N(xX) and N(xY)N(xY).

Let x:α3x:\alpha_{3}, xX:α2xX:\alpha_{2}, xY:α1xY:\alpha_{1}. Put X1=𝒱(xX)X_{1}=\mathcal{V}(xX) and X2=𝒱(xY)X_{2}=\mathcal{V}(xY). The associated multisystem, after applying some rules, will include α1=α2\alpha_{1}=\alpha_{2}. It will also include

α3\displaystyle\alpha_{3} =X1α3X1\displaystyle=\forall X_{1}\alpha_{3}^{X_{1}}
α3\displaystyle\alpha_{3} =X2α3X2\displaystyle=\forall X_{2}\alpha_{3}^{X_{2}}
α2\displaystyle\alpha_{2} =α3X1[X/X1]\displaystyle=\alpha_{3}^{X_{1}}[X/X_{1}]
α1\displaystyle\alpha_{1} =α3X2[Y/X2]\displaystyle=\alpha_{3}^{X_{2}}[Y/X_{2}]

Also Occ(X1,α3X1)Occ(X_{1},\alpha_{3}^{X_{1}}) and Occ(X2,α3X2)Occ(X_{2},\alpha_{3}^{X_{2}}).

Applying (Quant) to the first two equations yields:

α3X1\displaystyle\alpha_{3}^{X_{1}} =α3X2[X1/X2]\displaystyle=\alpha_{3}^{X_{2}}[X_{1}/X_{2}]
α3X2\displaystyle\alpha_{3}^{X_{2}} =α3X1[X2/X1]\displaystyle=\alpha_{3}^{X_{1}}[X_{2}/X_{1}]

Hence

α2\displaystyle\alpha_{2} =α3X2[X1/X2][X/X1]\displaystyle=\alpha_{3}^{X_{2}}[X_{1}/X_{2}][X/X_{1}]
α1\displaystyle\alpha_{1} =α3X2[Y/X2]\displaystyle=\alpha_{3}^{X_{2}}[Y/X_{2}]

Since X1X_{1} does not occur in α3X2\alpha_{3}^{X_{2}} we get

α2\displaystyle\alpha_{2} =α3X2[X/X2]\displaystyle=\alpha_{3}^{X_{2}}[X/X_{2}]
α1\displaystyle\alpha_{1} =α3X2[Y/X2]\displaystyle=\alpha_{3}^{X_{2}}[Y/X_{2}]

Hence, since α2=α1\alpha_{2}=\alpha_{1} by the last occurrence axiom we get that X=YX=Y, a contradiction.

Consider the term (y(xX))(xY)(y(xX))(xY). Set x:α1x:\alpha_{1}, xX:α2xX:\alpha_{2}, xY:α3xY:\alpha_{3}, y(xX):α4y(xX):\alpha_{4}, (y(xX))(xY):α5(y(xX))(xY):\alpha_{5}, y:α6y:\alpha_{6} and X1=𝒱(xX)X_{1}=\mathcal{V}(xX), X2=𝒱(xY)X_{2}=\mathcal{V}(xY). The associated multisystem contains:

α6\displaystyle\alpha_{6} =α2α4\displaystyle=\alpha_{2}\to\alpha_{4}
α4\displaystyle\alpha_{4} =α3α5\displaystyle=\alpha_{3}\to\alpha_{5}
α1\displaystyle\alpha_{1} =X1.α1X1\displaystyle=\forall X_{1}.\alpha_{1}^{X_{1}}
α1\displaystyle\alpha_{1} =X2.α1X2\displaystyle=\forall X_{2}.\alpha_{1}^{X_{2}}
α2\displaystyle\alpha_{2} =α1X1[X/X1]\displaystyle=\alpha_{1}^{X_{1}}[X/X_{1}]
α3\displaystyle\alpha_{3} =α1X2[Y/X2]\displaystyle=\alpha_{1}^{X_{2}}[Y/X_{2}]

and also Occ(X1,α1X1)Occ(X_{1},\alpha_{1}^{X_{1}}), Occ(X2,α1X2)Occ(X_{2},\alpha_{1}^{X_{2}}).

Applying (Quant) to the third and fourth equations yields:

α1X1\displaystyle\alpha_{1}^{X_{1}} =α1X2[X1/X2]\displaystyle=\alpha_{1}^{X_{2}}[X_{1}/X_{2}]
α1X2\displaystyle\alpha_{1}^{X_{2}} =α1X1[X2/X1]\displaystyle=\alpha_{1}^{X_{1}}[X_{2}/X_{1}]

Hence ¬Occ(X2,α1X1)\neg Occ(X_{2},\alpha_{1}^{X_{1}}).

Let us put α1X1=X1\alpha_{1}^{X_{1}}=X_{1}. Then α1=X1.X1\alpha_{1}=\forall X_{1}.X_{1} (so x:X1.X1x:\forall X_{1}.X_{1}), α2=X,α3=Y\alpha_{2}=X,\alpha_{3}=Y and α6=XYα5\alpha_{6}=X\rightarrow Y\rightarrow\alpha_{5} (so y:XYα5y:X\rightarrow Y\rightarrow\alpha_{5}).

Consider now (xX)Y(xX)Y.

Let x:α1,xX:α2,(xX)Y:α3x:\alpha_{1},xX:\alpha_{2},(xX)Y:\alpha_{3}, X1=𝒱(xX),X2=𝒱((xX)Y)X_{1}=\mathcal{V}(xX),X_{2}=\mathcal{V}((xX)Y).

The associated multisystem contains:

α3\displaystyle\alpha_{3} =α2X2[Y/X2]\displaystyle=\alpha_{2}^{X_{2}}[Y/X_{2}]
α2\displaystyle\alpha_{2} =α1X1[X/X1]\displaystyle=\alpha_{1}^{X_{1}}[X/X_{1}]

with Occ(X2,α2X2)Occ(X_{2},\alpha_{2}^{X_{2}}) and Occ(X1,α1X1)Occ(X_{1},\alpha_{1}^{X_{1}}). Since the associated multisystem contains:

α1\displaystyle\alpha_{1} =X1.α1X1\displaystyle=\forall X_{1}.\alpha_{1}^{X_{1}}
α2\displaystyle\alpha_{2} =X2.α2X2\displaystyle=\forall X_{2}.\alpha_{2}^{X_{2}}

we get

α1X1[X/X1]=X2.α2X2\alpha_{1}^{X_{1}}[X/X_{1}]=\forall X_{2}.\alpha_{2}^{X_{2}}

Occurrence axioms yield Occ(X,α1X1[X/X1])Occ(X,\alpha_{1}^{X_{1}}[X/X_{1}]) and thus Occ(X,α2X2)Occ(X,\alpha_{2}^{X_{2}}). We also have Occ(X2,α2X2)Occ(X_{2},\alpha_{2}^{X_{2}}). Also it is clear that ¬Occ(X1,α2X2)\neg Occ(X_{1},\alpha_{2}^{X_{2}}). Take α2X2=X2X\alpha_{2}^{X_{2}}=X_{2}\rightarrow X. Since

α1X1[X/X1]=X2.X2X\alpha_{1}^{X_{1}}[X/X_{1}]=\forall X_{2}.X_{2}\rightarrow X

and Occ(X1,α1X1)Occ(X_{1},\alpha_{1}^{X_{1}}) we must have α1X1=X2.X2X1\alpha_{1}^{X_{1}}=\forall X_{2}.X_{2}\rightarrow X_{1} and hence

x:X1.X2.X2X1x:\forall X_{1}.\forall X_{2}.X_{2}\rightarrow X_{1}

is a non-redundant typing.

Another example is ΛX.(xY)\Lambda X.(xY).

Put x:α1,xY:α2,ΛX.(xY):α3x:\alpha_{1},xY:\alpha_{2},\Lambda X.(xY):\alpha_{3} and X1=𝒱(xY)X_{1}=\mathcal{V}(xY). Then α3=X.α2\alpha_{3}=\forall X.\alpha_{2}, α2=α1X1[Y/X1]\alpha_{2}=\alpha_{1}^{X_{1}}[Y/X_{1}] and α1=X1.α1X1\alpha_{1}=\forall X_{1}.\alpha_{1}^{X_{1}} with Occ(X1,α1X1)Occ(X_{1},\alpha_{1}^{X_{1}}), Occ(X,α2)Occ(X,\alpha_{2}) and ¬Occ(X,α1)\neg Occ(X,\alpha_{1}).

Substitution yields Occ(X,α1X1[Y/X1])Occ(X,\alpha_{1}^{X_{1}}[Y/X_{1}]) and ¬Occ(X,X1.α1X1)\neg Occ(X,\forall X_{1}.\alpha_{1}^{X_{1}}) and the occurrence axioms imply the contradiction Occ(X,α1X1)Occ(X,\alpha_{1}^{X_{1}}) and ¬Occ(X,α1X1)\neg Occ(X,\alpha_{1}^{X_{1}}).

A more interesting example: (ΛX.λx.x)Y(\Lambda X.\lambda x.x)Y. In this case we get the non-redundant typing x:Xx:X as can easily be checked.

5. Final Remarks

Remark 29.

A procedure for type inference will take as input a typable term and generate a typing (or class of typings which is general enough in some sense). By the results of Section 4 we see that the output of such a procedure will involve not only specifying occurrence (or non-occurrence) constraints for variables and terminal type scheme variables but also will involve a bound on the number of occurrences that may be required to obtain a valid typing.

For Lemma 4.14 in the case in which cc does not choose any polymorphic subterms, that is, 𝒦c(M)=(M)\mathcal{K}_{c}(M)=\mathcal{B}(M) does not contain any positive constraints, we obtain a method of type inference for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} in Polymorphic Curry style.

Further work will involve a detailed analysis of the complexity of the procedure involved, preferably in the context of an actual implementation.

Remark 30.

In a recent work [PT21] Pistone and Tranchini proved that typability is decidable for Curry style 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}. They do this by means of an alternative approach which involves reducing typability to the type checking problem (TC). To show that TC is decidable, they employ a decidable restriction, modeled after 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}}, of the general undecidable second-order unification problem. The restricted problem is shown to be decidable by reduction to the first-order case where the problem of finding variable cycles is decidable. Type checking is reduced to such a restricted second-order unification problem. Our present work on the other hand analyzes typability not only for Curry style terms but also for Polymorphic Curry style terms and most of the paper is focused on obtaining a procedure for type inference embodying possible constraints.

The question we address in this paper of finding non-redundant typings for Polymorphic Curry terms can be posed also for Curry terms. Note that the question of the typability of a Curry term MM can be seen as involving the analysis of possible Polymorphic Curry terms NN such that [N]=M[N]=M. An assumption variable xx occurring in a Curry term MM is called non-applying if it does not occur in a subterm of the form xyxy. We call a Polymorphic Curry term NN such that [N]=M[N]=M non-trivial for MM if NN is not equal to MM or obtained from MM by replacing non-applying assumption variables xx in MM by xXxX for some type variable XX. A typing for such an NN is called a non-trivial typing of MM. For the Curry system the following important questions can be asked:

  1. (1)

    Given a Curry term MM is it decidable whether MM has a non-trivial non-redundant typing?77 7 This is non trivial. For example given a Curry term MM, one cannot simply consider ΛX.M\Lambda X.M for a certain XX as the example (λx.xy)z(\lambda x.xy)z shows.

  2. (2)

    In searching for a non-trivial non-redundant typing for MM do we need to consider only a finite number (bounded by the complexity of MM) of Polymorphic Curry terms NN such that [N]=M[N]=M?

  3. (3)

    for MM having a non-trivial non-redundant typing is there a procedure to generate such typings?

It seems plausible that question (2) can be answered in the affirmative, specially if we consider arguments based on strong normalisation as in Remark 5.3. In this case it is readily seen that the results of the present work allow us to answer (1) in the affirmative and that we obtain an effective procedure for question (3).

We also observe that in an implementation of 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} in actual programming languages the questions above are relevant. Redundant typing can be seen as problematic in terms of being computationally insignificant and a waste of resources.

Remark 31.

We mentioned in the above remark that TC for 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} in the Curry system has been shown to be decidable in [PT21] using a second-order unification technique. It seems there could be an alternative approach (perhaps computationally more efficient) based on the Polymorphic Curry style and the fact that 𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} has strong normalisation. Given an environment Γ\Gamma, a type AA and a Curry term MM, the above problem is equivalent to finding a Polymorphic Curry term NN such that [N]=M[N]=M and ΓN:A\Gamma\vdash N:A.

The number of instantiations in a derivation of NN is clearly bounded by the number of universal abstractions in the derivation and the total number of universal abstractions in Γ\Gamma, so we only need to study the bounds of these. But what about series of repeated applications of INST and GEN on the same variable? It would seem that we need normalisation arguments like [Wel99] [Lemma 3.2 or Lemma 3.4]. Also

Lemma 32.

Suppose Γ𝐅𝐚𝐭M:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M:A where MM is a Polymorphic Curry term and let MM contain a universal abstraction on XX, with XX not occurring in Γ\Gamma or in AA. Then there is a term MM^{\prime} such that [M]=[M][M]=[M^{\prime}], Γ𝐅𝐚𝐭M:A\Gamma\vdash_{{\mathbf{F}}_{\mathbf{at}}}M^{\prime}:A and MM^{\prime} has one less occurrence of universal abstractions on XX.

In the case in which Γ\Gamma and AA are canonical (in the terminology of [Wel99]), that is, have no redundant quantifiers, this follows from [Wel99] Lemma 3.11.

It seems plausible that using this lemma and normalisation (𝐅𝐚𝐭{\mathbf{F}}_{\mathbf{at}} has strong normalisation [FF13]) we can show that there are only a finite number of possible terms NN with [N]=M[N]=M which we need to consider to decide if ΓN:A\Gamma\vdash N:A. Of course if MM is not normal then there can be no normal NN such that [N]=M[N]=M. However we could restrict reduction to polymorphic redexes only. In the derivation of such reduced terms a INST can never come after a GEN. Also by canonicity sequences of GENs must be of length bounded by the structure of Γ\Gamma. Sequences of INST are bounded by the number of previous GENs. Hence the number of combinations of INST and GEN is finite and bounded by the structure of Γ\Gamma and AA and thus we need only consider a finite number of terms NN such that [N]=M[N]=M and the problem above is very likely decidable. We intend to proceed this line of research in future work.

Acknowledgments

The authors are grateful to the anonymous referees for useful comments and suggestions regarding the preliminary versions of this paper. In particular they acknowledge the idea of working with cc-non-redundancy.

References

  • [DR19] A. Dudenhefner and J. Rehof. A simpler undecidability proof for system F inhabitation. TYPES 2018, Leibniz International Proceedings in Informatics (LIPIcs), 130, 2019.
  • [Fer06] F. Ferreira. Comments on predicative logic. Journal of Philosophical Logic, 35:1–8, 2006.
  • [Fer17a] G. Ferreira. Eta-conversions of IPC implemented in atomic F. Logic Journal of the IGPL, 25(2):115–130, 2017.
  • [Fer17b] G. Ferreira. Rasiowa–Harrop disjunction property. Studia Logica, 105:649–664, 2017.
  • [FF13] F. Ferreira and G. Ferreira. Atomic polymorphism. The Journal of Symbolic Logic, 78(1):260–274, 2013.
  • [Gir71] J.-Y. Girard. Une extension de l’interprétation de Gödel à l’analyse, et son application a l’elimination des coupures dans l’analyse et la theorie des types. In Proceedings of the second scandinavian logic symposium (J. E. Fenstad, editor), pages 63–92. North Holland, 1971.
  • [GLT89] J-Y. Girard, Y. Lafont, and P. Taylor. Proofs and Types. Cambridge University Press, 1989.
  • [Lö76] M. H. Löb. Embedding first order predicate logic in fragments of intuitionistic logic. The Journal of Symbolic Logic, 41(4):705–718, 1976.
  • [Pro21] M. Clarence Protin. Type inhabitation of atomic polymorphism is undecidable. Journal of Logic and Computation, 31(2):416–425, 2021.
  • [PT21] Paolo Pistone and Luca Tranchini. What’s Decidable About (Atomic) Polymorphism? In Naoki Kobayashi, editor, 6th International Conference on Formal Structures for Computation and Deduction (FSCD 2021), volume 195 of Leibniz International Proceedings in Informatics (LIPIcs), pages 27:1–27:23, Dagstuhl, Germany, 2021. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. URL: https://drops.dagstuhl.de/opus/volltexte/2021/14265, doi:10.4230/LIPIcs.FSCD.2021.27.
  • [PTP22] P. Pistone, L. Tranchini, and M. Petrolo. The naturality of natural deduction (II). On atomic polymorphism and generalized propositional connectives. Studia Logica, 110:545–592, 2022.
  • [Rém02] D. Rémy. Using, Understanding, and Unraveling the OCaml Language. In Gilles Barthe, editor, Applied Semantics. Advanced Lectures. LNCS 2395., pages 413–537. Springer Verlag, 2002.
  • [Rey74] J. C. Reynolds. Towards a theory of type structure. In Colloque sur la programmation (B. Robinet, editor), volume 19 of Lecture Notes in Computer Science. Springer Verlag, 1974.
  • [SF20] J. Espírito Santo and G. Ferreira. A refined interpretation of intuitionistic logic by means of atomic polymorphism. Studia Logica, 108:477–507, 2020.
  • [TPP19] L. Tranchini, P. Pistone, and M. Petrolo. The naturality of natural deduction. Studia Logica, 107:195–231, 2019.
  • [Wel99] J. B. Wells. Typability and type checking in System F are equivalent and undecidable. Annals of Pure and Applied Logic, 98(1-3):111–156, 1999.