Types by Need
Abstract
A cornerstone of the theory of \(\lambda \)calculus is that intersection types characterise termination properties. They are a flexible tool that can be adapted to various notions of termination, and that also induces adequate denotational models.
Since the seminal work of de Carvalho in 2007, it is known that multi types (i.e. nonidempotent intersection types) refine intersection types with quantitative information and a strong connection to linear logic. Typically, type derivations provide bounds for evaluation lengths, and minimal type derivations provide exact bounds.
De Carvalho studied callbyname evaluation, and Kesner used his system to show the termination equivalence of callbyneed and callbyname. De Carvalho’s system, however, cannot provide exact bounds on callbyneed evaluation lengths.
In this paper we develop a new multi type system for callbyneed. Our system produces exact bounds and induces a denotational model of callbyneed, providing the first tight quantitative semantics of callbyneed.
1 Introduction
Duplications and erasures have always been considered as key phenomena in the \(\lambda \)calculus—the \(\lambda I\)calculus, where erasures are forbidden, is an example of this. The advent of linear logic [38] gave them a new, prominent logical status. Forbidding erasure and duplication enables singleuse resources, i.e. linearity, but limits expressivity, as every computation terminates in linear time. Their controlled reintroduction via the nonlinear modality Open image in new window recovers the full expressive power of cutelimination and allows a fine analysis of resource consumption. Duplication and erasure are therefore the key ingredients for logical expressivity, and—via CurryHoward—for the expressivity of the \(\lambda \)calculus. They are also essential to understand evaluation strategies.
In a \(\lambda \)term there can be many \(\beta \)redexes, that is, places where \(\beta \)reduction can be applied. In this sense, the \(\lambda \)calculus is nondeterministic. Nondeterminism does not affect the result of evaluation, if any, but it affects whether evaluation terminates, and in how many steps. There are two natural deterministic evaluation strategies, callbyname (shortened to CbN) and callbyvalue (CbV), which have dual behaviour with respect to duplication and erasure.
CallbyName = Silly Duplication + Wise Erasure. CbN never evaluates arguments of \(\beta \)redexes before the redexes themselves. As a consequence, it never evaluates in subterms that will be erased. This is wise, and makes CbN a normalising strategy, that is, a strategy that reaches a result whenever one exists^{1}. A second consequence is that if the argument of the redex is duplicated then it may be evaluated more than once. This is silly, as it repeats work already done.
CallbyValue = Wise Duplication + Silly Erasure. CbV, on the other hand, always evaluates arguments of \(\beta \)redexes before the redexes themselves. Consequently, arguments are not reevaluated—this is wise with respect to duplication—but they are also evaluated when they are going to be erased. For instance, on Open image in new window , where \(\varOmega \) is the famous looping \(\lambda \)term, CbV evaluation diverges (it keeps evaluating \(\varOmega \)) while CbN converges in one \(\beta \)step (simply erasing \(\varOmega \)). This CbV treatment of erasure is clearly as silly as the duplicated work of CbN.
CallbyNeed = Wise Duplication + Wise Erasure. It is natural to try to combine the advantages of both CbN and CbV. The strategy that is wise with respect to both duplications and erasures is usually called callbyneed (CbNeed), it was introduced by Wadsworth [57], and dates back to the ’70s. Despite being at the core of Haskell, one of the mostused functional programming languages, and—in its strong variant—being at work in the kernel of Coq as designed by Barras [16], the theory of CbNeed is much less developed than that of CbN or CbV.
One of the reasons for this is that it cannot be defined inside the \(\lambda \)calculus without some hacking. Manageable presentations of CbNeed indeed require firstclass sharing and microstep operational semantics where variable occurrences are replaced one at a time (when needed), and not all at once as in the \(\lambda \)calculus. Another reason is the less natural logical interpretation.
Linear Logic, Names, Values, and Needs. CbN and CbV have neat interpretations in linear logic. They correspond to two different representations of intuitionistic logic in linear logic, based on two different representations of implication^{2}.
The logical interpretation of CbNeed—studied by Maraist et al. in [47]—is less neat than those of CbN and CbV. Within linear logic, CbNeed is usually understood as corresponding to the CbV representation where erasures are generalised to all terms, not only those under the scope of a Open image in new window modality. So, it is seen as a sort of affine CbV. Such an interpretation however is unusual, because it does not match exactly with cutelimination in linear logic, as for CbN and CbV.
CallbyNeed, Abstractly. The main theorem of the theory of CbNeed is that it is termination equivalent to CbN, that is, on a fixed term, CbNeed evaluation terminates if and only if CbN evaluation terminates, and, moreover, they essentially produce the same result (up to some technical details that are irrelevant here). This is due to the fact that both strategies avoid silly divergent sequences such as that of \((\lambda x.\lambda y.y) \varOmega \). Termination equivalence is an abstract theorem stating that CbNeed erases as wisely as CbN. Curiously, in the literature there are no abstract theorems reflecting the dual fact that CbNeed duplicates as wisely as CbV—we provide one, as a side contribution of this paper.
CallbyNeed and Denotational Semantics. CbNeed is then usually considered as a CbV optimisation of CbN. In particular, every denotational model of CbN is also a model of CbNeed, and adequacy—that is the fact that the denotation of \(t\) is not degenerated if and only if \(t\) terminates—transfers from CbN to CbNeed.
Denotational semantics is invariant by evaluation, and so is insensitive to evaluation lengths by definition. It then seems that denotational semantics cannot distinguish between CbN and CbNeed. The aim of this paper is, somewhat counterintuitively, to separate CbN and CbNeed semantically. We develop a type system whose type judgements induce a model—this is typical of intersection type systems—and whose type derivations provide exact bounds for CbNeed evaluation—this is usually obtained via nonidempotent intersection types. Unsurprisingly, the design of the type system requires a delicate mix of erasure and duplication and builds on the linear logic understanding of CbN and CbV.
Multi Types. Our typing framework is given by multi types, which is an alternative name for nonidempotent intersection types^{3}. Multi types characterise termination properties exactly as intersection types, having moreover the advantages that they are closely related to (the relational semantics of) linear logic, their type derivations provide quantitative information about evaluation lengths, and the proof techniques are simpler—no need for the reducibility method.
The seminal work of de Carvalho [23] (appeared in 2007 but unpublished until 2018, see also [22]) showed how to use multi types to obtain exact bounds on evaluation lengths in CbN. Ehrhard adapted multi types to CbV [34], and very recently Accattoli and Guerrieri adapted de Carvalho’s study of exact bounds to Ehrhard’s system and CbV evaluation [8]. Kesner used de Carvalho’s CbN multi types to obtain a simple proof that CbNeed is termination equivalent to CbN [40] (first proved with other techniques by Maraist, Odersky, and Wadler [48] and Ariola and Felleisen [11] in the nineties), and then Kesner and coauthors continued exploring the theory of CbNeed via CbN multi types [14, 15, 42].
Kesner’s use of CbN multi types to study CbNeed is qualitative, as it deals with termination and not with exact bounds. For a quantitative study of CbNeed, de Carvalho’s CbN system cannot really be informative: CbN multi types provide bounds for CbNeed which cannot be exact because they already provide exact bounds for CbN, which generally takes more steps than CbNeed.
Multi Types by Need. In this paper we provide the first multi type system characterising CbNeed termination and whose minimal type derivations provide exact bounds for CbNeed evaluation lengths. The design of the type system is delicate, as we explain in Sect. 6. One of the key points is that, in contrast to Ehrhard’s system for CbV [34], multi types for CbNeed cannot be directly extracted by the relational semantics of linear logic, given that CbNeed does not have a clean representation in it. A byproduct of our work is a new denotational semantics of CbNeed, the first one to precisely reflect its quantitative properties.
Beyond the result itself, the paper tries to stress how the key ingredients of our type system are taken from those for CbN and CbV and combined together. To this aim, we first present multi types for CbN and CbV, and only then we proceed to build the CbNeed system and prove its properties.
Along the way, we also prove the missing fundamental property of CbNeed, that is, that it duplicates as efficiently as CbV. The result dualizes the termination equivalence of CbN and CbNeed, which shows that CbNeed erases as wisely as CbN. Careful: the CbV system is correct but of course not complete with respect to CbNeed, because CbNeed may normalise when CbV diverges. The proof of the result is straightforward, because of our presentations of CbV and CbNeed. We adopt a liberal, nondeterministic formulation of CbV, and assuming (without loss of generality, see [1]) that garbage collection is always postponed. These two ingredients turn CbNeed into a fragment of CbV, obtaining the new fundamental result as a corollary of correctness of CbV multi types for CbV evaluation.
Technical Development. The paper is extremely uniform, technically speaking. The three evaluations are presented as strategies of Accattoli and Kesner’s Linear Substitution Calculus (shortened to LSC) [1, 6], a calculus with a simple but expressive form of explicit sharing. The LSC is strongly related to linear logic [2], and provides a neat and manageable presentation of CbNeed, introduced by Accattoli, Barenbaum, and Mazza in [3], and further developed by various authors in [4, 5, 10, 14, 15, 40, 42]. Our type systems count evaluation steps by annotating typing rules in the exact same way, and the proofs of correctness and completeness all follow the exact same structure. While the results for CbN are very minor variations with respect to those in the literature [7, 23], those for CbV are the first ones with respect to a presentation of CbV with sharing.
As it is standard for CbNeed, we restrict our study to closed terms and weak evaluation (that is, out of abstractions). The main consequence of this fact is that normal forms are particularly simple (sometimes called answers in the literature). Compared with other recent works dealing with exact bounds such as Accattoli, GrahamLengrand, and Kesner [7] and Accattoli and Guerrieri [8] the main difference is that the size of normal forms is not taken into account by type derivations. This is because of the simple notions of normal forms in the closed and weak case, and not because the type systems are not accurate.
Related Work About CbNeed. Callbyneed was introduced by Wadsworth [57] in the ’70s. In the ’90s, it was first reformulated as operational semantics by Launchbury [46], Maraist, Odersky, and Wadler [48], and Ariola and Felleisen [11, 12], and then implemented by Sestoft [55] and further studied by Kutzner and SchmidtSchauß [45]. More recent papers are Garcia, Lumsdaine, and Sabry [36], Ariola, Herbelin, and Saurin [13], Chang and Felleisen [26], Danvy and Zerny [29], Downen et al. [33], Pédrot and Saurin [53], and Balabonski et al. [14].
Related Work About Multi Types. Intersection types are a standard tool to study \(\lambda \)calculi—see Coppo and Dezani [27, 28], Pottinger [54], and Krivine [44]. Nonidempotent intersection types, i.e. multi types, were first considered by Gardner [37], and then by Kfoury [43], Neergaard and Mairson [50], and de Carvalho [23]—a survey is Bucciarelli, Kesner, and Ventura [20].
Many recent works rely on multi types or relational semantics to study properties of programs and proofs. Beyond the cited ones, DiazCaro, Manzonetto, and Pagani [32], Carraro and Guerrieri [21], Ehrhard and Guerrieri [35], and Guerrieri [39] deal with CbV, while Bernadet and Lengrand [17], de Carvalho, Pagani, and Tortora de Falco [24] provide exact bounds. Further related work is by Bucciarelli, Ehrhard, and Manzonetto [18], de Carvalho and Tortora de Falco [25], Tsukada and Ong [56], Kesner and Vial [41], Piccolo, Paolini and Ronchi Della Rocca [52], Ong [51], Mazza, Pellissier, and Vial [49], Bucciarelli, Kesner and Ronchi Della Rocca [19]—this list is not exhaustive.
Proofs. Proofs are omitted. They can be found in the technical report [9].
2 Closed \(\lambda \)Calculi
In this section we define the CbN, CbV, and CbNeed evaluation strategies. We present them in the context of the Accattoli and Kesner’s linear substitution calculus (LSC) [1, 6]. We mainly follow the uniform presentation of these strategies given by Accattoli, Barenbaum, and Mazza [3]. The only difference is that we adopt a nondeterministic presentation of CbV, subsuming both the lefttoright and the righttoleft strategies in [3], that makes our results slightly more general. Such a nondeterminism is harmless: not only CbV evaluation is confluent, it even has the diamond property, so that all evaluations have the same length. Moreover, the nondeterministic presentation, together with the postponement of erasing steps discussed below, allows us to see CbNeed as a fragment of CbV, which shall provide a free proof that CbNeed duplicates as wisely as CbV.
We write \(W\langle t\rangle \) for the term obtained by replacing the hole \(\langle \cdot \rangle \) in context \(W\) by the term \(t\). This plugging operation, as usual with contexts, can capture variables—for instance \(((\langle \cdot \rangle t)[x{\leftarrow }s])\langle x\rangle = (xt)[x{\leftarrow }s]\). We write \(W\langle \! \langle t \rangle \! \rangle \) when we want to stress that the context \(W\) does not capture the free variables of \(t\).
Microstep Semantics. The rewriting rules decompose the usual smallstep semantics for \(\lambda \)calculi, by substituting linearly one variable occurrence at the time, and only when such an occurrence is in evaluation position. We emphasise this fact saying that we adopt a microstep semantics. We now give the definitions, examples of evaluation sequences follow right next.
where, in the rootstep \(\mapsto _{\mathtt m}\) (resp. \(\mapsto _{{\mathtt e}_\mathrm{cbv}}\); \(\mapsto _{{\mathtt e}_\mathrm{need}}\)), if Open image in new window for some \(n \in \mathbb {N}\), then \(\mathtt{fv}(s)\) (resp. \(\mathtt{fv}(V\langle \! \langle x \rangle \! \rangle )\); \(\mathtt{fv}(E\langle \! \langle x \rangle \! \rangle )\)) and \(\{y_1, \dots , y_n\}\) are disjoint. This condition can always be fulfilled by \(\alpha \)equivalence.
Note that evaluations \( \ {\xrightarrow {}}{}_{{\mathrm{cbn}}}^{} \), \( \ {\xrightarrow {}}{}_{{\mathrm{cbv}}}^{} \) and \( \ {\xrightarrow {}}{}_{{\mathrm{need}}}^{} \) can equivalently be defined as \( \ {\xrightarrow {}}{}_{{{\mathtt m}_\mathrm{cbn}}}^{} \cup \ {\xrightarrow {}}{}_{{{\mathtt e}_\mathrm{cbn}}}^{} \), \( \ {\xrightarrow {}}{}_{{{\mathtt m}_\mathrm{cbn}}}^{} \cup \ {\xrightarrow {}}{}_{{{\mathtt e}_\mathrm{cbv}}}^{} \) and \( \ {\xrightarrow {}}{}_{{{\mathtt m}_\mathrm{need}}}^{} \cup \ {\xrightarrow {}}{}_{{{\mathtt e}_\mathrm{need}}}^{} \), respectively.
Given an evaluation sequence \(d:t \ {\xrightarrow {}}{}_{\mathrm{cbn}}^{*} s\) we note with \(d\) the length of \(d\), and with \(d_{{\mathtt m}}\) and \(d_{{\mathtt e}}\) the number of multiplicative and exponential steps in \(d\), respectively—and similarly for \( \ {\xrightarrow {}}{}_{{\mathrm{cbv}}}^{} \) and \( \ {\xrightarrow {}}{}_{{\mathrm{need}}}^{} \).
Example 1
Note that the fact that CbN and CbV take the same number of steps is by chance, as they reduce different redexes: CbN never reduce the unneeded redex II associated to y, but it reduces twice the needed II redex associated to x, while CbV reduces both, but each one only once.
Proposition 1
(Syntactic characterization of closed normal forms). Let \(t\) be a closed term.
 1.
CbN and CbNeed: For \(\mathsf {r}\in \{\mathrm{cbn}, \mathrm{need}\}\), \(t\) is \(\mathsf {r}\)normal if and only if \(\mathsf{{normal}} ({t})\).
 2.
CbV: \(t\) is \(\mathrm{cbv}\)normal if and only if \({\mathsf{{normal}} _\mathrm{cbv}} ({t})\).
The simple structure of normal forms is the main point where the restriction to closed calculi plays a role in this paper.
From the syntactic characterization of normal forms (Proposition 1) it follows immediately that among closed terms, normal forms for CbN and CbNeed coincide, while normal forms for CbV are a subset of them. Such a subset is proper since the closed term \(I [x{\leftarrow }\delta \delta ]\) (where Open image in new window and Open image in new window ) is normal for CbN and CbNeed but not for CbV (and it cannot normalise in CbV).
3 Preliminaries About Multi Types
In this section we define basic notions about multi types, type contexts, and (type) judgements that are shared by the three typing systems of the paper.
where \([\ldots ]_{{}}\) denotes the multiset constructor. The empty multiset \([\,]\) (the multi type obtained for \(J = \emptyset \)) is called empty (multi) type and denoted by the special symbol \(\mathbf {0}\). An example of multiset is \([L, L, {L'}]_{{}}\), that contains two occurrences of \(L\) and one occurrence of \({L'}\). Multiset union is noted Open image in new window .
Type Contexts. A type context Open image in new window is a (total) map from variables to multi types such that only finitely many variables are not mapped to Open image in new window . The domain of Open image in new window is the set Open image in new window . The type context Open image in new window is empty if Open image in new window .
Multiset union Open image in new window is extended to type contexts pointwise, i.e. Open image in new window for each variable \(x\). This notion is extended to a finite family of type contexts as expected, so that Open image in new window denotes a finite union of type contexts—it stands for the empty context when \(J = \emptyset \). A type context Open image in new window is denoted by \(x_1 \,{:}\,M_1, \dots , x_n \,{:}\,M_n\) (for some \(n \in \mathbb {N}\)) if Open image in new window and Open image in new window for all \(1 \le i \le n\). Given two type contexts Open image in new window and \(\varPi \) such that Open image in new window , the type context Open image in new window is defined by Open image in new window if Open image in new window , Open image in new window if \(x\in \mathtt{dom}({\varPi })\), and Open image in new window otherwise.
Judgements. Type judgements are of the form Open image in new window or Open image in new window (noted also \( {}\ {\pmb \vdash }_{}^{(m, e)} {t} \,{:}\,{L}\) and \( {}\ {\pmb \vdash }_{}^{(m, e)} {t} \,{:}\,{M}\), respectively, when Open image in new window is the empty context), where the indices \(m\) and \(e\) are natural numbers whose intended meaning is that \(t\) evaluates to normal form in \(m\) multiplicative steps and \(e\) exponential steps, with respect to the evaluation strategy associated with the type system.
To make clear in which type systems the judgement is derived, we write Open image in new window if \(\varPhi \) is a derivation in the CbN system ending in the judgement Open image in new window , and similarly for CbV and CbNeed.
4 Types by Name
 CbN linear types are given by the following grammar: Multi(sets) types are defined as in Sect. 3, relatively to CbN linear types. Note the linear constant \(\mathsf{{normal}} \) (used to type abstractions, which are normal terms): it plays a crucial role in our quantitative analysis of CbN evaluation.

The CbN typing rules are in Fig. 1.

The \(\mathsf {many} \) rule: it has as many premises as the elements in the (possibly empty) set of indices J. When \(J = \emptyset \), the rule has no premises, and it types \(t\) with the empty multi type \(\mathbf {0}\). The \(\mathsf {many} \) rule is needed to derive the right premises of the rules \(\mathsf{app} \) and \(\mathsf{ES} \), that have a multi type \(M\) on their righthand side. Essentially, it corresponds to the promotion rule of linear logic, that, in the CbN representation of the \(\lambda \)calculus, is indeed used for typing the right subterm of applications and the content of explicit substitutions.

The size of a derivation Open image in new window is the sum \(m+ e\) of the indices. A quick look to the typing rules shows that indices on typing judgements are not needed, as \(m\) can be recovered as the number of \(\mathsf{app} \) rules, and \(e\) as the number of \(\mathsf {ax} \) rules. It is however handy to note them explicitly.
 1.
Introduction and destruction of multisets: multiset are introduced on the right by the \(\mathsf {many} \) rule and on the left by \(\mathsf {ax} \). Moreover, on the left they are summed by \(\mathsf{app} \) and \(\mathsf{ES} \).
 2.
Vacuous abstractions: the abstraction rule \(\mathsf{fun} \) can always abstract a variable \(x\); note that if \(M= \mathbf {0}\), then Open image in new window is equal to Open image in new window .
 3.
Relevance: No weakening is allowed in axioms. An easy induction on type derivations shows that
Lemma 1
(Type contexts and variable occurrences for CbN). Let Open image in new window be a derivation. If \(x\not \in \mathtt{fv}(t)\) then Open image in new window .
Lemma 1 implies that derivations of closed terms have empty type context. Note that there can be free variables of \(t\) not in Open image in new window : the ones only occurring in subterms not touched by the evaluation strategy.
 1.
Erasable terms and \(\mathbf {0}\): the empty multi type \(\mathbf {0}\) is the type of erasable terms. Indeed, abstractions that erase their argument—whose paradigmatic example is \(\lambda x.y\)—can only be typed with \(\mathbf {0} \multimap L\), because of Lemma 1. Note that in CbN every term—even diverging ones—can be typed with \(\mathbf {0}\) by rule \(\mathsf {many} \) (taking 0 premises), because, correctly, in CbN every term can be erased.
 2.
Adequacy and linear types: all CbN typing rules but \(\mathsf {many} \) assign linear types. And \(\mathsf {many} \) is used only as right premise of the rules \(\mathsf{app} \) and \(\mathsf{ES} \), to derive \(M\). It is with respect to linear types, in fact, that the adequacy of the system is going to be proved: a term is CbN normalising if and only if it is typable with a linear type, given by Theorems 1 and 2 below.
Definition 1
(Tight derivations for CbN). A derivation Open image in new window is tight (for CbN) if \(L= \mathsf{{normal}} \) and Open image in new window is empty.
Example 2
Let us return to the term Open image in new window used in Example 1 for explaining the difference in reduction lengths among the different strategies. We now give a derivation for it in the \(\text {CbN} \) type system.
The next two subsections prove the two halves of the properties of the CbN type system, namely correctness and completeness.
4.1 CbN Correctness
Correctness is the fact that every typable term is CbN normalising. In our setting it comes with additional quantitative information: the indices \(m\) and \(e\) of a derivation Open image in new window provide upper bounds on the length of the CbN evaluation of \(t\), that are exact when the derivation is tight.
The proof technique is standard. Moreover, the correctness theorems for CbV and CbNeed in the next sections follow exactly the same structure. The proof relies on a quantitative subject reduction property showing that \(m\) decreases by exactly one at each \({\mathtt m}_\mathrm{cbn}\)step, and similarly for \(e\) and \({\mathtt e}_\mathrm{cbn}\)steps. In turn, subject reduction relies on a linear substitution lemma. Last, correctness for tight derivations requires a further property of normal forms.
Let us point out that correctness is stated with respect to closed terms only, but the auxiliary results have to deal with open terms, since they are proved by inductions (over predicates defined by induction) over the structure of terms.
Linear Substitution. The linear substitution lemma states that substituting over a variable occurrence as in the exponential rule consumes exactly one linear type and decreases of one the exponential index \(e\).
Lemma 2
(CbN linear substitution). If Open image in new window then there is a splitting Open image in new window such that for every derivation \(\varPsi \triangleright _{\mathrm{cbn}\!}\ {\varPi }\ {\pmb \vdash }_{}^{(m', e')} {t} \,{:}\,{{L'}}\) there is a derivation Open image in new window .
The proof is by induction over CbN evaluation contexts.
Quantitative Subject Reduction. A key point of multi types is that the size of type derivations shrinks after every evaluation step, which is what allows to bound evaluation lengths. Remarkably, the size (defined as the sum of the indices) shrinks by exactly 1 at every evaluation step.
Proposition 2
(Quantitative subject reduction for CbN). Let Open image in new window be a derivation.
 1.
Multiplicative: if \(t \ {\xrightarrow {}}{}_{{{\mathtt m}_\mathrm{cbn}}}^{} s\) then \(m\ge 1\) and there exists a derivation Open image in new window .
 2.
Exponential: if \(t \ {\xrightarrow {}}{}_{{{\mathtt e}_\mathrm{cbn}}}^{} s\) then \(e\ge 1\) and there exists a derivation Open image in new window .
The proof is by induction on \(t \ {\xrightarrow {}}{}_{{{\mathtt m}_\mathrm{cbn}}}^{} s\) and \(t \ {\xrightarrow {}}{}_{{{\mathtt e}_\mathrm{cbn}}}^{} s\), using the linear substitution lemma for the root exponential step.
Tightness and Normal Forms. Since the indices are always nonnegative, quantitative subject reduction (Proposition 2) implies that they bound evaluation lengths. The bound is not necessarily exact, as derivations of normal forms can have strictly positive indices. If they are tight, however, they are indexed by (0, 0), as we now show. The proof of this fact (by induction on the predicate \(\mathsf{{normal}} \)) requires a slightly different statement, for the induction to go through.
Proposition 3
(\({\mathsf {normal}}\) typing of normal forms for CbN). Let \(t\) be such that \(\mathsf{{normal}} ({t})\), and Open image in new window be a derivation. Then Open image in new window is empty, and so \(\varPhi \) is tight, and \(m= e= 0\).
The Tight Correctness Theorem. The theorem is then proved by a straightforward induction on the evaluation length relying on quantitative subject reduction (Proposition 2) for the inductive case, and the properties of tight typings for normal forms (Proposition 3) for the base case.
Theorem 1
(CbN tight correctness). Let \(t\) be a closed term. If \(\varPhi \triangleright _{\mathrm{cbn}\!}\ {}\ {\pmb \vdash }_{}^{(m, e)} {t} \,{:}\,{L}\) then there is \(s\) such that \(d:t \ {\xrightarrow {}}{}_{\mathrm{cbn}}^{*} s\), with \(\mathsf{{normal}} ({s})\), \(d_{{\mathtt m}}\le m\) and \(d_{{\mathtt e}}\le e\). Moreover, if \(\varPhi \) is tight then \(d_{{\mathtt m}}= m\) and \(d_{{\mathtt e}}= e\).
Note that Theorem 1 implicitly states that tight derivations have minimal size among derivations.
4.2 CbN Completeness
Completeness is the fact that every CbN normalising term has a (tight) type derivation. As for correctness, the completeness theorem is always obtained via three intermediate steps, dual to those for correctness.
Normal Forms. The first step is to prove (by induction on the predicate \(\mathsf{{normal}} \)) that every normal form is typable, and is actually typable with a tight derivation.
Proposition 4
(Normal forms are tightly typable for CbN). Let \(t\) be such that \(\mathsf{{normal}} ({t})\). Then there is tight derivation \(\varPhi \triangleright _{\mathrm{cbn}\!}\ {}\ {\pmb \vdash }_{}^{(0, 0)} {t} \,{:}\,{\mathsf{{normal}}}\).
Linear Removal. In order to prove subject expansion, we have to first show that typability can also be pulled back along substitutions, via a linear removal lemma dual to the linear substitution lemma.
Lemma 3

a linear type \({L'}\) and two type contexts Open image in new window and \(\varPi \),

a derivation Open image in new window , and

a derivation Open image in new window

Type contexts: Open image in new window .

Indices: \((m, e) = (m'+ m'', e'+ e'' 1)\).
Quantitative Subject Expansion. This property is the dual of subject reduction.
Proposition 5
(Quantitative subject expansion for CbN). Let Open image in new window be a derivation.
 1.
Multiplicative: if \(t \ {\xrightarrow {}}{}_{{{\mathtt m}_\mathrm{cbn}}}^{} s\) then there is a derivation Open image in new window .
 2.
Exponential: if \(t \ {\xrightarrow {}}{}_{{{\mathtt e}_\mathrm{cbn}}}^{} \! s\) then there is a derivation Open image in new window .
The proof is by induction on \(t \ {\xrightarrow {}}{}_{{{\mathtt m}_\mathrm{cbn}}}^{} s\) and \(t \ {\xrightarrow {}}{}_{{{\mathtt e}_\mathrm{cbn}}}^{} s\), using the linear removal lemma for the root exponential step.
The Tight Completeness Theorem. The theorem is proved by a straightforward induction on the evaluation length relying on quantitative subject expansion (Proposition 5) in the inductive case, and the existence of tight typings for normal forms (Proposition 4) in the base case.
Theorem 2
(CbN tight completeness). Let \(t\) be a closed term. If \(d:\!t\! \ {\xrightarrow {}}{}_{\mathrm{cbn}}^{*} s\) and \(\mathsf{{normal}} ({s})\) then there is a tight derivation \(\varPhi \triangleright _{\mathrm{cbn}\!\!\!\!}\ {}\ {\pmb \vdash }_{}^{(d_{{\mathtt m}}, d_{{\mathtt e}})} {t} \,{:}\,{\mathsf{{normal}}}\).
The right premise of rule \(\mathsf{ES} _{\text {gc}} \) has been removed because the only way to introduce \(\mathbf {0}\) is via a \(\mathsf {many} \) rule with no premises. The index g bounds to the number of erasing steps. In the closed case, however, the bound cannot be, in general, exact. Variables typed with \(\mathbf {0}\) by Open image in new window do not exactly match variables not appearing in the typed term (that is the condition triggering the erasing step), because a variable typed with \(\mathbf {0}\) may appear in the body of abstractions typed with the normal rule, as such bodies are not typed.
It is reasonable to assume that exact bounds for erasing steps can only by provided by a type system characterising strong evaluation, whose typing rules have to inspect abstraction bodies. These erasing typing rules are nonetheless going to play a role in the design of the CbNeed system in Sect. 6.
4.3 CbN Model
In fact, adequacy also holds with respect to open terms. The issue in that case is that the characterisation of tight derivations is more involved, see Accattoli, GrahamLengrand and Kesner’s [7]. Said differently, weaker correctness and completeness theorems without exact bounds also hold in the open case. The same is true for the CbV and CbNeed systems of the next sections.
5 Types by Value

Righthand types: all rules but \(\mathsf{fun} \) assign a multi type to the term on the righthand side, and not a linear type as in CbN.

Abstractions and \(\mathsf {many} \): the \(\mathsf {many} \) rule has a restricted form with respect to the CbN one, it can only be applied to abstractions, that in turn are the only terms that can be typed with a linear type.

Indices: note as the indices are however incremented (on \(\mathsf {ax} \) and \(\mathsf{app} \)) and summed (in \(\mathsf {many} \) and \(\mathsf{ES} \)) exactly as in the CbN system.
Intuitions: The Empty Type \(\mathbf {0}\). The empty multiset type \(\mathbf {0}\) plays a special role in CbV. As in CbN, it is the type of terms that can be erased, but, in contrast to CbN, not every term is erasable in CbV.
In the CbN multi type system every term, even a diverging one, is typable with \(\mathbf {0}\). On the one hand, this is correct, because in CbN every term can be erased, and erased terms can also be divergent, because they are never evaluated. On the other hand, adequacy is formulated with respect to nonempty types: a term terminates if and only if it is typable with a nonempty type.
In CbV, instead, terms have to be evaluated before being erased; and, of course, their evaluation has to terminate. Thus, terminating terms and erasable terms coincide. Since the multi type system is meant to characterise terminating terms, in CbV a term is typable if and only if it is typable with \(\mathbf {0}\), as we shall prove in this section. Then the empty type is not a degenerate type excluded for adequacy from the interesting types of a term, as in CbN, it rather is the type, characterising (adequate) typability altogether. And this is also the reason for the absence of the constant \(\mathsf{{normal}} \)—one way to see it is that in CbV \(\mathsf{{normal}} = \mathbf {0}\).
Note that, in particular, in a type judgement Open image in new window the type context Open image in new window may give the empty type to a variable \(x\) occurring in \(t\), as for instance in the axiom \(x\,{:}\,\mathbf {0}\vdash x\,{:}\,\mathbf {0}\)—this may seem very strange to people familiar with CbN multi types. We hope that instead, according to the provided intuition that \(\mathbf {0}\) is the type of termination, it would rather seem natural.
Definition 2
(Tight derivation for CbV). A derivation Open image in new window is tight (for CbV) if \(M= \mathbf {0}\) and Open image in new window is empty.
Example 3
Let’s consider again the term Open image in new window of Example 1 (where Open image in new window ), for which a \(\text {CbN} \) tight derivation was given in Example 2, and let us type it in the \(\text {CbV} \) system with a tight derivation.
Correctness (i.e. typability implies normalisability) and completeness (i.e. normalisability implies typability) of the CbV type system with respect to CbV evaluation (together with quantitative information about evaluation lengths) follow exactly the same pattern of the CbN case, mutatis mutandis.
5.1 CbV Correctness
Lemma 4
(CbV linear substitution). Let Open image in new window and \(v\) be a value. There is a splitting Open image in new window such that, for any derivation Open image in new window , there is a derivation Open image in new window .
Proposition 6
(Quantitative subject reduction for CbV). Let Open image in new window be a derivation.
 1.
Multiplicative: if \(t \ {\xrightarrow {}}{}_{{{\mathtt m}_\mathrm{cbv}}}^{} t'\) then \(m\ge 1\) and there exists a derivation Open image in new window .
 2.
Exponential: if \(t \ {\xrightarrow {}}{}_{{{\mathtt e}_\mathrm{cbv}}}^{} t'\) then \(e\ge 1\) and there exists a derivation Open image in new window .
Proposition 7
(Tight typings for normal forms for CbV). Let Open image in new window be a derivation, with \({\mathsf{{normal}} _\mathrm{cbv}} ({t})\). Then Open image in new window is empty, and so \(\varPhi \) is tight, and \(m= e= 0\).
Theorem 3
(CbV tight correctness). Let \(t\) be a closed term. If Open image in new window then there is \(s\) such that \(d:t \ {\xrightarrow {}}{}_{\mathrm{cbv}}^{*} s\), with \({\mathsf{{normal}} _\mathrm{cbv}} ({s})\), \(d_{{\mathtt m}}\le m\) and \(d_{{\mathtt e}}\le e\). Moreover, if \(\varPhi \) is tight then \(d_{{\mathtt m}}= m\) and \(d_{{\mathtt e}}= e\).
5.2 CbV Completeness
Proposition 8
(Normal forms are tightly typable for CbV). Let \(t\) be such that \({\mathsf{{normal}} _\mathrm{cbv}} ({t})\). Then there exists a tight derivation \(\varPhi \triangleright _{\mathrm{cbv}\!}\ {}\ {\pmb \vdash }_{}^{(0, 0)} {t} \,{:}\,{\mathbf {0}}\).
Lemma 5

a multi type \(M'\) and two type contexts Open image in new window and \(\varPi \),

a derivation Open image in new window and

a derivation Open image in new window

Type contexts: Open image in new window ,

Indices: \((m, e) = (m'+ m'', e'+ e'' 1)\).
Proposition 9
(Quantitative subject expansion for CbV). Let Open image in new window be a derivation.
 1.
Multiplicative: if \(t \ {\xrightarrow {}}{}_{{{\mathtt m}_\mathrm{cbv}}}^{} t'\) then there is a derivation Open image in new window .
 2.
Exponential: if \(t \ {\xrightarrow {}}{}_{{{\mathtt e}_\mathrm{cbv}}}^{} t'\) then there is a derivation Open image in new window .
Theorem 4
(CbV tight completeness). Let \(t\) be a closed term. If \(d:\! t \ {\xrightarrow {}}{}_{\mathrm{cbv}}^{*} \! s\) with \({\mathsf{{normal}} _\mathrm{cbv}} ({s})\), then there is a tight derivation \(\varPhi \triangleright _{\mathrm{cbv}\!}\ {}\ {\pmb \vdash }_{}^{(d_{{\mathtt m}}, d_{{\mathtt e}})} {t} \,{:}\,{\mathbf {0}}\).
Note that rule \(\mathsf{fun} \) assigns a linear type but the interpretation considers only multi types. The invariance and the adequacy of \([\![t]\!]_{\vec {x}}^\text {CbV} \) with respect to CbV evaluation are obtained exactly as for the CbN case.
6 Types by Need

Wise erasures from CbN: in CbN wise erasures are induced by the fact that the empty multi type \(\mathbf {0}\) (the type of erasable terms) and the linear type \(\mathsf{{normal}} \) (the type of normalisable terms) are distinct and every term is typable with \(\mathbf {0}\) by using the \(\mathsf {many} \) rule with 0 premises. Adequacy is then formulated with respect to (nonempty) linear types.

Wise duplications from CbV: in CbV wise duplications are due to two aspects. First, only abstractions can be collected in multisets by rule \(\mathsf {many} \). This fact accounts for the evaluation of arguments to normal form—that is, abstractions—before being substituted. Second, terms are typed with multi types instead of linear types. Roughly, this second fact allows the first one to actually work because the argument is reduced once for a whole multi set of types, and not once for each element of the multi set, as in CbN.

separating \(\mathbf {0}\) and \(\mathsf{{normal}} \), that is, adding \(\mathsf{{normal}} \) to the system;

modifying the \(\mathsf {many} \) rule by distinguishing two cases: with 0 premises it can assign \(\mathbf {0}\) to whatever term—as in CbN—otherwise it is forced to work on abstractions, as in CbV;

restricting adequacy to nonempty types.
Note that introducing \({} \vdash ^{(0,1)} x \,{:}\,\mathbf {0}\) with rule \(\mathsf {ax} \) rather than via \(\mathsf {many} _0\) (the typing context \(x\,{:}\,\mathbf {0}\) is equivalent to the empty type context) would give a derivation with final judgement \({} \vdash ^{(1,1)} (\lambda x.{x}) t \,{:}\,\mathbf {0}\)—thus, the system messes up both indices.
The Actual Type System. Our solution to such an issue is to modify the system as to avoid derivations of \(\mathbf {0}\) to appear as right premises of rules \(\mathsf{app} \) and \(\mathsf{ES} \). We follow the schema of the rules for counting erasing steps given right after Theorem 2.
Therefore, we add two dedicated rules \(\mathsf{app} _{\text {gc}} \) and \(\mathsf{ES} _{\text {gc}} \), and constrain the right premise of rules \(\mathsf{app} \) and \(\mathsf{ES} \) to have a nonempty type. The system is in Fig. 4 and it is based on the same grammar of types of the naïve system. Note that rules \(\mathsf {many} \) and \(\mathsf {ax} \) can still introduce \(\mathbf {0}\). These \(\mathbf {0}\)s, however, can no longer mess up the indices of tight derivations, as we are going to show.
Definition 3
(Tight derivations for CbNeed). A derivation Open image in new window is tight (for CbNeed) if \(M= [\mathsf{{normal}} ]\) and Open image in new window is empty.
Example 4
We return to the term Open image in new window used in Example 1 and we give it a tight derivation in the \(\text {CbNeed} \) type system.
Remarkably, the technical development to prove correctness and completeness of the CbNeed type system with respect to CbNeed evaluation follows smoothly along the same lines of the two other systems, mutatis mutandis.
6.1 CbNeed Correctness
Lemma 6
(CbNeed linear substitution). Let Open image in new window and \(v\) be a value. There is a splitting Open image in new window such that for any derivation \(\varPsi \triangleright _{\mathrm{need}\!}\ {\varPi } \vdash ^{(m', e')} v \,{:}\,O\) there exists Open image in new window .
Proposition 10
(Quantitative subject reduction for CbNeed). Let Open image in new window be a derivation such that Open image in new window .

Multiplicative: if \(t \ {\xrightarrow {}}{}_{{{\mathtt m}_\mathrm{need}}}^{} s\) then \(m\ge 1\) and there is a derivation Open image in new window .

Exponential: if \(t \ {\xrightarrow {}}{}_{{{\mathtt e}_\mathrm{need}}}^{} s\) then \(e\ge 1\) and there exists a derivation Open image in new window .
Note the condition \(M\ne \mathbf {0}\) in the statement of subject reduction, that is in contrast to the CbV system but akin to the CbN one. It is due to the way multi types are used as arguments, via rules \(\mathsf{ES} _{\text {gc}} \) and \(\mathsf{app} _{\text {gc}} \). The restriction is necessary: the CbNeed type system derives \({} \vdash ^{(0,1)} x[x{\leftarrow }\delta \delta ] \,{:}\,\mathbf {0}\), but \(x[x{\leftarrow }\delta \delta ]\) is not normalising for CbNeed evaluation. And it is expected, as it amounts to the fact that adequacy holds only with respect to nonempty types, as for CbN, and as stressed when introducing the CbNeed type system. The same restriction appears in Theorem 5, Proposition 13 and Theorem 6 below, for the same reason.
Proposition 11
(\([ \mathsf{{normal}} ] \) typings for normal forms for CbNeed). Let Open image in new window be a derivation, with \(\mathsf{{normal}} ({t})\). Then Open image in new window is empty, and so \(\varPhi \) is tight, and \(m= e= 0\).
Theorem 5
(CbNeed tight correctness). Let \(t\) be a closed term. If \(\varPhi \triangleright _{\mathrm{need}\!}\ {} \vdash ^{(m, e)} t \,{:}\,M\) where \(M\ne \mathbf {0}\), then there is \(s\) such that \(d:t \ {\xrightarrow {}}{}_{\mathrm{need}}^{*} s\), with \(\mathsf{{normal}} ({s})\), \(d_{{\mathtt m}} \le m\) and \(d_{{\mathtt e}} \le e\). Moreover, if \(\varPhi \) is tight then \(d_{{\mathtt m}} = m\) and \(d_{{\mathtt e}} = e\).
6.2 CbNeed Completeness
Proposition 12
(Normal forms are tightly typable for CbNeed). Let \(t\) be such that \(\mathsf{{normal}} ({t})\). Then there is a tight derivation \(\varPhi \triangleright _{\mathrm{need}\!}\ {} \vdash ^{(0,0)} t \,{:}\,[ \mathsf{{normal}} ] \).
Lemma 7

a multi type \(M'\) and two type contexts Open image in new window and \(\varPi \),

a derivation Open image in new window , and

a derivation Open image in new window

Type contexts: Open image in new window .

Indices: \((m, e) = (m'+ m'', e'+ e'' 1)\).
Proposition 13

Multiplicative: if \(t \ {\xrightarrow {}}{}_{{{\mathtt m}_\mathrm{need}}}^{} s\) then there is a derivation Open image in new window ,

Exponential: if \(t \ {\xrightarrow {}}{}_{{{\mathtt e}_\mathrm{need}}}^{} s\) then there is a derivation Open image in new window .
Theorem 6
(CbNeed tight completeness). Let \(t\) be a closed term. If \(d:t \ {\xrightarrow {}}{}_{\mathrm{need}}^{*} s\) and \(\mathsf{{normal}} ({s})\) then there exists a tight derivation \(\varPhi \triangleright _{\mathrm{need}\!}\ {} \vdash ^{(d_{{\mathtt m}},d_{{\mathtt e}})} t \,{:}\,[ \mathsf{{normal}} ] \).
7 A New Fundamental Theorem for CallbyNeed
CbNeed Erases Wisely. In the literature, the theorem about CbNeed is the fact that it is operationally equivalent to CbN. This result was first proven independently by two groups, Maraist, Odersky, and Wadler [48], and Ariola and Felleisen [11], in the nineties, using heavy rewriting techniques.
Recently, Kesner gave a much simpler proof via CbN multi types [40]. She uses multi types to first show termination equivalence of CbN and CbNeed, from which she then infers operational equivalence. Termination equivalence means that a given term terminates in CbN if and only if terminates in CbNeed, and it is a consequence of our slogan that CbN and CbNeed both erase wisely.
With our terminology and notations, Kesner’s result takes the following form.
Theorem 7
(Kesner [40]). Let \(t\) be a closed term.
 1.
Correctness: if \(\varPhi \triangleright _{\mathrm{cbn}\!}\ {}\ {\pmb \vdash }_{}^{(m, e)} {t} \,{:}\,{L}\) then there exists \(s\) such that \(d:t \ {\xrightarrow {}}{}_{\mathrm{need}}^{*} s\), \(\mathsf{{normal}} ({s})\), \(d_{{\mathtt m}}\le m\) and \(d_{{\mathtt e}}\le e\).
 2.
Completeness: if \(d:\! t\! \ {\xrightarrow {}}{}_{\mathrm{need}}^{*} s\) and \(\mathsf{{normal}} ({s})\) then there is \(\varPhi \triangleright _{\mathrm{cbn}\!\!}\ {}\ {\pmb \vdash }_{}^{(m, e)} {t\!} \,{:}\,{\!\mathsf{{normal}}}\).
Note that, with respect to the other similar theorems in this paper, the result does not cover tight derivations and it does not provide exact bounds. In fact, the CbN system cannot provide exact bounds for CbNeed, because it does provide them for CbN evaluation, that in general is slower than CbNeed. Consider for instance the term \(t\) in Example 1 and its CbN tight derivation in Example 2: the derivation provides indices (5, 5) for \(t\) (and so \(t\) evaluates in 10 CbN steps), but \(t\) evaluates in 8 CbNeed steps. Closing such a gap is the main motivation behind this paper, achieved by the CbNeed multi type system in Sect. 6.
CbNeed Duplicates Wisely. Curiously, in the literature there are no dual results showing that CbNeed duplicates as wisely as CbV. One of the reasons is that it is a theorem that does not admit a simple formulation such as operational or termination equivalence, because CbNeed and CbV are not in such relationships. Morally, this is subsumed by the logical interpretation according to which CbNeed corresponds to an affine variant of the linear logic representation of CbV. Yet, it would be nice to have a precise, formal statement establishing that CbNeed duplicates as wisely as CbV—we provide it here.

Bounds are not exact: the indices of a CbV derivation do not generally provide exacts bounds for CbNeed, not even in the case of tight derivations. The reason is that CbNeed does not evaluate unneeded subterms (i.e. those typed with \(\mathbf {0}\)), while CbV does. Consider again the term \(t\) of Example 1, for instance, whose CbV tight derivation has indices (5, 5) (and so \(t\) evaluates in 10 CbV steps) but it CbNeed evaluates in 8 steps.

Completeness cannot hold: we prove correctness but not completeness simply because the CbV system is not complete with respect to CbNeed evaluation. Consider for instance \((\lambda x.I) \varOmega \): it is CbV untypable by Theorem 4, because it is CbV divergent, and yet it is CbNeed normalisable.
Corollary 1
(CbV correctness w.r.t. CbNeed). Let \(t\) be a closed term and \(\varPhi \triangleright _{\mathrm{cbv}}\ {}\ {\pmb \vdash }_{}^{(m,e)} {t} \,{:}\,{M}\) be a derivation. Then there exists \(s\) such that \(d:t \ {\xrightarrow {}}{}_{\mathrm{need}}^{*} s\) and \(\mathsf{{normal}} ({s})\), with \(d_{{\mathtt m}} \le m\) and \(d_{{\mathtt e}} \le e\).
Since the CbNeed system provides exact bounds (Theorem 5), we obtain that CbNeed duplicates as wisely as CbV, when the comparison makes sense, that is, on CbV normalisable terms.
Corollary 2
(CbNeed duplicates as wisely as CbV). Let \(d:t \ {\xrightarrow {}}{}_{\mathrm{cbv}}^{*} u\) with \({\mathsf{{normal}} _\mathrm{cbv}} ({u})\). Then there is \(d':t \ {\xrightarrow {}}{}_{\mathrm{need}}^{*} s\) with \(\mathsf{{normal}} ({s})\) and \(d'_{{\mathtt m}} \le d_{{\mathtt m}}\) and \(d'_{{\mathtt e}} \le d_{{\mathtt e}}\).
8 Conclusions
Contributions. This paper introduces a multi type system for CbNeed evaluation, carefully blending ingredients from multi type systems for CbN and CbV evaluation in the literature. Notably, it is the first type system whose minimal derivations—explicitly characterised—provide exact bounds for evaluation lengths. It also characterises CbNeed termination, and thus its judgements provide an adequate relational semantics.
The technical development is simple, and uniform with respect to those of CbN and CbV multi type systems. The typing rules count evaluation steps following exactly the same schema of the CbN and CbV rules. The proofs of correctness and completeness also follow exactly the same structure.
A further side contribution of the paper is a new fundamental result of CbNeed, formally stating that it duplicates as wisely as CbV. More precisely, the CbV multi type system is (quantitatively) correct with respect to CbNeed evaluation. Pleasantly, our presentations of CbV and CbNeed provide the result for free. This result dualizes the other fundamental theorem stating that CbNeed erases as wisely as CbN, usually formulated as termination equivalence, and recently reproved by Kesner using CbN multi types [40].
Future Work. Recently, Barenbaum et al. extended CbNeed to strong evaluation [14], and it is natural to try to extend our type system as well. The definition of the system, in particular the extension of tight derivations to that setting, seems however far from being evident. Barembaum, Bonelli, and Mohamed also apply CbN multi types to a CbNeed calculus extended with pattern matching and fixpoints [15], that might be interesting to refine along the lines of our work.
An orthogonal direction is the study of the denotational models of CbNeed. It would be interesting to have a categorical semantics of CbNeed, as well as a categorical way of discriminating our quantitative precise model from the quantitatively lax one given by CbN multi types. It would also be interesting to obtain game semantics of CbNeed, hopefully satisfying a strong correspondence with our multi types in the style of what happens in CbN [30, 31, 51, 56].
A further, unconventional direction is to dualise the inception of the CbNeed type system trying to mix silly duplication from CbN and silly erasure from CbV, obtaining—presumably—a multi types system measuring a perpetual strategy.
Footnotes
 1.
If a term \(t\) admits both converging and diverging evaluation sequences then the diverging sequences occur in erasable subterms of \(t\), which is why CbN avoids them.
 2.
The CbN translation maps \(A\Rightarrow B\) to Open image in new window , while the CbV maps it to Open image in new window , or equivalently to Open image in new window .
 3.
The new terminology is due to the fact that a nonidempotent intersection \(A \wedge A \wedge B \wedge C\) can be seen as a multiset \([ A,A,B,C ] \).
Notes
Acknowledgements
This work has been partially funded by the ANR JCJC grant COCA HOLA (ANR16CE4000401) and by the EPSRC grant EP/R029121/1 “Typed LambdaCalculi with Sharing and Unsharing”.
References
 1.Accattoli, B.: An abstract factorization theorem for explicit substitutions. In: 23rd International Conference on Rewriting Techniques and Applications (RTA 2012). LIPIcs, vol. 15, pp. 6–21 (2012). https://doi.org/10.4230/LIPIcs.RTA.2012.6
 2.Accattoli, B.: Proof nets and the linear substitution calculus. In: Fischer, B., Uustalu, T. (eds.) ICTAC 2018. LNCS, vol. 11187, pp. 37–61. Springer, Cham (2018). https://doi.org/10.1007/9783030025083_3CrossRefGoogle Scholar
 3.Accattoli, B., Barenbaum, P., Mazza, D.: Distilling abstract machines. In: Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming (ICFP 2014), pp. 363–376 (2014). https://doi.org/10.1145/2628136.2628154
 4.Accattoli, B., Barras, B.: Environments and the complexity of abstract machines. In: Proceedings of the 19th International Symposium on Principles and Practice of Declarative Programming (PPDP 2017), pp. 4–16. ACM (2017). https://doi.org/10.1145/3131851.3131855
 5.Accattoli, B., Barras, B.: The negligible and yet subtle cost of pattern matching. In: Chang, B.Y.E. (ed.) APLAS 2017. LNCS, vol. 10695, pp. 426–447. Springer, Cham (2017). https://doi.org/10.1007/9783319712376_21CrossRefGoogle Scholar
 6.Accattoli, B., Bonelli, E., Kesner, D., Lombardi, C.: A nonstandard standardization theorem. In: The 41st Annual Symposium on Principles of Programming Languages (POPL 2014), pp. 659–670. ACM (2014). https://doi.org/10.1145/2535838.2535886
 7.Accattoli, B., GrahamLengrand, S., Kesner, D.: Tight typings and split bounds. PACMPL 2(ICFP), 94:1–94:30 (2018). https://doi.org/10.1145/3236789CrossRefGoogle Scholar
 8.Accattoli, B., Guerrieri, G.: Types of fireballs. In: Ryu, S. (ed.) APLAS 2018. LNCS, vol. 11275, pp. 45–66. Springer, Cham (2018). https://doi.org/10.1007/9783030027681_3CrossRefGoogle Scholar
 9.Accattoli, B., Guerrieri, G., Leberle, M.: Types by Need (Extended Version). CoRR abs/1902.05945 (2019)Google Scholar
 10.Accattoli, B., Sacerdoti Coen, C.: On the value of variables. Inf. Comput. 255, 224–242 (2017). https://doi.org/10.1016/j.ic.2017.01.003MathSciNetCrossRefzbMATHGoogle Scholar
 11.Ariola, Z.M., Felleisen, M.: The callbyneed lambda calculus. J. Funct. Program. 7(3), 265–301 (1997)MathSciNetCrossRefGoogle Scholar
 12.Ariola, Z.M., Felleisen, M., Maraist, J., Odersky, M., Wadler, P.: The callbyneed lambda calculus. In: Conference Record of POPL 1995: 22nd Symposium on Principles of Programming Languages, pp. 233–246. ACM Press (1995). https://doi.org/10.1145/199448.199507
 13.Ariola, Z.M., Herbelin, H., Saurin, A.: Classical callbyneed and duality. In: Ong, L. (ed.) TLCA 2011. LNCS, vol. 6690, pp. 27–44. Springer, Heidelberg (2011). https://doi.org/10.1007/9783642216916_6CrossRefzbMATHGoogle Scholar
 14.Balabonski, T., Barenbaum, P., Bonelli, E., Kesner, D.: Foundations of strong call by need. PACMPL 1(ICFP), 20:1–20:29 (2017). https://doi.org/10.1145/3110264CrossRefGoogle Scholar
 15.Barenbaum, P., Bonelli, E., Mohamed, K.: Pattern matching and fixed points: resource types and strong callbyneed: extended abstract. In: Proceedings of the 20th International Symposium on Principles and Practice of Declarative Programming (PPDP 2018), pp. 6:1–6:12. ACM (2018). https://doi.org/10.1145/3236950.3236972
 16.Barras, B.: Autovalidation d’un système de preuves avec familles inductives. Ph.D. thesis, Université Paris 7 (1999)Google Scholar
 17.Bernadet, A., GrahamLengrand, S.: Nonidempotent intersection types and strong normalisation. Logical Methods Comput. Sci. 9(4) (2013). https://doi.org/10.2168/LMCS9(4:3)2013
 18.Bucciarelli, A., Ehrhard, T., Manzonetto, G.: A relational semantics for parallelism and nondeterminism in a functional setting. Ann. Pure Appl. Logic 163(7), 918–934 (2012). https://doi.org/10.1016/j.apal.2011.09.008MathSciNetCrossRefzbMATHGoogle Scholar
 19.Bucciarelli, A., Kesner, D., Ronchi Della Rocca, S.: Inhabitation for nonidempotent intersection types. Logical Methods Comput. Sci. 14(3) (2018). https://doi.org/10.23638/LMCS14(3:7)2018
 20.Bucciarelli, A., Kesner, D., Ventura, D.: Nonidempotent intersection types for the lambdacalculus. Logic J. IGPL 25(4), 431–464 (2017). https://doi.org/10.1093/jigpal/jzx018MathSciNetCrossRefzbMATHGoogle Scholar
 21.Carraro, A., Guerrieri, G.: A semantical and operational account of callbyvalue solvability. In: Muscholl, A. (ed.) FoSSaCS 2014. LNCS, vol. 8412, pp. 103–118. Springer, Heidelberg (2014). https://doi.org/10.1007/9783642548307_7CrossRefzbMATHGoogle Scholar
 22.de Carvalho, D.: Sémantiques de la logique linéaire et temps de calcul. Ph.D. thesis, Université AixMarseille II (2007)Google Scholar
 23.de Carvalho, D.: Execution time of \(\lambda \)terms via denotational semantics and intersection types. Math. Struct. Comput. Sci. 28(7), 1169–1203 (2018). https://doi.org/10.1017/S0960129516000396MathSciNetCrossRefzbMATHGoogle Scholar
 24.de Carvalho, D., Pagani, M., Tortora de Falco, L.: A semantic measure of the execution time in linear logic. Theoret. Comput. Sci. 412(20), 1884–1902 (2011). https://doi.org/10.1016/j.tcs.2010.12.017MathSciNetCrossRefzbMATHGoogle Scholar
 25.de Carvalho, D., Tortora de Falco, L.: A semantic account of strong normalization in linear logic. Inf. Comput. 248, 104–129 (2016). https://doi.org/10.1016/j.ic.2015.12.010
 26.Chang, S., Felleisen, M.: The callbyneed lambda calculus, revisited. In: Seidl, H. (ed.) ESOP 2012. LNCS, vol. 7211, pp. 128–147. Springer, Heidelberg (2012). https://doi.org/10.1007/9783642288692_7CrossRefGoogle Scholar
 27.Coppo, M., DezaniCiancaglini, M.: A new type assignment for \(\lambda \)terms. Arch. Math. Log. 19(1), 139–156 (1978). https://doi.org/10.1007/BF02011875MathSciNetCrossRefzbMATHGoogle Scholar
 28.Coppo, M., DezaniCiancaglini, M.: An extension of the basic functionality theory for the \(\lambda \)calculus. Notre Dame J. Formal Logic 21(4), 685–693 (1980). https://doi.org/10.1305/ndjfl/1093883253MathSciNetCrossRefzbMATHGoogle Scholar
 29.Danvy, O., Zerny, I.: A synthetic operational account of callbyneed evaluation. In: 15th International Symposium on Principles and Practice of Declarative Programming (PPDP 2013), pp. 97–108. ACM (2013). https://doi.org/10.1145/2505879.2505898
 30.Di Gianantonio, P., Honsell, F., Lenisa, M.: A type assignment system for game semantics. Theor. Comput. Sci. 398(1–3), 150–169 (2008). https://doi.org/10.1016/j.tcs.2008.01.023MathSciNetCrossRefzbMATHGoogle Scholar
 31.Di Gianantonio, P., Lenisa, M.: Innocent game semantics via intersection type assignment systems. In: Computer Science Logic 2013 (CSL 2013). LIPIcs, vol. 23, pp. 231–247 (2013). https://doi.org/10.4230/LIPIcs.CSL.2013.231
 32.DíazCaro, A., Manzonetto, G., Pagani, M.: Callbyvalue nondeterminism in a linear logic type discipline. In: Artemov, S., Nerode, A. (eds.) LFCS 2013. LNCS, vol. 7734, pp. 164–178. Springer, Heidelberg (2013). https://doi.org/10.1007/9783642357220_12CrossRefGoogle Scholar
 33.Downen, P., Maurer, L., Ariola, Z.M., Varacca, D.: Continuations, processes, and sharing. In: Proceedings of the 16th International Symposium on Principles and Practice of Declarative Programming (PPDP 2014), pp. 69–80. ACM (2014). https://doi.org/10.1145/2643135.2643155
 34.Ehrhard, T.: Collapsing nonidempotent intersection types. In: Computer Science Logic (CSL 2012)  26th International Workshop/21st Annual Conference of the EACSL. LIPIcs, vol. 16, pp. 259–273 (2012). https://doi.org/10.4230/LIPIcs.CSL.2012.259
 35.Ehrhard, T., Guerrieri, G.: The bang calculus: an untyped lambdacalculus generalizing callbyname and callbyvalue. In: Proceedings of the 18th International Symposium on Principles and Practice of Declarative Programming (PPDP 2016), pp. 174–187. ACM (2016). https://doi.org/10.1145/2967973.2968608
 36.Garcia, R., Lumsdaine, A., Sabry, A.: Lazy evaluation and delimited control. In: Proceedings of the 36th Symposium on Principles of Programming Languages (POPL 2009), pp. 153–164. ACM (2009). https://doi.org/10.1145/1480881.1480903
 37.Gardner, P.: Discovering needed reductions using type theory. In: Hagiya, M., Mitchell, J.C. (eds.) TACS 1994. LNCS, vol. 789, pp. 555–574. Springer, Heidelberg (1994). https://doi.org/10.1007/3540578870_115CrossRefGoogle Scholar
 38.Girard, J.Y.: Linear logic. Theoret. Comput. Sci. 50, 1–102 (1987). https://doi.org/10.1016/03043975(87)900454MathSciNetCrossRefzbMATHGoogle Scholar
 39.Guerrieri, G.: Towards a semantic measure of the execution time in callbyvalue lambdacalculus. In: Proceedings of ITRS 2018 (2018, to appear)Google Scholar
 40.Kesner, D.: Reasoning about callbyneed by means of types. In: Jacobs, B., Löding, C. (eds.) FoSSaCS 2016. LNCS, vol. 9634, pp. 424–441. Springer, Heidelberg (2016). https://doi.org/10.1007/9783662496305_25CrossRefzbMATHGoogle Scholar
 41.Kesner, D., Vial, P.: Types as resources for classical natural deduction. In: 2nd International Conference on Formal Structures for Computation and Deduction (FSCD 2017). LIPIcs, vol. 84, pp. 24:1–24:17 (2017). https://doi.org/10.4230/LIPIcs.FSCD.2017.24
 42.Kesner, D., Ríos, A., Viso, A.: Callbyneed, neededness and all that. In: Baier, C., Dal Lago, U. (eds.) FoSSaCS 2018. LNCS, vol. 10803, pp. 241–257. Springer, Cham (2018). https://doi.org/10.1007/9783319893662_13CrossRefzbMATHGoogle Scholar
 43.Kfoury, A.J.: A linearization of the lambdacalculus and consequences. J. Logic Comput. 10(3), 411–436 (2000). https://doi.org/10.1093/logcom/10.3.411MathSciNetCrossRefzbMATHGoogle Scholar
 44.Krivine, J.L.: LambdaCalculus, Types and Models. Ellis Horwood Series in Computers and Their Applications. Ellis Horwood, Upper Saddle River, NJ, USA (1993)Google Scholar
 45.Kutzner, A., SchmidtSchauß, M.: A nondeterministic callbyneed lambda calculus. In: Proceedings of the Third International Conference on Functional Programming (ICFP 1998), pp. 324–335. ACM (1998). https://doi.org/10.1145/289423.289462
 46.Launchbury, J.: A natural semantics for lazy evaluation. In: Conference Record of the Twentieth Annual Symposium on Principles of Programming Languages (POPL 1993), pp. 144–154. ACM Press (1993). https://doi.org/10.1145/158511.158618
 47.Maraist, J., Odersky, M., Turner, D.N., Wadler, P.: Callbyname, callbyvalue, callbyneed and the linear lambda calculus. Theor. Comput. Sci. 228(1–2), 175–210 (1999). https://doi.org/10.1016/S03043975(98)003582MathSciNetCrossRefzbMATHGoogle Scholar
 48.Maraist, J., Odersky, M., Wadler, P.: The callbyneed lambda calculus. J. Funct. Program. 8(3), 275–317 (1998)MathSciNetCrossRefGoogle Scholar
 49.Mazza, D., Pellissier, L., Vial, P.: Polyadic approximations, fibrations and intersection types. PACMPL 2(POPL), 6:1–6:28 (2018). https://doi.org/10.1145/3158094
 50.Neergaard, P.M., Mairson, H.G.: Types, potency, and idempotency: why nonlinearity and amnesia make a type system work. In: Proceedings of the Ninth International Conference on Functional Programming (ICFP 2004), pp. 138–149. ACM (2004). https://doi.org/10.1145/1016850.1016871
 51.Ong, C.L.: Quantitative semantics of the lambda calculus: some generalisations of the relational model. In: 32nd Annual Symposium on Logic in Computer Science (LICS 2017), pp. 1–12. IEEE Computer Society (2017). https://doi.org/10.1109/LICS.2017.8005064
 52.Paolini, L., Piccolo, M., Ronchi Della Rocca, S.: Essential and relational models. Math. Struct. Comput. Sci. 27(5), 626–650 (2017). https://doi.org/10.1017/S0960129515000316
 53.Pédrot, P.M., Saurin, A.: Classical byneed. In: Thiemann, P. (ed.) ESOP 2016. LNCS, vol. 9632, pp. 616–643. Springer, Heidelberg (2016). https://doi.org/10.1007/9783662494981_24CrossRefGoogle Scholar
 54.Pottinger, G.: A type assignment for the strongly normalizable \(\lambda \)terms. In: Seldin, J., Hindley, J. (eds.) To H.B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, pp. 561–578. Academic Press, Cambridge (1980)Google Scholar
 55.Sestoft, P.: Deriving a lazy abstract machine. J. Funct. Program. 7(3), 231–264 (1997)MathSciNetCrossRefGoogle Scholar
 56.Tsukada, T., Ong, C.L.: Plays as resource terms via nonidempotent intersection types. In: Proceedings of the 31st Annual Symposium on Logic in Computer Science (LICS 2016), pp. 237–246. ACM (2016). https://doi.org/10.1145/2933575.2934553
 57.Wadsworth, C.P.: Semantics and pragmatics of the lambdacalculus. Ph.D. thesis, University of Oxford (1971). Chapter 4Google Scholar
Copyright information
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.
The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.