<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Properties of a Computational Lambda Calculus for Higher-Order Relational Queries</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Claudio Sacerdoti Coen</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Riccardo Treglia</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Università di Bologna</institution>
          ,
          <addr-line>Bologna, Italy, Mura Anteo Zamboni, 7, 40126 Bologna (BO)</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>We study the operational semantics of an untyped computational lambda calculus whose normal forms represent queries on databases. The calculus extends the computational core with additional operations and rewriting rules whose efect is to turn the monadic type of computations into a multiset monad that captures tables. Moreover, we introduce comonadic constructs and additional rewriting rules to be able to form tables of tables. Proving confluence becomes tricky: we succeed exploiting decreasing diagrams. In the second part, we study a Curry style type assignment system for the calculus. We introduce an idempotent intersection type system establishing type invariance under conversion.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Lambda calculus</kwd>
        <kwd>Monads</kwd>
        <kwd>Confluence</kwd>
        <kwd>Intersection Types</kwd>
        <kwd>Databases</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        add two more co-monadic constructs to reflect computations into values, following ideas
by [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. These constructs are the thunk/force constructs of Levy’s call-by-push-value
calculus [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]; however, our calculus is strong, i.e., it allows reduction inside values as well.
Finally, we introduce an equational theory over computations to capture associativity
and commutativity of ⊎ and idempotency of ∅: this is the minimal theory that turns the
calculus into a confluent one.
      </p>
      <p>
        The calculus we are going to introduce takes inspiration from the (untyped) NRC
calculus [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], and it is to it as  © is to the (untyped)  -calculus. Indeed, we introduce it
with the intent of studying semantic properties of the NRC -calculus via intersection
types, trying to scale what the second author already did for  ©, thus providing an
explicit monadic formulation of Ricciotti et al’s calculus.
      </p>
      <p>Because of the important application to databases, from now on we call our extension
of the  ©-calculus the   -calculus.</p>
      <p>
        Intersection Types were introduced by Coppo and Dezani-Ciancaglini in the late 70’s
[
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] to overcome the limitations of Curry’s type discipline and enlarge the class of terms
that can be typed. This is reached by means of a new type constructor, the intersection.
Thus, one can assign a finite set of types to a term, thus providing a form of finite, ad
hoc polymorphism.
      </p>
      <p>In the same way that simple types guarantee termination, intersection types do the
same. However, they also characterize termination, that is, they type all terminating
 -terms. Intersection types have also a very elegant semantic flavour, since they may be
seen as a syntactic presentation of denotational models. Notwithstanding, here we do
not delve into the denotational semantics of the calculus, and keep the treatment at the
syntactical level. In fact, intersection types have shown to be remarkably flexible, since
diferent termination forms can be characterized by tuning details of the type system ( e.g.,
weak/strong normalization, head/weak/call-by-value evaluation). In the present work,
we introduce an idempotent intersection type discipline and prove it enjoys the subject
convertibility, i.e., the type is preserved not only by reduction, but also by expansion.
This is the key property to reach the soundness and completeness results of the type
system with respect to termination.</p>
      <p>
        To get an account of the history and expressivity of intersection types, see for example
the recent survey by Bono and Dezani-Ciancaglini [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ].
      </p>
      <p>
        Contributions. The first contribution of the work is the design of the   -calculus
in Section 2, which goes beyond the mere efort to fit the NRC  into a well-assessed
monadic frame. Indeed, this can be considered as an experiment of extending  © with
algebraic operators (other cases are [
        <xref ref-type="bibr" rid="ref12 ref13">12, 13</xref>
        ]), but here it immediately highlights, for
example, the need to introduce other kinds of constructs, such as the comonadic unit,
that could be added to  © independently of the algebraic operators.
      </p>
      <p>
        The second contribution, treated in Section 3, is the proof of a fundamental property
of the calculus: confluence. The proof is labour-intensive because the rewriting rules
associated to algebraicity of the operators turn them into control operators: each operator
can capture its context and then erase or duplicate it, and many critical pairs arise.
Moreover, there is also the issue of the interplay between the equational theory and the
rewriting theory. Technically, we make strong use of van Oostrom’s decreasing diagram
technique [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ], the most dificult point of which is to find the order relation between the
labels of the calculus reduction rules. This will be done by considering orthogonal and
nested closures of certain reduction rules, inspired by the work in [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ], postponing in a
ifnal step the commutation with respect to the union operator.
      </p>
      <p>Section 4 is devoted to the third contribution: an idempotent, monadic, intersection
types assignment system, proved to enjoy subject convertibility. The intersection type
theory we present is monadic version of strict intersection types in the case the monad
into account is the multiset monad equipped with the possibility of reflect and reify types.
This contribution can be seen as a first step to characterize convergent terms of the
calculus and as a first move in obtaining a resource-aware type system for the calculus
into consideration.</p>
      <p>Future work and related ones are discussed in Section 5.</p>
    </sec>
    <sec id="sec-2">
      <title>2. Syntax and Reduction</title>
      <p>relation are reported below:
Definition 2.1 (Term syntax).</p>
      <p>The syntax of the untyped computational SQL  -calculus, shortly  
, and its reduction</p>
      <p>Val : , 
Com : , 
::=  | .
::= [ ] |  ⋆ 
| ⟨⟨ ⟩⟩
|

⊎ 
| ∅ | !
Like in  ©, terms are of either sorts Val and Com, representing values and computations,
respectively. Variables  , abstractions .
— where  is bound in 
— and the
constructors [ ] and  ⋆ 
, written return 
and 
»= 
in Haskell-like syntax,
respectively, form the syntax of  ©, which is agnostic on the interpretation of computations.
In</p>
      <p>, instead, computations are meant to be understood as tables, i.e., multisets of
values, and therefore [ ] is interpreted as the singleton whose only element is 
and ⋆
as the bind operator of the multiset monad. The binary and 0-ary operators ⊎ and ∅
are additionally used to construct tables. The pair of constructs ⟨⟨·⟩⟩ and ! are used to
reflect computations into labels, allowing to form tables of (reflected) tables. Note that
bound variables so that the capture avoiding substitution 
⟨⟨·⟩⟩ can be understood as the unit of a comonad. Terms are identified up to renaming of
{ /
} is always well defined;</p>
      <p>( ) denotes the set of free variables in  . Finally, like in  ©, application among
computations can be encoded by  
(.  ⋆</p>
      <p>), where  is fresh.</p>
      <p>≡  ⋆
Wrapping up, the syntax can be condensed in the motto:</p>
      <p>SQL ≈  © + operations over tables + monadic reification/reflection
with the latter extension being orthogonal to the second one.</p>
      <p>We are now in place to introduce the  
reduction relation, later closed under
contexts:
Definition 2.2 (Reduction). The reduction relation is the union of the following binary
relations over Com:
  )
⊎ )
⊎ )
∅1)
∅2)</p>
      <p>!)
 ) ( ⋆ .
(
 ⋆ .</p>
      <p>[ ] ⋆ .</p>
      <p>The first two rules, taken from  ©, are oriented monadic equations. The next two rules
capture algebraicity of the ⊎ operator, but only w.r.t. contexts made of ⋆ only (e.g.,
there is no rule (
⊎  ) ⊎  ↦→ (
⊎  ) ⊎ (
⊎  ) because that would be unsound for</p>
      <sec id="sec-2-1">
        <title>The reduction →− SQL (when it is clear from the context we omit the subscript) is</title>
        <p>the contextual closure of  SQL under computational contexts, where such contexts are
mutually defined with value contexts as follows:</p>
        <p>V ::= ⟨·Val⟩ | .</p>
        <p>C | ⟨⟨C⟩⟩
C ::= ⟨·Com⟩ | [V] | C ⋆  |  ⋆</p>
        <p>Value Contexts
V | C ⊎ 
|

⊎ C | !V</p>
        <p>Computation Contexts
Notice that the hole of each kind of context has to be filled in with a proper kind of term.</p>
        <p>
          We equip the calculus with a sound, but not complete, equational theory for multisets,
taken from [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ].
        </p>
        <p>Definition 2.3 (Equational theory  ).</p>
        <p>) 
)
⊎ 
∅ ⊎ ∅
= 
=
∅
⊎</p>
        <p>
          The exact choice of rewriting and equational rules that we pick seems rather arbitrary
at first: the empty set is not the neutral element of
⊎ and the monadic operations are not
forced to be completely algebraic (e.g., ⊎ does not commute with contexts that include
thunks or force). This choice was made in order to keep the calculus as close as possible
to the reference NRC calculus in [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ].
        </p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Route to Confluence</title>
      <p>postponed.</p>
      <p>We modularize the proof of confluence by first showing that the equational part can be
Getting rid of the equational theory. A classic tool to modularize a proof of confluence
is Hindley-Rosen lemma, stating that the union of confluent reductions is itself confluent
if they all commute with each other. Let us first define what commutation between a
reduction relation and an equational theory means, and then state that result properly.
Definition 3.1. Given a reduction relation →− and an equational theory = , we say that
→− commutes over = if for all , ,  such that  =  →−  , there exists  such
that  →−  =  .</p>
      <p>Lemma 3.2 (Hindley-Rosen). Let ℛ 1 and ℛ 2 be relations on the set  . If ℛ 1 and ℛ 2
are confluent and commute with each other, then ℛ 1 ∪ ℛ 2 is confluent.</p>
      <p>We will exploit that to focus just on the reduction relation while proving confluence.
Lemma 3.3. = commutes with →−.</p>
      <p>
        Hence, by Lemma 3.3 one needs just the confluence of
→− modulo  .
→− to assert the confluence of
Remark 3.4. One can be also interested in the modulo confluence, which is in general
diferent from the confluence modulo (see ch. 14 of [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ]). In fact, the equational theory
 induces an equivalence relation on computations Com, where the equivalence class
[ ] of an element a  consists of all elements  such that  =  . The set of all
equivalence classes, denoted by Com/ = , is called the quotient set of Com modulo  .
It is easy to see that in our specific case, even if we are not interested in it, confluence
modulo  implies the confluence of Com/ = .
      </p>
      <p>
        Decreasing diagram. Now that is possible to omit the equational theory induced by
Definition 2.3, we need to prove the commutation of all the reduction rules, and in
this intent, we use decreasing diagrams by van Oostrom [
        <xref ref-type="bibr" rid="ref14 ref17">14, 17</xref>
        ]. This is a powerful
and general tool to establish commutation properties, which reduces the problem of
showing commutation to a local test; in exchange of localization, the diagrams need to
be decreasing with respect to some labelling.
      </p>
      <sec id="sec-3-1">
        <title>Definition 3.5 (Decreasing, [14]). An rewriting relation ℛ is locally decreasing if there</title>
        <p>exist a presentation (, {→− } ∈ ) of ℛ and a well-founded strict order &gt; on  such that:
← · → ⊆ ←∨*→ · −→= · ∨←{*→} · ←=− · ←∨*→ ,
where ∨¯ = { ∈  | ∃ ∈ ¯.  &gt;  }, ∨ abbreviates ∨{ }, and →−* (resp. ←*→ ) and −→=
(resp. ←=→ ) are the transitive and reflexive closures of the relation →− (resp. ↔).</p>
        <p>Let us give a hint about the above definition. The property of decreasiness is stated
for relations, seen as a family of labelled binary relations. Such labels are equipped with
a well-founded, strict, order such that every peak can be rejoined in a particular way,
regulated by that specific order on labels.</p>
        <p>The following theorem, due to van Oostrom, states that decreasiness implies confluence.
confluent.</p>
        <p>
          Theorem 3.6 (van Oostrom [
          <xref ref-type="bibr" rid="ref14 ref17">14, 17</xref>
          ]). Every locally decreasing rewriting relation ℛ
is
        </p>
        <p>
          In [
          <xref ref-type="bibr" rid="ref14">14</xref>
          ], the method is guaranteed to be complete in the sense that any (countable)
confluent rewrite relation can be equipped with such a labelling. But by undecidability of
confluence completeness also entails that finding such a labelling is, in general, dificult.
So to prove confluence of the relation in Definition 2.2 one needs to prove it decreasing
with respect to some labelling. This means rearranging the family in such a way that the
union is still the relationship we want to prove the confluence of, but the indices of the
family are rearranged to comply with a labelling that fits the definition of decreasiness.
        </p>
        <sec id="sec-3-1-1">
          <title>Which order?</title>
          <p>Now the point is to find a proper labelling and a strict order on that
labelling that satisfies the property of decreasiness. If one considers diagrams involving
as labels of potential labellings. Consider, for instance, the following diagram:
rules of ⊎ or ⊎ vs. ∅1 and ∅2, it is easy to perceive how these rules should be ordered
( 1 ⊎  2) ⋆ . ∅
- ( 1 ⋆ . ∅) ⊎ ( 2 ⋆ . ∅</p>
          <p>)
⊎
∅
∅
2
2
2
∅
(( 1 ⊎  2) ⋆ .</p>
        </sec>
      </sec>
      <sec id="sec-3-2">
        <title>In fact, the rules concerning the empty table, ∅1 and ∅2, can be bottom elements of the</title>
        <p>order over labels we are searching for (read it as: these rules can always be postponed at
the end of a reduction sequence).
 .</p>
      </sec>
      <sec id="sec-3-3">
        <title>When it comes to comparing ⊎ vs.  , the situation is a bit trickier because ⊎ only quasi-commutes over  . The following diagrams show that ⊎ must be made greater than</title>
        <p>. ( ⋆ .
Indeed,</p>
        <p>)).
where  ¯1 = (( 1 ⋆ .
) ⊎ ( 2 ⋆ .
),  ¯2 = ( 1 ⋆ .
)) ⊎ ( 2 ⋆</p>
        <p>The case for   vs ⊎ , however, shows the need for a non-trivial approach, since
depending on which context the rules are applied, we need either   &gt; ⊎ or   &lt; ⊎ .
⊎

·
)) ⋆ .

2
- ( 1 ⊎  2) ⋆ .</p>
        <p>The case for ⊎ vs. ⊎ can seem innocent, for example:
( 1 ⊎  2) ⋆ . ( 1 ⊎  2)</p>
        <p>- ( 1 ⋆ . ( 1 ⊎  2)) ⊎ ( 2 ⋆ . ( 1 ⊎  2))
⊎</p>
        <p>?
1) ⊎ (( 1 ⊎  2) ⋆ .
2)
⊎
2
⊎
(( 1 ⊎  2) ⋆ .
where  ¯ ≡ ( 1 ⋆ .
( 1 ⋆ . 1) ⊎ ( 1 ⋆ .
1) ⊎ ( 2 ⋆ .
2) ⊎ ( 2 ⋆ .
1) ⊎ ( 1 ⋆ .
1) ⊎ ( 2 ⋆ .
⊎ 2</p>
        <p>?
-  ¯ =  ^
2) ⊎ ( 2 ⋆ .
2)
2) and  ^ ≡
Remark 3.7. Actually, for more complex terms the diagram is not so elegant. Consider
for example the term  ≡ ( 1 ⊎  2) ⋆  (( 1 ⊎  2) ⊎  3). If one is seeking a modular
proof of confluence, it is possible to consider the rewriting system made by just the
rules ⊎ and ⊎ . Both together are weakly Church-Rosser (provable by easy induction)
and terminating (since the number of ⊎ symbols in a term is finite), thus by Newman’s
Lemma, the rewrite system is Church-Rosser. By the way, we are searching for the right
application of van Oostrom’s decreasing diagram, hence we are to introduce a generalized
version of ⊎ and ⊎ , respectively.</p>
      </sec>
      <sec id="sec-3-4">
        <title>Definition 3.8 (Generalized union step). Let us define as generalized ⊎ and ⊎ steps as</title>
        <p>follows</p>
        <p>
          Gen ⊎ ) (. . . ( 1 ⊎  2) ⊎ . . . ⊎   ) ⋆ . ↦→Gen⊎
Gen ⊎ )  ⋆ . (. . . ( 1 ⊎  2) ⊎ . . . ⊎   ) ↦→Gen⊎
( ⋆ .
( ⋆ .
) ⊎ ( 2 ⋆ .
1) ⊎ ( ⋆ .
) ⊎ . . . ⊎ (  ⋆ .
2) ⊎ . . . ⊎ ( ⋆ .
)
 )
Multi-reduction. The confluence proof we are going to sketch avoids the issue with   vs.
⊎ reported above by considering multiple reductions. Roughly speaking, this means that
we consider a labelling that comprehends reduction rules that can perform simultaneously
in many ’parts’ of the term, called formally positions. For a fair formalization of these
basic notions of rewriting theory, please see, e.g., [
          <xref ref-type="bibr" rid="ref18">18</xref>
          ].
        </p>
        <p>A parallel rewrite step is a sequence of reductions at a set  of parallel positions,
ensuring that the result does not depend upon a particular sequentialization of  . Given
a reduction step  we define its parallel version as Par .</p>
        <p>We are now ready to state our main result:
Theorem 3.9 (Confluence) .</p>
        <p>is confluent.</p>
        <p>Proof sketch. 1. All reduction rules strongly commute with !: proved by tedious
inspection of all cases.
2. Under the following order for parallel rewriting steps, all remaining rules are
decreasing as well: also proved by tedious inspection of all cases.</p>
        <p>Par  &gt; Par &gt;</p>
        <p>ParGen⊎ &gt; ParGen⊎ &gt; ∅1 &gt; ∅2</p>
      </sec>
      <sec id="sec-3-5">
        <title>The diagrams for the cases Par⊎ vs Par⊎ and Par⊎ vs ∅1 only hold up to  .</title>
        <p>
          E.g., ∅ ∅1← ∅ ⋆ . ⊎  →−⊎ →−2∅1 ∅ ⊎ ∅.
3. Confluence is obtained combining the previous points with Lemma 3.3 and
Theorem 3.6, following [
          <xref ref-type="bibr" rid="ref15">15</xref>
          ].
        </p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. The Intersection Type Assignment System</title>
      <p>
        Intersection types are an extension of Curry’s simple type assignment system to untyped
 -terms, obtained by adding new types  ∧  ′ to be assigned to terms that have both type
 and  ′. Intersection type assignment systems form a whole family in the literature; see
[
        <xref ref-type="bibr" rid="ref19">19</xref>
        ] part III. What all these families have in common is that intersection types embody a
sort of ad hoc polymorphism, in which the conjunction of semantically unrelated types
can be contemplated. An advantage is having the ability to assign two diferent types
to two distinct occurrences of a variable, which allows more terms to be typed, thus
enlarging the class of terms that can be typed by Curry’s type discipline.
      </p>
      <p>
        In building an intersection type discipline for   , we actually do not extend the
system in [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] (i.e., we do not consider a type theory with subtyping in the BCD fashion,
[
        <xref ref-type="bibr" rid="ref20">20</xref>
        ]). In fact, we present a syntax-directed type assignment system, without subtyping,
to type tables and operations of merging tables, by specializing the generic monad  to
the multiset monad (the semantical understanding of this will be the focus of a companion
paper). Specifically, we adapt strict intersection type theory as in [
        <xref ref-type="bibr" rid="ref21 ref22">21, 22</xref>
        ] to the case
of   , meaning that the introduction of intersection is restricted merely to values.
We introduce two sorts of types corresponding to the two sorts of terms in Definition
2.1, and a third kind, called blind types, inspired by [23], typing particular occurrences
of values. The choices to avoid subtyping, and hence the proof of a generation lemma
(also named ’inversion lemma’, typical lemma needed in intersection type disciplines
with subtyping, see [
        <xref ref-type="bibr" rid="ref19">19</xref>
        ]), and to introduce a third layer of types, the blind types ones,
that at this stage are pleonastic, have been made to smoothly move in a future step to
a quantitative version of the present type system obtained via non-idempotent, strict
intersection [24].
      </p>
      <p>Definition 4.1 (Intersection Types Syntax). Let  range over a countable set of type
variables (the atoms); then we define three sorts of types by mutual induction as follows:</p>
      <p>ValType : 
ComType : 
BlindType : 
::=</p>
      <p>∧∅ →− 
::=  |  →  | ⋀︀  ≥0  | ⟨⟨ ⟩⟩ (value types)
::= [ ] | ∅^ |  ⊎ 
(computation types)
(blind types)</p>
      <sec id="sec-4-1">
        <title>We assume that ∧ and ⊎ take precedence over →− and that →− associates to the right, so that  →−  ∧  ′ reads as  →− ( ∧  ′), and  →−  ⊎  ′ reads as  →− ( ⊎  ′). We note the empty intersection as ∧∅.</title>
      </sec>
      <sec id="sec-4-2">
        <title>We introduce the emptyset type ∅^ , as a constant, and should not be mistaken as</title>
        <p>the symbol for an empty union. As for the terms, we equip computational types in
Definition 4.1 with an equational theory stating the commutativity of union and the
idempotency of the emptyset type ∅^ w.r.t. the union of types. We then introduce for
all the computational types  a boolean predicate emptyin( ), that is true if and only
if ∅^ ∈  . In such a way, we can speak of canonical form of computational types for
 SQL: it is easy to see that for every  ∈ ComType there exists a canonical form (up to
commutativity of union) ⨄︀  ≥0[  ] ⊎ ∅^ if emptyin( ), or ⨄︀ &gt; 0[  ], otherwise. These forms
will be used in type assignment systems to clarify and handle generic computational
types when needed.</p>
        <sec id="sec-4-2-1">
          <title>Type Assignment System.</title>
          <p>system for   .</p>
          <p>We are now in place to introduce the type assignment
Definition 4.2 (Type assignment). A basis is a finite set of typings Γ = { 1 :  1, . . .   :   }
with pairwise distinct variables   , whose domain is the set  (Γ) = { 1, . . . ,   }. A
basis determines a function from variables to types such that Γ( ) =  if  :  ∈ Γ, Γ( )
is the empty intersection ∧∅, otherwise.</p>
          <p>A judgment is an expression of either shapes: Γ ⊢  :  or Γ ⊢  :  . It is derivable
if it is the conclusion of a derivation according to the rules in Figure 1.</p>
          <p>The blind types to which we are taking inspiration are the ones presented by Kesner
et al. in [23, 25] to grant strong normalization even in the presence of terms whose
occurrences will all be erased during computation. The intersection types discipline
assigns to terms being erased ∧∅ and therefore the terms would not be typed, not
capturing their divergence. Instead, we type them with a blind type, which states that
the term will not receive at runtime any input to be used and it can return any output.
 :  ∈ Γ
Γ ⊢  :</p>
          <p>(Ax)
Γ ⊢  : 
Γ ⊢ ⟨⟨ ⟩⟩ : ⟨⟨ ⟩⟩</p>
          <p>Γ ⊢  : 
Γ ⊢ .</p>
          <p>: Γ( ) →− 
(Γ ⊢  :   ) =1,...,
Γ ⊢  :

︁⋀</p>
          <p>The union operator for types is introduced just for computations as regulated in rule
(⊎ I). The introduction of bind is split in two, depending on the cases in which the type
associated with the computation is just an empty union type or not. In fact, in the case
of (⋆∅ I) we explicitly ask for the value to have an empty intersection to deal with the
case the computation has just the empty union type. The rule (⋆ I), instead, takes care
of the case in which the computation has non empty union type ( is strictly greater
than 0) and possibly the empty union type (this is the meaning of ⨄︀
case, the empty union type, if it is in the premise, is propagated to the resulting type.
 ≤1 ∅^ ); in such a</p>
        </sec>
        <sec id="sec-4-2-2">
          <title>Results.</title>
          <p>We are now in place to state the main results of the presented type system.</p>
        </sec>
      </sec>
      <sec id="sec-4-3">
        <title>Theorem 4.3 (Subject Reduction). If Γ ⊢  :  and</title>
      </sec>
      <sec id="sec-4-4">
        <title>Theorem 4.4 (Subject Expansion). If Γ ⊢  :  and</title>
        <p>→−  , then Γ ⊢  :  .
→−  , then Γ ⊢  :  .</p>
        <p>The above theorems state two results: the first is the subject reduction, a desirable
property for all type systems. The second property, the subject expansion, on the other
hand, is typical of intersection types and the key to proving characterisation results. This
property, indeed, states that the type of a term is preserved even going backwards in its
reduction.</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>5. Conclusions</title>
      <p>
        In the present work, we have introduced a computational  -calculus  SQL as an extension of
the computational core  © [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. We have proved the confluence of the calculus and presented
an intersection type assignment system enjoying subject reduction and expansion.
      </p>
      <p>We leave for future works the full characterization of convergent terms, via soundness
and completeness of the type system, plus a deep investigation on the semantical level
via a filter model construction as in [26].</p>
      <p>
        Related works. As mentioned in the Introduction,  SQL stems from NRC calculus in [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ].
The first calculus is an example of nested, higher-order relational calculus that provides
a principled foundation for integrating database queries into programming languages. In
NRC , a database table is represented by the multiset of its rows, where each row is just
a value (NRC has tuples). The main properties of the calculus are that it is confluent
and strongly normalizing and, moreover, some normal forms can be directly interpreted
as SQL queries (those such that the types of the free variables and of the result are just
tables of base types and not tables of tables). In particular, the set of rewriting and
equational rules that our calculus inherits from the NRC -calculus is the minimal set
that grants the previous properties.
      </p>
      <p>
        In designing our type system, we were deeply influenced by the desire to reach a
quantitative type system for  SQL, and in doing so we took inspiration from [
        <xref ref-type="bibr" rid="ref13">24, 13</xref>
        ], since
our splitting rules in the presence/absence of the empty union type are reminiscent of
the persistent/consuming rules in the cited works.
      </p>
      <p>
        We find that our calculus and type system have substantial connections with dependent
type systems, even if not yet explored in detail. This is the case with the intuition
borrowed from [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ] in proving confluence and with [ 27] where a dependent intersection
type system is presented. Linking our types to the last cited work, it is easy to notice
that our types stand to that system as the lists stand to the natural numbers, where the
bind in fact is the iterator. As said, we leave a deepening of these insights for future
work.
      </p>
      <p>Long-term perspectives. Considering the structure of the present work, we set two
long-term goals. The first is related to the confluence proof based on decreasing diagrams
in Section 3, since the labelling extracts an order over reduction rules to design a
well-behaved normalizing strategy.</p>
      <p>Concerning the type system, our idempotent intersection type one is just a mid-term
objective, since we are interested in defining an appropriate intersection type system based
on tight multi-types [28] to capture quantitatively the set of terminating queries according
to strategy extracted from the confluence proof. Such non-idempotent type systems have
been proven to be useful in detecting the length of normalizing reductions and the size of
the normal forms, which in our case is the size of the computed SQL queries, via the type
system itself. As a result, extending such non-idempotent intersection type disciplines
for   should capture even more quantitative, computational information about the
queries themselves.</p>
    </sec>
    <sec id="sec-6">
      <title>Acknowledgments</title>
      <p>We would like to thank th reviewers for taking the necessary time and efort to review
the manuscript. We sincerely appreciate all your valuable comments and suggestions,
which helped us in improving the quality of the manuscript.
[23] D. Kesner, P. Vial, Consuming and persistent types for classical logic, in: H.
Hermanns, L. Zhang, N. Kobayashi, D. Miller (Eds.), LICS ’20: 35th Annual ACM/IEEE
Symposium on Logic in Computer Science, Saarbrücken, Germany, July 8-11,
2020, ACM, 2020, pp. 619–632. URL: https://doi.org/10.1145/3373718.3394774.
doi:10.1145/3373718.3394774.
[24] D. Kesner, A. Viso, Encoding tight typing in a unified framework, in: F. Manea,
A. Simpson (Eds.), 30th EACSL Annual Conference on Computer Science Logic, CSL
2022, February 14-19, 2022, Göttingen, Germany (Virtual Conference), volume 216
of LIPIcs, Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2022, pp. 27:1–27:20.
URL: https://doi.org/10.4230/LIPIcs.CSL.2022.27. doi:10.4230/LIPIcs.CSL.2022.
27.
[25] D. Kesner, P. Vial, Non-idempotent types for classical calculi in natural
deduction style, Log. Methods Comput. Sci. 16 (2020). URL: https://doi.org/10.23638/
LMCS-16(1:3)2020. doi:10.23638/LMCS-16(1:3)2020.
[26] U. de’Liguoro, R. Treglia, From semantics to types: The case of the imperative
 -calculus, Theor. Comput. Sci. 973 (2023) 114082. URL: https://doi.org/10.1016/j.
tcs.2023.114082. doi:10.1016/j.tcs.2023.114082.
[27] U. D. Lago, M. Gaboardi, Linear dependent types and relative completeness, Log.</p>
      <p>Methods Comput. Sci. 8 (2011). URL: https://doi.org/10.2168/LMCS-8(4:11)2012.
doi:10.2168/LMCS-8(4:11)2012.
[28] B. Accattoli, S. Graham-Lengrand, D. Kesner, Tight typings and split bounds,
fully developed, J. Funct. Program. 30 (2020) e14. URL: https://doi.org/10.1017/
S095679682000012X. doi:10.1017/S095679682000012X.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <surname>U. de'Liguoro</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          <string-name>
            <surname>Treglia</surname>
          </string-name>
          , The untyped computational
          <article-title>-calculus and its intersection type discipline</article-title>
          ,
          <source>Theor. Comput. Sci</source>
          .
          <volume>846</volume>
          (
          <year>2020</year>
          )
          <fpage>141</fpage>
          -
          <lpage>159</lpage>
          . URL: https://doi.org/10. 1016/j.tcs.
          <year>2020</year>
          .
          <volume>09</volume>
          .029. doi:
          <volume>10</volume>
          .1016/j.tcs.
          <year>2020</year>
          .
          <volume>09</volume>
          .029.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>C.</given-names>
            <surname>Faggian</surname>
          </string-name>
          , G. Guerrieri, U. de' Liguoro,
          <string-name>
            <given-names>R.</given-names>
            <surname>Treglia</surname>
          </string-name>
          ,
          <article-title>On reduction and normalization in the computational core</article-title>
          ,
          <source>Mathematical Structures in Computer Science</source>
          <volume>32</volume>
          (
          <year>2022</year>
          )
          <fpage>934</fpage>
          -
          <lpage>981</lpage>
          . doi:
          <volume>10</volume>
          .1017/S0960129522000433.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>E.</given-names>
            <surname>Moggi</surname>
          </string-name>
          ,
          <article-title>Computational lambda-calculus and monads</article-title>
          ,
          <source>in: Proceedings of the Fourth Annual Symposium on Logic in Computer Science (LICS '89)</source>
          , IEEE Computer Society,
          <year>1989</year>
          , pp.
          <fpage>14</fpage>
          -
          <lpage>23</lpage>
          . doi:
          <volume>10</volume>
          .1109/LICS.
          <year>1989</year>
          .
          <volume>39155</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>E.</given-names>
            <surname>Moggi</surname>
          </string-name>
          ,
          <article-title>Notions of computation and monads</article-title>
          ,
          <source>Inf. Comput</source>
          .
          <volume>93</volume>
          (
          <year>1991</year>
          )
          <fpage>55</fpage>
          -
          <lpage>92</lpage>
          . doi:
          <volume>10</volume>
          .1016/
          <fpage>0890</fpage>
          -
          <lpage>5401</lpage>
          (
          <issue>91</issue>
          )
          <fpage>90052</fpage>
          -
          <lpage>4</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>G. D.</given-names>
            <surname>Plotkin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Power</surname>
          </string-name>
          ,
          <article-title>Notions of computation determine monads</article-title>
          ,
          <source>in: FOSSACS</source>
          <year>2002</year>
          , volume
          <volume>2303</volume>
          of Lecture Notes in Computer Science, Springer,
          <year>2002</year>
          , pp.
          <fpage>342</fpage>
          -
          <lpage>356</lpage>
          . URL: https://doi.org/10.1007/3-540-45931-6_
          <fpage>24</fpage>
          . doi:
          <volume>10</volume>
          .1007/3-540-45931-6\ _
          <fpage>24</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>G. D.</given-names>
            <surname>Plotkin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Power</surname>
          </string-name>
          ,
          <article-title>Algebraic operations and generic efects</article-title>
          ,
          <source>Appl. Categorical Struct</source>
          .
          <volume>11</volume>
          (
          <year>2003</year>
          )
          <fpage>69</fpage>
          -
          <lpage>94</lpage>
          . doi:
          <volume>10</volume>
          .1023/A:
          <fpage>1023064908962</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>A.</given-names>
            <surname>Filinski</surname>
          </string-name>
          ,
          <article-title>Representing monads</article-title>
          , in: H.
          <string-name>
            <surname>Boehm</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          <string-name>
            <surname>Lang</surname>
            ,
            <given-names>D. M.</given-names>
          </string-name>
          <string-name>
            <surname>Yellin</surname>
          </string-name>
          (Eds.),
          <source>Conference Record of POPL'94: 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Portland</source>
          , Oregon, USA, January
          <volume>17</volume>
          -
          <issue>21</issue>
          ,
          <year>1994</year>
          , ACM Press,
          <year>1994</year>
          , pp.
          <fpage>446</fpage>
          -
          <lpage>457</lpage>
          . URL: https://doi.org/10.1145/174675.178047. doi:
          <volume>10</volume>
          .1145/174675.178047.
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <surname>P. B. Levy</surname>
          </string-name>
          ,
          <article-title>Call-by-push-value: A subsuming paradigm</article-title>
          ,
          <source>in: Typed Lambda Calculi and Applications, 4th International Conference (TLCA'99)</source>
          , volume
          <volume>1581</volume>
          of Lecture Notes in Computer Science,
          <year>1999</year>
          , pp.
          <fpage>228</fpage>
          -
          <lpage>242</lpage>
          . URL: https://doi.org/10.1007/ 3-540-48959-2_
          <fpage>17</fpage>
          . doi:
          <volume>10</volume>
          .1007/3-540-48959-2\_
          <fpage>17</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>W.</given-names>
            <surname>Ricciotti</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Cheney</surname>
          </string-name>
          ,
          <article-title>Strongly normalizing higher-order relational queries</article-title>
          ,
          <source>in: 5th International Conference on Formal Structures for Computation and Deduction</source>
          ,
          <string-name>
            <surname>FSCD</surname>
          </string-name>
          <year>2020</year>
          , June 29-July 6,
          <year>2020</year>
          , Paris, France (Virtual Conference),
          <year>2020</year>
          , pp.
          <volume>28</volume>
          :
          <fpage>1</fpage>
          -
          <lpage>28</lpage>
          :
          <fpage>22</fpage>
          . URL: https://doi.org/10.4230/LIPIcs.FSCD.
          <year>2020</year>
          .
          <volume>28</volume>
          . doi:
          <volume>10</volume>
          .4230/LIPIcs. FSCD.
          <year>2020</year>
          .
          <volume>28</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>M.</given-names>
            <surname>Coppo</surname>
          </string-name>
          ,
          <article-title>An extended polymorphic type system for applicative languages</article-title>
          , in: P. Dembinski (Ed.),
          <source>Mathematical Foundations of Computer Science 1980 (MFCS'80)</source>
          ,
          <source>Proceedings of the 9th Symposium, Rydzyna, Poland, September 1-5</source>
          ,
          <year>1980</year>
          , volume
          <volume>88</volume>
          of Lecture Notes in Computer Science, Springer,
          <year>1980</year>
          , pp.
          <fpage>194</fpage>
          -
          <lpage>204</lpage>
          . URL: https: //doi.org/10.1007/BFb0022505. doi:
          <volume>10</volume>
          .1007/BFb0022505.
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>V.</given-names>
            <surname>Bono</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Dezani-Ciancaglini</surname>
          </string-name>
          ,
          <article-title>A tale of intersection types</article-title>
          , in: H.
          <string-name>
            <surname>Hermanns</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          <string-name>
            <surname>Zhang</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          <string-name>
            <surname>Kobayashi</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          <string-name>
            <surname>Miller</surname>
          </string-name>
          (Eds.),
          <source>LICS '20: 35th Annual ACM/IEEE Symposium on Logic in Computer Science</source>
          , Saarbrücken, Germany, July 8-
          <issue>11</issue>
          ,
          <year>2020</year>
          , ACM,
          <year>2020</year>
          , pp.
          <fpage>7</fpage>
          -
          <lpage>20</lpage>
          . URL: https://doi.org/10.1145/3373718.3394733. doi:
          <volume>10</volume>
          .1145/ 3373718.3394733.
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <surname>U. de'Liguoro</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          <string-name>
            <surname>Treglia</surname>
          </string-name>
          ,
          <article-title>Intersection types for a  -calculus with global store</article-title>
          , in: N.
          <string-name>
            <surname>Veltri</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          <string-name>
            <surname>Benton</surname>
          </string-name>
          , S. Ghilezan (Eds.),
          <source>PPDP 2021: 23rd International Symposium on Principles and Practice of Declarative Programming</source>
          , Tallinn, Estonia, September 6-
          <issue>8</issue>
          ,
          <year>2021</year>
          , ACM,
          <year>2021</year>
          , pp.
          <volume>5</volume>
          :
          <fpage>1</fpage>
          -
          <lpage>5</lpage>
          :
          <fpage>11</fpage>
          . URL: https://doi.org/10.1145/3479394.3479400. doi:
          <volume>10</volume>
          .1145/3479394.3479400.
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>S.</given-names>
            <surname>Alves</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Kesner</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Ramos</surname>
          </string-name>
          ,
          <source>Quantitative global memory 13923</source>
          (
          <year>2023</year>
          )
          <fpage>53</fpage>
          -
          <lpage>68</lpage>
          . URL: https://doi.org/10.1007/978-3-
          <fpage>031</fpage>
          -39784-
          <issue>4</issue>
          _4. doi:
          <volume>10</volume>
          .1007/ 978-3-
          <fpage>031</fpage>
          -39784-4\_4.
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <surname>V. van Oostrom</surname>
          </string-name>
          ,
          <article-title>Confluence by decreasing diagrams</article-title>
          ,
          <source>Theor. Comput. Sci</source>
          .
          <volume>126</volume>
          (
          <year>1994</year>
          )
          <fpage>259</fpage>
          -
          <lpage>280</lpage>
          . URL: https://doi.org/10.1016/
          <fpage>0304</fpage>
          -
          <lpage>3975</lpage>
          (
          <issue>92</issue>
          )
          <fpage>00023</fpage>
          -
          <lpage>K</lpage>
          . doi:
          <volume>10</volume>
          .1016/
          <fpage>0304</fpage>
          -
          <lpage>3975</lpage>
          (
          <issue>92</issue>
          )
          <fpage>00023</fpage>
          -
          <lpage>K</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <given-names>A.</given-names>
            <surname>Assaf</surname>
          </string-name>
          , G. Dowek,
          <string-name>
            <given-names>J.-P.</given-names>
            <surname>Jouannaud</surname>
          </string-name>
          , J. Liu, Untyped Confluence In Dependent Type Theories (
          <year>2016</year>
          ). URL: https://inria.hal.science/hal-01515505.
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <surname>Terese</surname>
          </string-name>
          ,
          <article-title>Term rewriting systems</article-title>
          , volume
          <volume>55</volume>
          of Cambridge tracts in theoretical computer science, Cambridge University Press,
          <year>2003</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <surname>V. van Oostrom</surname>
          </string-name>
          ,
          <article-title>Confluence by decreasing diagrams converted</article-title>
          ,
          <source>in: Rewriting Techniques and Applications</source>
          , 19th International Conference,
          <source>RTA 2008„ volume 5117 of Lecture Notes in Computer Science</source>
          , Springer,
          <year>2008</year>
          , pp.
          <fpage>306</fpage>
          -
          <lpage>320</lpage>
          . doi:
          <volume>10</volume>
          . 1007/978-3-
          <fpage>540</fpage>
          -70590-1_
          <fpage>21</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          [18]
          <string-name>
            <given-names>F.</given-names>
            <surname>Baader</surname>
          </string-name>
          , T. Nipkow,
          <article-title>Term rewriting and all that</article-title>
          , Cambridge University Press,
          <year>1998</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          [19]
          <string-name>
            <given-names>H.</given-names>
            <surname>Barendregt</surname>
          </string-name>
          ,
          <string-name>
            <given-names>W.</given-names>
            <surname>Dekkers</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Statman</surname>
          </string-name>
          , Lambda Calculus with Types, Perspectives in Logic, Cambridge University Press,
          <year>2013</year>
          . doi:
          <volume>10</volume>
          .1017/CBO9781139032636.
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          [20]
          <string-name>
            <given-names>H.</given-names>
            <surname>Barendregt</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Coppo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Dezani-Ciancaglini</surname>
          </string-name>
          ,
          <article-title>A filter lambda model and the completeness of type assignment</article-title>
          ,
          <source>Journal of Symbolic Logic</source>
          <volume>48</volume>
          (
          <year>1983</year>
          )
          <fpage>931</fpage>
          -
          <lpage>940</lpage>
          . doi:
          <volume>10</volume>
          .2307/2273659.
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          [21]
          <string-name>
            <surname>S. van Bakel</surname>
          </string-name>
          ,
          <article-title>Intersection Type Disciplines in Lambda Calculus and Applicative Term Rewriting Systems</article-title>
          ,
          <source>Ph.D. thesis</source>
          , Department of Computer Science, University of Nijmegen,
          <year>1993</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref22">
        <mixed-citation>
          [22]
          <string-name>
            <surname>S. van Bakel</surname>
          </string-name>
          ,
          <article-title>Strict intersection types for the lambda calculus</article-title>
          ,
          <source>ACM Comput. Surv</source>
          .
          <volume>43</volume>
          (
          <year>2011</year>
          )
          <volume>20</volume>
          :
          <fpage>1</fpage>
          -
          <lpage>20</lpage>
          :
          <fpage>49</fpage>
          . URL: https://doi.org/10.1145/1922649.1922657. doi:
          <volume>10</volume>
          .1145/ 1922649.1922657.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>