- 1Faculty of Technical Sciences, University of Novi Sad, Novi Sad, Serbia
- 2Mathematical Institute of the Serbian Academy of Sciences and Arts, Belgrade, Serbia
There is a plethora of semantics of computational models, nevertheless, the semantics of combinatory logic are among the less investigated ones. In this paper, we propose semantics for the computational system of combinatory logic with intersection types. We define extensional applicative structures endowed with special elements corresponding to primitive combinators. We prove two soundness and completeness results. First, the equational theory of untyped combinatory logic is proven to be sound and complete with respect to the proposed semantics. Second, the system of the combinatory logic with intersection types is proven to be sound and complete with respect to the proposed semantics. The usual approach to the semantics for calculi with types that can be found in the literature is based on models for the untyped calculus endowed with a valuation of type variables which enables the interpretation of types to be defined inductively. We propose, however, a different approach. In the semantics we propose, the interpretation of types is represented as a family of subsets that satisfies certain properties, whereas for a given valuation of term variables, the interpretation of terms is defined inductively. Due to the wide applicability of semantics of computational models, the presented approach could be further developed to other computational models and beyond—to current and foreseen application of semantics to large distributed systems and new challenging technologies.
1. Introduction
In the 1920s two models of computation were invented, combinatory logic and lambda calculus. The foundations of combinatory logic and lambda calculus was established in Curry (1930) and Church (1936), respectively. They were developed with the aim to describe functions, their behavior and properties. Nowadays they serve as a basis for the design of functional programming languages and programming languages at large. These two models of computation have the same computational power, they can express the same computational concepts; however the syntax of combinatory logic is much simpler. The basic idea of combinatory logic, introduced in Schönfinkel (1924), is to build functions without using variables. In order to control function application, type systems were introduced for both combinatory logic and lambda calculus. A recent comprehensive overview of combinators is given in Wolfram (2021). Apart from usual application in programming languages, typed combinatory logic has found its application in a wide range of different fields, such as machine learning, artificial intelligence, program synthesis. Developments of these fields urge for further investigation and development of the theory of combinatory logic.
In computation and type theory, intersection types characterize exactly all strongly normalizing lambda terms (Coppo and Dezani-Ciancaglini, 1978; Sallé, 1978; Pottinger, 1980) providing, on the computational side, a significant extension of simple types, which do not type even some normal forms, such as λx.xx. On the semantical side, intersection types became a powerful tool suitable for analysing lambda models (Barendregt et al., 1983, 2013). Intersection types for different systems have been studied (e.g., van Bakel et al., 2018; de'Liguoro and Treglia, 2019). Combinatory logic was equipped with intersection types in Dezani-Ciancaglini and Hindley (1992) with the same computational advantage of characterizing exactly all strongly normalizing combinatory terms, i.e., computations that always terminate.
The main contributions and results of this paper:
• We propose a novel semantics for combinatory logic with intersection types. We define extensional applicative structures endowed with special elements corresponding to primitive combinators S, K and I.
• We prove that the equational theory of untyped combinatory logic is sound and complete with respect to the proposed semantics.
• We then prove that combinatory logic with intersection types is sound and complete with respect to the proposed semantics.
1.1. Background and Motivation
There have been several approaches to semantics of lambda calculus with intersection types (Barendregt et al., 1983; Dezani-Ciancaglini and Margaria, 1984; Barbanera et al., 1995; Ong and Tsukada, 2012; de Carvalho, 2018) nevertheless none of them addresses combinatory logic. In Barendregt et al. (1983), the authors have introduced the filter models for lambda calculus and proved the soundness and completeness of the type assignment system with respect to the proposed semantics. Further, in Dezani-Ciancaglini and Margaria (1984) a modification of intersection type discipline has been considered, and it has been proved that this type system is sound and complete with respect to the F-semantics. The type assignment system with intersection and union types has been introduced in Barbanera et al. (1995), where authors proposed three semantics for the introduced system and proved soundness and completeness results. In de Carvalho (2018), the author introduced a non-uniform semantics of lambda calculus which allows to measure execution time and presented the intersection type system induced by these semantics, which can be seen as a reformulation of the system of Coppo et al. (1980). In Ong and Tsukada (2012), the two-level game semantics is used to model intersection types.
On the other hand, semantics for combinatory logic with intersection types has not been investigated as much as the semantics for lambda calculus with intersection types. An overview of models of combinatory logic is given in Bimbó (2012), however most of these models are models of untyped combinatory logic. Particularly, one class of models for combinatory logic with intersection types is presented based on theories of types which are in 1 − 1 correspondence with filters. Nevertheless, to the best of our knowledge filter models for combinatory logic with intersection types has not been published anywhere. The lack of study of models of combinatory logic has been our motivation for the present research.
1.2. Organization of the Paper
In Section 2, we briefly review basic notions of the untyped combinatory logic and intersection type assignment system for combinatory logic. We then define the semantics in Section 3. Section 4 presents the results of the paper: in Section 4.1, we prove the soundness and completeness of the equational theory of the untyped combinatory logic with respect to the proposed semantics; in Section 4.2, we prove the soundness and completeness of the combinatory logic with intersection types with respect to the proposed semantics. Section 5 concludes and contains the discussion of the related work.
2. Combinatory Logic With Intersection Types
We shortly review some basic notions of the untyped combinatory logic CL (Barendregt, 1985; Hindley and Seldin, 1986; Bimbó, 2012), and intersection types for combinatory logic (Dezani-Ciancaglini and Hindley, 1992).
2.1. Combinatory Logic
The language of combinatory logic is build up from a countable set of term variables V and a set of term constants using application, the only (binary) operation. Terms of combinatory logic, called CL-terms, are generated by the following grammar:
where x is a term variable and S, K, I are term constants, or constants for short. The set of all CL-terms is denoted by CL and is ranged over by capital letters M, N, …, M1, …. The set of variables that occur in a term M is denoted by FV(M), and the result of substitution of the term N for variable x in the term M is denoted by M{N/x}. The use of parentheses is minimized by the convention that application associates to the left: M1M2…Mn means […(M1M2)…Mn].
The main objects of study in combinatory logic are the relations between terms. We will consider the equivalence relation generated by the equational theory given in Figure 1.
If M = N can be derived from the set of axioms and rules of Figure 1 we say that terms M and N are equal, and we write M = N. The equational theory obtained by adding the rule
to the equational theory will be denoted by , and it represents the extensional equational theory. We write M =η N, whenever M = N is provable in . We use the notion of equivalence classes: .
2.2. Intersection Types
Intersection types for combinatory logic were introduced in Dezani-Ciancaglini and Hindley (1992). The set of intersection types is generated by the following grammar:
where a belongs to a countable set of type variables VType and ω is a type constant. There are two type forming operations: the arrow, →, which generates the simple types and the intersection, ∩, which provides the extension of the simple types. The set of all intersection types is denoted by Types and is ranged over by σ, τ, …, σ1, …. We can omit parentheses in arrow types by removing outer parentheses and using the convention that, unless otherwise bracketed, nested arrows associate to the right: σ1 → … → σn−1 → σn means (σ1 → … → (σn−1 → σn)). Intersection types are associative: (σ ∩ τ) ∩ ρ is the same as σ ∩ (τ ∩ ρ), and an intersection type takes precedence over an arrow type: σ ∩ τ → ρ means (σ ∩ τ) → ρ.
Definition 2.1 (Dezani-Ciancaglini and Hindley, 1992; Barendregt et al., 2013).
(i) A statement is of the form M : σ, where M ∈ CL and σ ∈ Types. The term M is the subject and the type σ is the predicate of the statement.
(ii) A declaration is a statement with a term variable as subject, i.e., x : σ.
(iii) A basis (context) is a set of declarations with distinct term variables as subjects.
(iv) Let Γ = {x1 : σ1, …, xn : σn} be a basis. The set dom(Γ) = {x1, …, xn} is the domain of the basis Γ.
(v) Let Γ = {x1 : σ1, …, xn : σn} be a basis. Then |Γ| = {σ1, …, σn}.
The subtyping (pre-order) relation on the set of intersection types is defined in the following way.
Definition 2.2 (Dezani-Ciancaglini and Hindley, 1992). The relation ≤ is the smallest binary relation satisfying:
(1) σ ≤ σ;
(2) σ ≤ σ ∩ σ;
(3) σ ≤ ω;
(4) σ ∩ τ ≤ σ, σ ∩ τ ≤ τ;
(5) ω ≤ ω → ω;
(6) (σ → ρ) ∩ (σ → τ) ≤ σ → (ρ ∩ τ);
(7) if σ ≤ τ, τ ≤ ρ then σ ≤ ρ;
(8) if σ ≤ σ1, τ ≤ τ1, then σ ∩ σ1 ≤ τ ∩ τ1;
(9) if σ ≤ σ1, τ ≤ τ1, then σ1 → τ ≤ σ → τ1,
The induced equivalence relation ~ is defined by
The type-assignment system for combinatory logic with intersection types, denoted by CL∩, is presented in Figure 2. If the typing judgment Γ ⊢ M : σ can be derived by the rules in Figure 2, then it means that the statement M : σ is derivable from the basis Γ and that the term M is typable in the given basis Γ with type σ.
The rules (axiom S), (axiom K), and (axiom I) type the combinators S, K, and I, respectively. The rule (axiom ω) enables every combinatory term M to be typable. The rules (→ elim), (∩ elim-l), and (∩ elim-r) are the usual elimination rules for → and ∩, respectively. The rule (∩ intro) is the introduction rule for ∩. The rule (sub-type) is the subsumption rule induced by the subtyping relation on types and the rule (eq) is the rule which enables type preservation under equality.
Remark 2.3. The type-assignment system of Dezani-Ciancaglini and Hindley (1992) is obtained from CL∩ by omitting the rule (eq). Type-assignment statements in are preserved by the equality generated by the equational theory (Dezani-Ciancaglini and Hindley, 1992, Theorem 3.12). In order to obtain a type-assignment system in which types are preserved by the equality generated by the extensional equational theory , the rule (eq) has to be added.
Lemma 2.4 (Weakening lemma). If Γ ⊢ M : σ and Γ ⊆ Γ′ then Γ′ ⊢ M : σ.
Proof. By induction on the length of derivation of Γ ⊢ M : σ.□
3. Semantics for CL∩
In this section, we introduce a semantics for combinatory logic with intersection types. We define a model for CL∩ as an applicative structure equipped with an environment.
Definition 3.1. An applicative structure for CL∩ is a tuple
which consists of:
(i) a non-empty set D, called domain,
(ii) a family {Aσ} of sets indexed by types σ, such that for every σ, τ ∈ Types,
• Aσ ⊆ D,
• Aω = D,
• Aσ∩τ = Aσ ∩ Aτ,
• if σ ≤ τ, then Aσ ⊆ Aτ.
(iii) an application function App:D × D → D, such that for every σ, τ ∈ Types,
App↾(Aσ → τ × Aσ):Aσ → τ × Aσ → Aτ.
Definition 3.2. An applicative structure
has combinators if there exist elements s, k, i of the domain D such that
• s ∈ A(σ → (ρ → τ)) → ((σ → ρ) → (σ → τ)) for every σ, ρ, τ ∈ Types,
• k ∈ Aσ → (τ → σ) for every σ, τ ∈ Types,
• i ∈ Aσ → σ for every σ ∈ Types,
• for every a, b, c ∈ D the following equations hold:
Definition 3.3. An applicative structure
is extensional if for all f, g ∈ D it holds that
Definition 3.4. An environment ρ for an applicative structure is a mapping from a set of term variables to the domain, ρ:V → D.
Although the proposed semantics is not Kripke-style semantics, its definition is inspired by the Kripke-style semantics introduced in Mitchell and Moggi (1991) and Kašterović and Ghilezan (2020), where a model is also defined as an applicative structure provided with an environment. The important difference between Definition 3.4 and the definition of an environment in Kašterović and Ghilezan (2020) is the fact that the environment in Kašterović and Ghilezan (2020) was a partial mapping, whereas herein it is a total mapping. The motivation for defining environments as total mappings will be explained in Remark 4.5.
Let ρ be an environment for and a ∈ D. By ρ(x: = a) we denote the environment for such that for all y ∈ V
Definition 3.5. A model for CL∩ is a pair , where is an extensional applicative structure for CL∩ with combinators, and ρ is an environment for .
Definition 3.6. Let be a model for CL∩. We define the meaning of a term M in the environment ρ, denoted by ⟦M⟧ρ, inductively as follows:
1. ⟦x⟧ρ = ρ(x),
2. ⟦S⟧ρ = s,
3. ⟦K⟧ρ = k,
4. ⟦I⟧ρ = i,
5. ⟦MN⟧ρ = App(⟦M⟧ρ, ⟦N⟧ρ).
Note that the meaning of a term does not depend on the meaning of the variables that do not occur in the term. Since an environment ρ is a total mapping and ρ(x) is defined for every variable x, the meaning of every term M, denoted by ⟦M⟧ρ, is also well-defined.
Remark 3.7. An important difference between the applicative structure we define and the one introduced in Mitchell and Moggi (1991) is that we have a domain in the applicative structure. In Mitchell and Moggi (1991) the authors define the interpretation of the judgment Γ ⊢ M : σ, they interpret the term with its type. In turn, we wanted to be able to define the interpretation of a term independent of its type. For this reason we have introduced a domain as part of the applicative structure.
Lemma 3.8. Let be an extensional applicative structure for CL∩ with combinators, ρ1 and ρ2 environments for and M a CL-term. If ρ1(x) = ρ2(x) holds for every variable x ∈ FV(M), then ⟦M⟧ρ1 = ⟦M⟧ρ2.
Proof. We prove the statement by induction on the structure of the term M.
• Let M be a variable x. If ρ1(x) = ρ2(x), then ⟦x⟧ρ1 = ρ1(x) = ρ2(x) = ⟦x⟧ρ2.
• If M is a term constant, then its interpretation does not depend on the environment, but only on the applicative structure. For example, let M be a term constant S, then ⟦S⟧ρ1 = s = ⟦S⟧ρ2.
• If M is an application NL, then by the induction hypothesis the statement holds for terms N and L, ⟦N⟧ρ1 = ⟦N⟧ρ2 and ⟦L⟧ρ1 = ⟦L⟧ρ2. Now, by Definition 3.6 we have
□
Lemma 3.9 (Substitution lemma). Let M, N be CL-terms and ρ an environment for an applicative structure . Then,
The satisfiability of a statement M : σ in a model and the notion of semantical consequence are defined as follows.
Definition 3.10 (Kašterović and Ghilezan, 2020).
1. A statement M : σ is satisfied in a model Mρ, denoted by , if and only if . In this case we say is a model of the statement M : σ. If a model does not satisfy the statement M : σ, we write .
2. A model is a model of a basis Γ, denoted by , if and only if every declaration x : σ from the basis Γ is satisfied in the model , namely .
3. A statement M : σ is a semantical consequence of a basis Γ, denoted by Γ ⊧ M : σ, if and only if every model of the basis Γ is also a model of the statement M : σ.
4. Soundness and Completeness Results
In this section we present the main results of the paper. We prove in Section 4.1 that the equational theory of the untyped combinatory logic is sound and complete with respect to the proposed semantics. In Section 4.2, we prove that the type-assignment system CL∩ is sound and complete with respect to the proposed semantics.
4.1. Soundness and Completeness of Equational Theory
In the previous section we have introduced models for CL∩ such that the interpretation of every term is defined in a model. A fundamental question to ask is: if two terms are proven to be equal in the equational theory are their interpretations equal in a model?—this is referred to as the soundness of the equational theory with respect to the model. The other direction: if interpretations of two terms are equal in every model are the terms proven to be equal in the equational theory?—is referred to as the completeness.
In the sequel, we prove that the equational theory of untyped combinatory logic is sound and complete with respect to the proposed semantics.
Theorem 4.1 (Soundness of ). If M =η N, then ⟦M⟧ρ = ⟦N⟧ρ for every model .
Proof. The proof is by induction on the length of the proof of M = N in .
If M = N is an instance of axiom (id), then terms M and N represent the same term L and it holds that ⟦M⟧ρ = ⟦L⟧ρ = ⟦N⟧ρ for every model .
If M = N is obtained by axiom (S), then there exist terms P, Q and R such that terms M and N are terms SPQR and (PR)(QR), respectively. Then, from Definitions 3.2 and 3.6 we obtain
If M = N is obtained by axiom (K), then there exist terms P and Q, such that terms M and N are terms KPQ and P, respectively. Then, from Definitions 3.2 and 3.6 we obtain
If M = N falls under axiom (I), then terms M and N are of the form IP and P, respectively, for some term P. In a similar way as in the previous two cases, we obtain
If M = N is obtained from N = M by rule (sym), then by induction hypothesis ⟦N⟧ρ = ⟦M⟧ρ and the statement holds.
If M = N is obtained from M = L and L = N by rule (trans), then ⟦M⟧ρ = ⟦L⟧ρ and ⟦L⟧ρ = ⟦N⟧ρ hold by induction hypothesis. Thus, ⟦M⟧ρ = ⟦N⟧ρ also holds.
Next, let us suppose that M = N is obtained from L = Q by rule (app-l), then terms M and N are of the form LP and QP, respectively, for some term P. By induction hypothesis ⟦L⟧ρ = ⟦Q⟧ρ. From the latter we obtain
Similarly to the previous case, if M = N is obtained by rule (app-r), then terms M and N are of the form PL and PQ, respectively, for some terms P, L, Q such that L = Q is provable in . By induction hypothesis we obtain ⟦L⟧ρ = ⟦Q⟧ρ, and thus
Finally, we consider the case where M = N is obtained by applying rule (ext) to Mx = Nx, with x being a variable which appears neither in M nor in N. Let be a model for CL∩. In order to prove that ⟦M⟧ρ = ⟦N⟧ρ holds, it is enough to prove that for every d ∈ D it holds that App(⟦M⟧ρ, d) = App(⟦N⟧ρ, d), because of the extensionality of the applicative structure . Let d ∈ D. Since by induction hypothesis ⟦Mx⟧ρ = ⟦Nx⟧ρ holds in any model, it also holds in model , that is App(⟦M⟧ρ(x: = d), ⟦x⟧ρ(x: = d)) = App(⟦N⟧ρ(x: = d), ⟦x⟧ρ(x: = d)). From the assumption that x does not appear in M and Lemma 3.8, we obtain ⟦M⟧ρ = ⟦M⟧ρ(x: = d). Similarly, ⟦N⟧ρ = ⟦N⟧ρ(x: = d). Now, we have
Thus, ⟦M⟧ρ = ⟦N⟧ρ due to the extensionality of the applicative structure.
This concludes the proof.□
Recall that by [M] we denote the equivalence class of term M with respect to the equivalence relation generated by the equational theory , .
In order to prove the completeness, we first prove the following property.
Lemma 4.2. Let be an extensional applicative structure with combinators, such that D = {[M]∣M ∈ CL}, App([M], [N]) = [MN], s = [S], k = [K] and i = [I]. If an environment ρ⋆ is defined by ρ⋆(x) = [x], then .
Proof. The proof is by induction on the structure of M.
• If the term M is a variable x, then by Definition 3.6 we have .
• If the term M is a term constant, for example S, then by Definition 3.6 we have . Similarly, for term constants K and I.
• If the term M is an application NL, then by the induction hypothesis the statement holds for terms N and L, and . Further, by Definition 3.6 we obtain .
□
Theorem 4.3 (Completeness of ). If ⟦M⟧ρ = ⟦N⟧ρ holds in every model , then M =η N.
Proof. Suppose that ⟦M⟧ρ = ⟦N⟧ρ holds for any model . We define a model where is an applicative structure 〈D, {Aσ}, App〉 with the following components:
• the domain D is defined by D = {[M] ∣ M ∈ CL};
• for every σ ∈ Types, Aσ = {[M] ∣ M ∈ CL and ⊢ M : σ};
• App is a function defined by App([M], [N]) = [MN].
The environment ρ⋆ is defined by ρ⋆(x) = [x].
First we prove that the structure is an applicative structure, meaning that it satisfies conditions of Definition 3.1. The set D is a non-empty set. For every σ ∈ Types, the set Aσ = {[M] ∣ M ∈ CL and ⊢ M : σ} is a subset of the set D = {[M] ∣ M ∈ CL}. Since for every term M it holds that ⊢ M : ω, we have that Aω = {[M] ∣ M ∈ CL and ⊢ M : ω} = {[M] ∣ M ∈ CL} = D. Next, we look at the sets Aσ and Aτ. By the definition of the applicative structure we have Aσ = {[M] ∣ M ∈ CL and ⊢ M : σ} and Aτ = {[M] ∣ M ∈ CL and ⊢ M : τ}. If [M] ∈ Aσ ∩ Aτ, then ⊢ M : σ and ⊢ M : τ. By rule (∩ intro) of Figure 2 we obtain ⊢ M : σ ∩ τ, which is equivalent to [M] ∈ Aσ∩τ, and we conclude Aσ ∩ Aτ ⊆ Aσ∩τ. Similarly, we prove that Aσ∩τ ⊆ Aσ ∩ Aτ and we conclude Aσ∩τ = Aσ ∩ Aτ. Let σ, τ ∈ Types such that σ ≤ τ. If [M] ∈ Aσ, then ⊢ M : σ holds, and since σ ≤ τ we obtain ⊢ M : τ by rule (sub-type). It follows that [M] ∈ Aτ and we can conclude that σ ≤ τ implies Aσ ⊆ Aτ. The function App defined by App([M], [N]) = [MN] maps D × D to D. If [M] ∈ Aσ → τ and [N] ∈ Aσ, then by the definition of the applicative structure we have ⊢ M : σ → τ and ⊢ N : σ. By rule (→ elim) of Figure 2 we obtain ⊢ MN : τ, thus we conclude [MN] ∈ Aτ and App ↾ (Aσ → τ × Aσ):Aσ → τ × Aσ → Aτ.
Next, we prove that the applicative structure has combinators. We consider the equivalence classes [S], [K], [I] ∈ D and denote them by s, k, i, respectively. Since ⊢ S:(σ → (τ → ρ)) → ((σ → τ) → (σ → ρ)) holds by (axiom S) of Figure 2, we have that s = [S] ∈ A(σ → (τ → ρ)) → ((σ → τ) → (σ → ρ)) for any σ, τ, ρ ∈ Types. Similarly, we obtain k = [K] ∈ Aσ → (τ → σ) and i = [I] ∈ Aσ → σ. We also have to prove that the elements s, k, and i satisfy the Equations (1)–(3). By the rules of the equational theory we obtain [SMNL] = [(ML)(NL)], [KMN] = [M] and [IM] = [M] and it follows that:
The extensionality of the applicative structure follows from the extensionality of combinatory logic. Let [M], [N] ∈ D such that for every [L] ∈ D, App([M], [L]) = App([N], [L]), i.e., [ML] = [NL]. Then, for a variable x, that does not appear in terms M and N, it holds that [Mx] = [Nx], that is Mx = Nx is provable in . By rule (ext) we obtain M = N is provable in , so [M] = [N].
We have proved that is a model for CL∩. If ⟦M⟧ρ = ⟦N⟧ρ in any model, then it also holds in the model . Hence, we have that . From Lemma 4.2 we get and . Now we can conclude that [M] = [N] holds, that is M =η N.□
Theorems 4.1 and 4.3 prove that the equational theory of untyped combinatory logic is both sound and complete with respect to the proposed semantics, hence the proposed semantics is a semantics of the untyped combinatory logic.
4.2. Soundness and Completeness of Type-Assignment System CL∩
In the sequel we consider another fundamental question: if M : σ is (syntactically) derivable in the type system CL∩, ⊢ M : σ, is it valid in all models, ⊧ M : σ?—this is referred to as the soundness of the type-assignment system with respect to the model. More general, if Γ ⊢ M : σ is (syntactically) derivable in the type system CL∩, is it semantically derivable, Γ ⊧ M : σ? The other direction: if M : σ is valid in all models of CL∩, is it derivable in CL∩?—is referred to as the completeness. More general, does semantical derivability Γ ⊧ M : σ imply syntactical derivability Γ ⊢ M : σ?
We prove herein the type-assignment system CL∩ to be sound and complete with respect to the proposed semantics.
Theorem 4.4 (Soundness of CL∩). If Γ ⊢ M : σ, then Γ ⊧ M : σ.
Proof. We prove the statement by induction on the derivation of Γ ⊢ M : σ, considering the last rule used.
• Let be the last rule used. Assume that is a model, such that . By Definition 3.10, the latter implies that for every y : τ ∈ Γ, . From the premise we have x : σ ∈ Γ, thus .
• If Γ ⊢ M : σ falls under (axiom S), then we have Γ ⊢ S:(σ1 → (ρ1 → τ1)) → ((σ1 → ρ1) → (σ1 → τ1)) for some σ1, τ1, ρ1 ∈ Types. Let be an arbitrary model for CL∩. By Definition 3.6 we have that . Thus, and we can conclude Γ ⊧ S:(σ1 → (ρ1 → τ1)) → ((σ1 → ρ1) → (σ1 → τ1)).
• If Γ ⊢ M : σ falls under (axiom K), then we have Γ ⊢ K : σ1 → (τ1 → σ1) for some σ1, τ1 ∈ Types. Let be an arbitrary model for CL∩. We have that . Thus, holds and we can conclude Γ ⊧ K : σ1 → (τ1 → σ1).
• If Γ ⊢ M : σ falls under (axiom I), then we have Γ ⊢ I : σ1 → σ1 for some σ1 ∈ Types. For an arbitrary model it holds that . Hence, and Γ ⊧ I : σ1 → σ1.
• If Γ ⊢ M : σ falls under (axiom ω), then we have Γ ⊢ M : ω. Let be an arbitrary model for CL∩. We have that ⟦M⟧ρ ∈ D and Aω = D. From this we obtain , that is .
• Let be the last rule used and a model which satisfies Γ. By the induction hypothesis, we have that the statement holds for premises Γ ⊢ M : σ → τ and Γ ⊢ N : σ, i.e., Γ ⊧ M : σ → τ and Γ ⊧ N : σ. From the induction hypothesis and the assumption , we obtain and . The former implies and the latter implies . Thus, it holds that , and we obtain .
• Let be the last rule used and a model of Γ. By the induction hypothesis we have , which implies that holds. Since Aσ∩τ = Aσ ∩ Aτ by Definition 3.1, we have . Thus, we conclude .
• If the last rule used is the proof proceeds similarly as in the previous case.
• Let be the last rule used and a model of Γ. By the induction hypothesis we obtain and . The former implies that holds, and the latter implies that holds. Since Aσ ∩ Aτ = Aσ∩τ by Definition 3.1, we have . Finally, we conclude .
• Let be the last rule used and a model which satisfies the basis Γ. By the induction hypothesis we obtain that the statement holds for the premise, i.e., Γ ⊧ M : σ and since we have that . The latter implies . By Definition 3.1 we know that σ ≤ τ implies Aσ ⊆ Aτ. Hence, it holds that , and we can conclude .
• Let be the last rule used and a model of Γ. By the induction hypothesis we have , which implies that holds. From M =η N, that is M = N is provable in , and Theorem 4.1 we obtain ⟦M⟧ρ = ⟦N⟧ρ. Thus, we can conclude , that is .
• This concludes the proof.
□
Remark 4.5. As pointed out in Section 3, we have defined an environment as a total mapping, whereas in Kašterović and Ghilezan (2020) an environment was defined as a partial mapping. Every combinatory term is typable with the type ω, i.e., Γ ⊢ M : ω for any basis Γ, and in order to obtain the soundness of the type-assignment system we need to prove that M : ω holds in every model. Thus, we had to define environments so that the meaning of every term M is defined in all models. This is specific to intersection type systems and is due to the rule (axiom ω) which ensures typability of all terms.
We define a class of canonical models, following the approach used in Kašterović and Ghilezan (2020), in order to prove the completeness of the type-assignment system CL∩ with respect to the models presented in Section 3. Each canonical model is defined with respect to some basis, so that it satisfies only statements that can be derived from that basis. More precisely, we will define a model such that
Definition 4.6. Let Γ be a basis. A canonical model is a pair , where
such that
• D = {[M] ∣ M ∈ CL},
• Aσ = {[M] ∣ M ∈ CL and Γ ⊢ M : σ},
• App([M], [N]) = [MN],
and ρ⋆(x) = [x].
Lemma 4.7. The canonical model is a model for CL∩.
Proof. We need to prove that the tuple introduced in Definition 4.6 satisfies the conditions of Definition 3.5. First, we prove that is an applicative structure. The set D is a non-empty set. The set Aσ = {[M] ∣ M ∈ CL and Γ ⊢ M : σ} is a subset of D = {[M] ∣ M ∈ CL}. For every CL-term M we have Γ ⊢ M : ω, thus Aω = {[M] ∣ M ∈ CL and Γ ⊢ M : ω} = {[M] ∣ M ∈ CL} = D. The proofs that the family {Aσ} and the application function App satisfy the conditions of Definition 3.1 are obtained similarly as in the proof of Theorem 4.3.
We have proved that the tuple is an applicative structure. Next, we prove that it has combinators and that it is extensional. Similarly as in the proof of Theorem 4.3 we denote equivalence classes [S], [K], [I] by s, k, i, respectively. From the type-assignment system (Figure 2) we know that for the basis Γ, Γ ⊢ S:(σ → (τ → ρ)) → ((σ → τ) → (σ → ρ)). From the latter it follows that s = [S] ∈ A(σ → (τ → ρ)) → ((σ → τ) → (σ → ρ)). Similarly, we obtain k = [K] ∈ Aσ → (τ → σ) and i = [I] ∈ Aσ → σ. The proof that elements [S], [K], [I] satisfy Equations (1)–(3) is given in the proof of Theorem 4.3.
We have proved that the applicative structure introduced in Definition 4.6 has combinators. The proof that the applicative structure is extensional is the same as in the proof of Theorem 4.3.
The mapping ρ⋆ defined by ρ⋆(x) = [x] is an environment for the applicative structure .
This completes the proof that is a model for CL∩.□
Lemma 4.8. Let be the canonical model. For every CL-term M, it holds .
Proof. This is a straightforward consequence of Lemma 4.2.□
Theorem 4.9. Let be a canonical model. It holds that
Proof. By Definition 4.6 and Lemma 4.8 we obtain
□
Theorem 4.10 (Completeness of CL∩). If Γ ⊧ M : σ, then Γ ⊢ M : σ.
Proof. Suppose that Γ ⊧ M : σ. Let be a canonical model (Definition 4.6). First, we need to prove that . Let x : σ be a declaration from the basis Γ. By Lemma 4.8 and Definition 4.6 we have
It follows that . From the latter and the assumption Γ ⊧ M : σ we obtain . By Theorem 4.9 we obtain Γ ⊢ M : σ.□
Theorems 4.4 and 4.10 prove that the type-assignment system CL∩ is both sound and complete with respect to the proposed semantics. Hence the proposed semantics is a semantics of the combinatory logic with intersection types and of the untyped combinatory logic, as proven in Section 4.1.
5. Discussion and Conclusion
Combinatory logic, both typed and untyped, found its application in different scientific fields of computer science, e.g., machine learning (Liang et al., 2010) and artificial intelligence (e.g., Garrette et al., 2015), cognitive representation (e.g., Pierre Desclés, 2004), program synthesis (e.g., Düdder et al., 2012). The development of these fields urge for the further development of combinatory logic, typed, and untyped. Combinatory logic with intersection types has been the object of several studies (Dezani-Ciancaglini and Hindley, 1992; Bunder, 2002; Rehof and Urzyczyn, 2011; Bimbó, 2012). In Dezani-Ciancaglini and Hindley (1992), two different formulations of intersection types for combinatory logic are proposed and we consider in the paper one of these formulations. The authors proved that type-assignment statements are preserved by combinatory β-equality. A logic of intersection types is considered in Venneri (1994), by studying a logical characterization for the intersection-type discipline. The author presents a new formulation of the intersection type inference, equivalent to the original one, and then define a Hilbert-style axiomatization such that a formula is provable in the logical system if and only if it is an inhabited intersection type. Bunder (2002) also studies a logic of intersection types for lambda-terms and combinators by introducing a new system for intersection types, weaker than the one of Venneri (1994), and with the advantage that the logic of types can be obtained directly from the rules of the type-assignment system. None of these papers consider semantics for combinatory logic with intersection types. Models for combinatory logic with intersection types are presented in Bimbó (2012) along with the proof that the type-assignment system is sound and complete with respect to the presented models. Kripke-style semantics for lambda calculus and combinatory logic with types are introduced in Mitchell and Moggi (1991) and Kašterović and Ghilezan (2020). In Mitchell and Moggi (1991), calculi with simple types are considered, whereas in Kašterović and Ghilezan (2020) the authors considered full simply typed calculi. However, to the best of our knowledge the semantics we propose is novel.
We have introduced a semantics for combinatory logic with intersection types. As the main results of the paper we have proved that both the extensional equational theory of the untyped CL and the intersection type-assignment system CL∩ are sound and complete with respect to the proposed semantics.
The usual approach to the semantics for calculi with types that can be found in the literature, e.g., filter models for lambda calculus with intersection types (Barendregt et al., 1983), is based on a model for the untyped calculus endowed with a valuation of type variables which enables the interpretation of types to be defined inductively. We propose a different approach. In the semantics we propose, the interpretation of types is represented as a family of subsets that satisfies certain properties. Moreover, for a given valuation of term variables, the interpretation of terms is defined inductively, whereas in the previously mentioned semantics the interpretation of terms is defined as a function that satisfies specified conditions.
We plan to further develop this approach to lambda calculus, to different frameworks in logic and computation, e.g., polymorphic types.
Data Availability Statement
The original contributions presented in the study are included in the article/supplementary materials, further inquiries can be directed to the corresponding author/s.
Author Contributions
Both authors listed have made a substantial, direct, and intellectual contribution to the work and approved it for publication.
Funding
This research reported in the paper is partly supported by the Science Fund Republic of Serbia #6526707 AI4TrustBC.
Conflict of Interest
The authors declare that the research was conducted in the absence of any commercial or financial relationships that could be construed as a potential conflict of interest.
Publisher's Note
All claims expressed in this article are solely those of the authors and do not necessarily represent those of their affiliated organizations, or those of the publisher, the editors and the reviewers. Any product that may be evaluated in this article, or claim that may be made by its manufacturer, is not guaranteed or endorsed by the publisher.
Acknowledgments
The authors would like to thank the referees whose suggestions lead to major improvements.
References
Barbanera, F., Dezani-Ciancaglini, M., and de'Liguoro, U. (1995). Intersection and union types: syntax and semantics. Inf. Comput. 119, 202–230. doi: 10.1006/inco.1995.1086
Barendregt, H. P. (1985). The Lambda Calculus - Its Syntax and Semantics, Volume 103 of Studies in Logic and the Foundations of Mathematics. Elsevier: North-Holland.
Barendregt, H. P., Coppo, M., and Dezani-Ciancaglini, M. (1983). A filter lambda model and the completeness of type assignment. J. Symb. Logic. 48, 931–940. doi: 10.2307/2273659
Barendregt, H. P., Dekkers, W., and Statman, R. (2013). Lambda Calculus With Types. Perspectives in Logic. Cambridge: University Press. doi: 10.1017/CBO9781139032636
Bimbó, K. (2012). Combinatory Logic: Pure, Applied, and Typed. Boca Raton, FL: CRC Press; Taylor & Francis Group. doi: 10.1201/b11046
Bunder, M. W. (2002). Intersection types for lambda-terms and combinators and their logics. Log. J. IGPL 10, 357–378. doi: 10.1093/jigpal/10.4.357
Church, A. (1936). An unsolvable problem of elementary number theory. Am. J. Math. 58, 345–363. doi: 10.2307/2371045
Coppo, M., and Dezani-Ciancaglini, M. (1978). A new type assignment for λ-terms. Arch. Math. Log. 19, 139–156. doi: 10.1007/BF02011875
Coppo, M., Dezani-Ciancaglini, M., and Venneri, B. (1980). “Principal type schemes and lambda-calculus semantics,” in H.B.Curry: Essays on Combinatory Logic, Lambda-Calculus and Formalism (San Diego, CA: Academic Press), 535–560.
Curry, H. B. (1930). Grundlagen der kombinatorischen logik. Am. J. Math. 52, 509–536. doi: 10.2307/2370619
de Carvalho, D. (2018). Execution time of λ-terms via denotational semantics and intersection types. Math. Struct. Comput. Sci. 28, 1169–1203. doi: 10.1017/S0960129516000396
de'Liguoro, U., and Treglia, R. (2019). “Intersection types for the computational lambda-calculus,” in Proceedings of the 20th Italian Conference on Theoretical Computer Science, ICTCS 2019, eds A. Cherubini, N. Sabadini, and S. Tini (Como), 184–189.
Dezani-Ciancaglini, M., and Hindley, J. R. (1992). Intersection types for combinatory logic. Theor. Comput. Sci. 100, 303–324. doi: 10.1016/0304-3975(92)90306-Z
Dezani-Ciancaglini, M., and Margaria, I. (1984). “F-semantics for intersection type discipline,” in Semantics of Data Types, International Symposium Sophia-Antipolis, Vol. 173 of Lecture Notes in Computer Science, eds G. Kahn, D. B. MacQueen, and G. D. Plotkin (Berlin; Heidelberg: Springer), 279–300. doi: 10.1007/3-540-13346-1_14
Düdder, B., Martens, M., Rehof, J., and Urzyczyn, P. (2012). “Bounded combinatory logic,” in Computer Science Logic (CSL'12) - 26th International Workshop/21st Annual Conference of the EACSL, CSL 2012, Vol. 16 of LIPIcs, eds P. Cégielski and A. Durand (Fontainebleau: Schloss Dagstuhl - Leibniz-Zentrum für Informatik), 243–258.
Garrette, D., Dyer, C., Baldridge, J., and Smith, N. A. (2015). “Weakly-supervised grammar-informed Bayesian CCG parser learning,” in Proceedings of the Twenty-Ninth AAAI Conference on Artificial Intelligence, eds B. Bonet and S. Koenig (Austin, TX: AAAI Press), 2246–2252.
Hindley, J. R., and Seldin, J. P. (1986). Introduction to Combinators and Lambda-Calculus. Cambridge: Cambridge University Press.
Kašterović, S., and Ghilezan, S. (2020). Kripke-style semantics and completeness for full simply typed lambda calculus. J. Log. Comput. 30, 1567–1608. doi: 10.1093/logcom/exaa055
Liang, P., Jordan, M. I., and Klein, D. (2010). “Learning programs: a hierarchical Bayesian approach,” in Proceedings of the 27th International Conference on Machine Learning (ICML-10), eds J. Fürnkranz and T. Joachims (Haifa: Omnipress), 639–646.
Mitchell, J. C., and Moggi, E. (1991). Kripke-style models for typed lambda calculus. Ann Pure Appl. Logic 51, 99–124. doi: 10.1016/0168-0072(91)90067-V
Ong, C. L., and Tsukada, T. (2012). “Two-level game semantics, intersection types, and recursion schemes,” in Automata, Languages, and Programming - 39th International Colloquium, ICALP 2012, Vol. 7392 of Lecture Notes in Computer Science, eds A. Czumaj, K. Mehlhorn, A. M. Pitts, and R. Wattenhofer (Warwick: Springer), 325–336. doi: 10.1007/978-3-642-31585-5_31
Pierre Desclés, J. (2004). “Combinatory logic, language, and cognitive representations,” in Alternative Logics. Do Sciences Need Them?, ed P. Weingartner (Berlin: Springer Verlag), 115–148. doi: 10.1007/978-3-662-05679-0_9
Pottinger, G. (1980). “A type assignment for the strongly normalizable λ-terms,” in To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, eds J. P. Seldin and J. R. Hindley (London: Academic Press), 561–577.
Rehof, J., and Urzyczyn, P. (2011). “Finite combinatory logic with intersection types,” in Typed Lambda Calculi and Applications - 10th International Conference, TLCA 2011, Volume 6690 of Lecture Notes in Computer Science, ed C. L. Ong (Novi Sad: Springer), 169–183. doi: 10.1007/978-3-642-21691-6_15
Sallé, P. (1978). “Une extension de la théorie des types en lambda-calcul,” in 5th International Conference on Automata, Languages and Programming, ICALP'78, Vol. 62 of Lecture Notes in Computer Science, eds G. Ausiello and C. Böhm (Udine: Springer), 398–410. doi: 10.1007/3-540-08860-1_30
Schönfinkel, M. (1924). Über die bausteine der mathematischen logik. Math. Ann. 92, 305–316. doi: 10.1007/BF01448013
van Bakel, S., Barbanera, F., and de'Liguoro, U. (2018). Intersection types for the lambda-mu calculus. arXiv:1704.00272. doi: 10.48550/arXiv.1704.00272
Venneri, B. (1994). Intersection types as logical formulae. J. Log. Comput. 4, 109–124. doi: 10.1093/logcom/4.2.109
Keywords: computational systems, combinatory logic, equational theory, type theory, intersection types, soundness, completeness, semantics
Citation: Ghilezan S and Kašterović S (2022) Semantics for Combinatory Logic With Intersection Types. Front. Comput. Sci. 4:792570. doi: 10.3389/fcomp.2022.792570
Received: 10 October 2021; Accepted: 17 June 2022;
Published: 12 July 2022.
Edited by:
Jonni Virtema, The University of Sheffield, United KingdomReviewed by:
Marcos Cramer, Technical University Dresden, GermanyHarsh Beohar, The University of Sheffield, United Kingdom
Copyright © 2022 Ghilezan and Kašterović. This is an open-access article distributed under the terms of the Creative Commons Attribution License (CC BY). The use, distribution or reproduction in other forums is permitted, provided the original author(s) and the copyright owner(s) are credited and that the original publication in this journal is cited, in accordance with accepted academic practice. No use, distribution or reproduction is permitted which does not comply with these terms.
*Correspondence: Silvia Ghilezan, Z3NpbHZpYSYjeDAwMDQwO3Vucy5hYy5ycw==