Call-by-need, neededness and all that

We show that call-by-need is observationally equivalent to weak-head needed reduction. The proof of this result uses a semantical argument based on a (non-idempotent) intersection type system called $\mathcal{V}$. Interestingly, system $\mathcal{V}$ also allows to syntactically identify all the weak-head needed redexes of a term.


Introduction
One of the fundamental notions underlying this paper is the one of needed reduction in λ-calculus, which is to be used here to understand (lazy) evaluation of functional programs. Key notions are those of reducible and non-reducible programs: the former are programs (represented by λ-terms) containing nonevaluated subprograms, called reducible expressions (redexes), whereas the latter can be seen as definitive results of computations, called normal forms. It turns out that every reducible program contains a special kind of redex known as needed or, in other words, every λ-term not in normal form contains a needed redex. A redex r is said to be needed in a λ-term t if r has to be contracted (i.e. evaluated) sooner or later when reducing t to normal form, or, informally said, if there is no way of avoiding r to reach a normal form.
The needed strategy, which always contracts a needed redex, is normalising [8], i.e. if a term can be reduced (in any way) to a normal form, then contraction of needed redexes necessarily terminates. This is an excellent starting point to design an evaluation strategy, but unfortunately, neededness of a redex is not decidable [8]. As a consequence, real implementations of functional languages cannot be directly based on this notion.
Our goal is, however, to establish a clear connection between the semantical notion of neededness and different implementations of lazy functional languages (e.g. Miranda or Haskell). Such implementations are based on call-by-need calculi, pioneered by Wadsworth [19], and extensively studied e.g. in [3]. Indeed, call-by-need calculi fill the gap between the well-known operational semantics of the call-by-name λ-calculus and the actual implementations of lazy functional languages. While call-by-name re-evaluates an argument each time it is used -an operation which is quite expensive-call-by-need can be seen as a memoized version of call-by-name, where the value of an argument is stored the first time it is

Preliminaries
This section introduces some standard definitions and notions concerning the reduction strategies studied in this paper, that is, call-by-name, head and weakhead reduction, and neededness, this later notion being based on the theory of residuals [7].

The Call-By-Name Lambda-Calculus
Given a countable infinite set X of variables x, y, z, . . . we consider the following grammar: (Terms) t, u ::= x ∈ X | t u | λx.t (Values) v ::= λx.t (Contexts) C ::= | C t | t C | λx.C (Name contexts) E ::= | E t The set of λ-terms is denoted by T a . We use I, K and Ω to denote the terms λx.x, λx.λy.x and (λx.x x) (λx.x x) respectively. We use C t (resp. E t ) for the term obtained by replacing the hole of C (resp. E) by t. The sets of free and bound variables of a term t, written respectively fv(t) and bv(t), are defined as usual [7]. We work with the standard notion of α-conversion, i.e. renaming of bound variables for abstractions; thus for example λx.x y = α λz.z y.

Head, Weak-Head and Leftmost Reductions
In order to introduce different notions of reduction, we start by formalising the general mechanism of reduction which consists in contracting a redex at some specific occurrence. Occurrences are finite words over the alphabet {0, 1}. We use ǫ to denote the empty word and notation a n for n ∈ N concatenations of some letter a of the alphabet. The set of occurrences of a given term is defined by induction as follows: Given two occurrences p and q, we use the notation p ≤ q to mean that p is a prefix of q, i.e. there is p ′ such that pp ′ = q. We denote by t| p the subterm of t at occurrence p, defined as expected [4], thus for example ((λx.y) z)| 00 = y. The set of redex occurrences of t is defined by roc(t) def = {p ∈ oc(t) | t| p = (λx.s) u}.
We use the notation r : t → β t ′ to mean that r ∈ roc(t) and t reduces to t ′ by contracting the redex at occurrence r, e.g. 000 : (λx.(λy.y) x x) z → β (λx.x x) z. This notion is extended to reduction sequences as expected, and noted ρ : t ։ β t ′ , where ρ is the list of all the redex occurrences contracted along the reduction sequence. We use nil to denote the empty reduction sequence, so that nil : t ։ β t holds for every term t.
Any term t has exactly one of the following forms: λx 1 .. . . λx n .y t 1 . . . t m or λx 1 .. . . λx n .(λy.s) u t 1 . . . t m with n, m ≥ 0. In the latter case we say that (λy.s) u is the head redex of t, while in the former case there is no head redex. Moreover, if n = 0, we say that (λy.s) u is the weak-head redex of t. In terms of occurrences, the head redex of t is the minimal redex occurrence of the form 0 n with n ≥ 0. In particular, if it satisfies that t| 0 k is not an abstraction for every k ≤ n, it is the weak-head redex of t. A reduction sequence contracting at each step the head redex (resp. weak-head redex) of the corresponding term is called the head reduction (resp. weak-head reduction).
Given two redex occurrences r, r ′ ∈ roc(t), we say that r is to-the-left of r ′ if the anchor of r is to the left of the anchor of r ′ . Thus for example, the redex occurrence 0 is to-the-left of 1 in the term (I x) (I y), and ǫ is to-the-left of 00 in (λx.(I I)) z. Alternatively, the relation to-the-left can be understood as a dictionary order between redex occurrences, i.e. r is to-the-left of r ′ if either r ′ = rq with q = ǫ (i.e. r is a proper prefix of r ′ ); or r = p0q and r ′ = p1q ′ (i.e. they share a common prefix and r is on the left-hand side of an application while r ′ is on the right-hand side). Notice that in any case this implies r ′ ≤ r. Since this notion defines a total order on redexes, every term not in normal form has a unique leftmost redex . The term t leftmost reduces to t ′ if t reduces to t ′ and the reduction step contracts the leftmost redex of t. For example, (I x) (I y) leftmost reduces to x (I y) and (λx.(I I)) z leftmost reduces to I I. This notion extends to reduction sequences as expected.

Towards neededness
Needed reduction is based on two fundamental notions: that of residual, which describes how a given redex is traced all along a reduction sequence, and that of normal form, which gives the form of the expected result of the reduction sequence. This section extends the standard notion of needed reduction [8] to those of head and weak-head needed reductions.
Notice that p/r ⊆ oc(t ′ ) where r : t → β t ′ . Furthermore, if p is the occurrence of a redex in t (i.e. p ∈ roc(t)), then p/r ⊆ roc(t ′ ), and each position in p/r is called a residual of p after reducing r. This notion is extended to sets of redex occurrences, indeed, the residuals of P after r in t are P/r def = p∈P p/r. In particular ∅/r = ∅. Given ρ : t ։ β t ′ and P ⊆ roc(t), the residuals of P after the sequence ρ are: P/nil def = P and P/rρ ′ def = (P/r)/ρ ′ . Stability of the to-the-left relation makes use of the notion of residual: Lemma 1. Given a term t, let l, r, s ∈ roc(t) such that l is to-the-left of r, s ≤ l and s : t → β t ′ . Then, l ∈ roc(t ′ ) and l is to-the-left of r ′ for every r ′ ∈ r/s.

Proof.
First, notice that s ≤ l implies l/s = {l}, then it is immediate to see that l ∈ roc(t ′ ). If s ≤ r, then r/s = {r} and the result holds immediately. Otherwise, s ≤ r implies s ≤ r ′ for every r ′ ∈ r/s by definition. From l is to-the-left of r, we may distinguish two cases: either r = lq with q = ǫ; or r = p1q and l = p0q ′ . Both cases imply that l and r share a common prefix, say p ′ (resp. l or p on each case). From s ≤ l and s ≤ r we know that p ′ is a proper prefix of s. Thus, it is a proper prefix of r ′ too, i.e. either r ′ = lq ′′ with q ′′ = ǫ; or r ′ = p1q ′′ . Hence, l is to-the-left of r ′ for every r ′ ∈ r/s. Notice that this result does not only implies that the leftmost redex is preserved by reduction of other redexes, but also that the residual of the leftmost redex occurs in exactly the same occurrence as the original one. Corollary 1. Given a term t, and l ∈ roc(t) the leftmost redex of t, if the reduction ρ : t ։ β t ′ contracts neither l nor any of its residuals, then l ∈ roc(t ′ ) is the leftmost redex of t ′ .
Proof. By induction on the length of ρ using Lem. 1.

Notions of Normal Form
The expected result of evaluating a program is specified by means of some appropriate notion of normal form. Given any relation → R , a term t is said to be in given an R-normalising term t, we can define the set of R-normal forms of t as In particular, it turns out that a term in weak-head β-normal form (WHNF β ) is of the form x t 1 . . . t n (n ≥ 0) or λx.t, where t, t 1 , . . . , t n are arbitrary terms, i.e. it has no weak-head redex. The set of weak-head β-normal Similarly, a term in head β-normal form (HNF β ) turns out to be of the form λx 1 .. . . λx n .x t 1 . . . t m (n, m ≥ 0), i.e. it has no head redex. The set of head β-normal forms of t is given by Last, any term in β-normal form (NF β ) has the form λx 1 .. . . λx n .x t 1 . . . t m (n, m ≥ 0) where t 1 , . . . , t m are themselves in β-normal form. It is well-known that the set nf β (t) is a singleton, so we may use it either as a set or as its unique element.
It is worth noticing that NF β ⊂ HNF β ⊂ WHNF β . Indeed, the inclusions are strict, for instance λx.(λy.y) z is in weak-head but not in head β-normal form, while x ((λy.y) x) z is in head but not in β-normal form.

Notions of Needed Reduction
The different notions of normal form considered in Sec. 3.2 suggest different notions of needed reduction, besides the standard one in the literature [8]. Indeed, consider r ∈ roc(t). We say that r is used in a reduction sequence ρ iff ρ reduces r or some residual of r. Then: 1. r is needed in t if every reduction sequence from t to β-normal form uses r; 2. r is head needed in t if every reduction sequence from t to head β-normal form uses r; 3. r is weak-head needed in t if every reduction sequence of t to weak-head β-normal form uses r.
A one-step reduction → β is needed (resp. head or weak-head needed ), noted → nd (resp. → hnd or → whnd ), if the contracted redex is needed (resp. head or weak-head needed). A reduction sequence ։ β is needed (resp. head or weak-head needed ), noted ։ nd (resp. ։ hnd or ։ whnd ), if every reduction step in the sequence is needed (resp. head or weak-head needed).
For instance, consider the reduction sequence: (λy.λx.I x (I I r1 )) (I I) → nd (λy.λx.I x r2 I) (I I) → nd (λy.λx.x I) (I I) r3 → nd λx.x I which is needed but not head needed, since redex r 1 might not be contracted to reach a head normal form: (λy.λx.I x r2 (I I)) (I I) → hnd (λy.λx.x (I I)) (I I) r3 → hnd λx.x (I I) Moreover, this second reduction sequence is head needed but not weak-head needed since only redex r 3 is needed to get a weak-head normal form: Notice that the following equalities hold: NF nd = NF β , NF hnd = HNF β and NF whnd = WHNF β .
Leftmost redexes and reduction sequences are indeed needed: The leftmost redex in any term not in normal form (resp. head or weak-head normal form) is needed (resp. head or weak-head needed).
Proof. Since the existing proof [8] does not extend to weak-head normal forms, we give here an alternative argument which does not only cover the standard case of needed reduction but also the new ones of head and weak-head reductions. Let t be a term not in normal form (resp. head normal form or weak-head normal form) and let us consider ρ : t ։ β t ′ such that t ′ is a normal form (resp. head normal form or weak-head normal form). Assume towards a contradiction that the leftmost redex l of t is not used in ρ. By Cor. 1 the occurrence l is still the leftmost redex of t ′ . This leads to a contradiction with t ′ being a normal form (resp. head normal form or weak-head normal form), in particular because the leftmost redex of a term not in head normal form (resp. weak-head normal form) is necessarily the head redex (resp. weak-head redex). Theorem 1. Let r ∈ roc(t) and ρ : t ։ β t ′ be the leftmost reduction (resp. head reduction or weak-head reduction) starting with t such that . Then, r is needed (resp. head or weak-head needed) in t iff r is used in ρ.
Proof. ⇒) Immediate by definition of needed (resp. head or weak-head needed).
⇐) Let ρ = ρ ′ r ′ ρ ′′ with r ′ ∈ r/ρ ′ . By hypothesis r ′ is the leftmost redex of its corresponding term. By Lem. 2, r ′ is needed (resp. head or weak-head needed). Notice that, given a redex s not needed in t, it follows from the definition that no residual of s is needed either. Therefore, r ′ needed (resp. head or weak-head needed) implies r needed (resp. head or weak-head needed) as well.
Notice that the weak-head reduction is a prefix of the head reduction, which is in turn a prefix of the leftmost reduction to normal form. As a consequence, it is immediate to see that every weak-head needed redex is in particular head needed, and every head needed redex is needed as well. For example, consider: where r 3 is a needed redex but not head needed nor weak-head needed. However, r 2 is both needed and head needed, while r 1 is the only weak-head needed redex in the term, and r 4 is not needed at all.

The Type System V
In this section we recall the (non-idempotent) intersection type system V [14] -an extension of those in [13,12]-used here to characterise normalising terms w.r.t. the weak-head strategy. More precisely, we show that t is typable in system V if and only if t is normalising when only weak-head needed redexes are contracted. This characterisation is used in Sec. 9 to conclude that the weak-head needed strategy is observationally equivalent to the call-by-need calculus (to be introduced in Sec. 8).
Given a constant type a that denotes answers and a countable infinite set B of base type variables α, β, γ, . . ., we define the following sets of types: The empty multiset is denoted by { {} }. We remark that types are strict [17], i.e. the right-hand sides of functional types are never multisets. Thus, the general form of a type is M 1 → . . . → M n → τ with τ being the constant type or a base type variable.
Typing contexts (or just contexts), written Γ, ∆, are functions from variables to multiset types, assigning the empty multiset to all but a finite set of variables. The domain of Γ is given by . This notion is extended to several contexts as expected, so that + i∈I Γ i denotes a finite union of contexts (when I = ∅ the notation is to be understood as the empty context). We write Type judgements have the form Γ ⊢ t : τ , where Γ is a typing context, t is a term and τ is a type. The intersection type system V for the λ-calculus is given in Fig. 1. The constant type a in rule (val) is used to type values. The axiom (ax) is relevant (there is no weakening) and the rule ( → e) is multiplicative. Note that the argument of an application is typed #(I) times by the premises of rule ( → e). A particular case is when I = ∅: the subterm u occurring in the typed term t u turns out to be untyped.
A (type) derivation is a tree obtained by applying the (inductive) typing rules of system V. The notation ⊲ V Γ ⊢ t : τ means there is a derivation of the judgement Γ ⊢ t : τ in system V. The term t is typable in system V, or V-typable, iff t is the subject of some derivation, i.e. iff there are Γ and τ such that ⊲ V Γ ⊢ t : τ . We use the capital Greek letters Φ, Ψ, . . . to name type derivations, by writing for example Φ ⊲ V Γ ⊢ t : τ . For short, we usually denote with Φ t a derivation with subject t for some type and context. The size of the derivation Φ, denoted by sz(Φ), is defined as the number of nodes of the corresponding derivation tree. We write RULE(Φ) ∈ {(ax), ( → i), ( → e)} to access the last rule applied in the derivation Φ. Likewise, PREM(Φ) is the multiset of proper maximal subderivations of Φ. For instance, given We also use functions CTXT(Φ), SUBJ(Φ) and TYPE(Φ) to access the context, subject and type of the judgement in the root of the derivation tree respectively. For short, we also use notation Φ(x) to denote the type associated to the variable x in the typing environment of the conclusion of Φ (i.e. Φ(x) def = CTXT(Φ)(x)).
Intersection type systems can usually be seen as models [11], i.e. typing is stable by convertibility: if t is typable and t = β t ′ , then t ′ is typable too. This property splits in two different statements known as subject reduction and subject expansion respectively, the first one giving stability of typing by reduction, the second one by expansion. In the particular case of non-idempotent types, subject reduction refines to weighted subject-reduction, stating that not only typability is stable by reduction, but also that the size of type derivations is decreasing. Moreover, this decrease is strict when reduction is performed on special occurrences of redexes, called typed occurrences. We now introduce all these concepts.
Given a type derivation Φ, the set TOC(Φ) of typed occurrences of Φ, which is a subset of oc(SUBJ(Φ)), is defined by induction on the last rule of Φ.
Remark 1. The weak-head redex of a typed term is always a typed occurrence.
For convenience we introduce an alternative way to denote type derivations. We refer to AX(x, τ ) as the result of applying (ax) with subject x and type τ : We denote with VAL(x, t) the result of applying (val) abstracting x and term t: We refer to ABS(x, Φ t ) as the result of applying ( → i) with premise Φ t and abstracting variable x: Likewise, we write APP(Φ t , u, (Φ i u ) i∈I ) for the result of applying ( → e) with premises Φ t and (Φ i u ) i∈I , and argument u (the argument u is untyped when I = ∅). Note that this application is valid provided that TYPE Given Φ and p ∈ TOC(Φ), the multiset Φ| p of all the subderivations of Φ at occurrence p is inductively defined as follows: Given type derivations Φ, (Ψ i ) i∈I and a position p ∈ oc(SUBJ(Φ)), replacing the subderivations of Φ at occurrence p by (Ψ i ) i∈I , written Φ[(Ψ i ) i∈I ] p , is a type derivation inductively defined as follows, assuming #(Φ| p ) = #(I) and SUBJ(Ψ i ) = SUBJ(Ψ j ) for every i, j ∈ I (we call s the unique subject of all these derivations): where s is the unique subject of all the derivations Ψ i and r ′ [r] q denotes the replacement of the subterm r ′ | q by r in r ′ (variable capture is allowed). Remark that the decomposition of I into the sets I j (j ∈ J) is non-deterministic, thus replacement turns out to be a non-deterministic operation.
We can now state the two main properties of system V, whose proofs can be found in Sec. 7 of [9].

Theorem 2 (Weighted Subject Reduction). Let
Note that weighted subject reduction implies that reduction of typed redex occurrences turns out to be normalising.

Substitution and Reduction on Derivations
In order to relate typed redex occurrences of convertible terms, we now extend the notion of β-reduction to derivation trees, by making use of a natural and basic concept of typed substitution. In contrast to substitution and β-reduction on terms, these operations are now both non-deterministic on derivation trees (see [18] for discussions and examples). Given a variable x and type deriva- i∈I by making an abuse of notation, is a type derivation induc- if there is no capture of the variable y.
if there is no capture of the variable y.
Remark that the decomposition of I into I ′ and the sets I j (j ∈ J) is non-deterministic, thus substitution of derivation trees turns out to be a non-deterministic operation.
Intuitively, the typed substitution replaces typed occurrences of x in Φ t by a corresponding derivation Φ i u matching the same type, where such a matching is chosen in a non-deterministic way. Moreover, it also substitutes all untyped occurrences of x by u, where this untyped operation is completely deterministic. Thus, for example, consider the following substitution, where Φ KI is defined in Sec. 4: The following lemma relates the typed occurrences of the trees composing a substitution and those of the substituted tree itself: Proof. By induction on Φ t .
Based on the previous notion of substitutions on derivations, we are now able to introduce (non-deterministic) reduction on derivation trees. The reduction relation → β on derivation trees is then defined by first considering the following basic rewriting rules.
1. For typed β-redexes: For β-redexes in untyped occurrences, with u → β u ′ : As in the case of the λ-calculus, where reduction is closed under usual term contexts, we need to close the previous relation under derivation tree contexts. However, a one-step reduction on a given subterm causes many one-step reductions in the corresponding derivation tree (recall Φ| p is defined to be a multiset). Then, informally, given a redex occurrence r of t, a type derivation Φ of t, and the multiset of minimal subderivations of Φ containing r, written M , we apply the reduction rules → β,ν,ξ to all the elements of M , thus obtaining a multiset M ′ , and we recompose the type derivation of the reduct of t.
To formalise this idea, given a type derivation Φ and an occurrence p ∈ oc(SUBJ(Φ)), we define the maximal typed prefix of p in Φ, written mtp Φ (p), as the unique prefix of p satisfying Notice that the multiset of subderivations of Φ at position mtp Φ (p) (i.e. Φ| mtp Φ (p) ) corresponds to the multiset of minimal subderivations of Φ containing p. For instance, consider the type derivation Φ KIΩ presented in Sec. 4: where TOC(Φ KIΩ ) = {ǫ, 0, 00, 01, 000, 0000}. Indeed, mtp ΦKIΩ (010) = 01 and the minimal subderivation of Φ KIΩ containing this occurrence is Then, given terms t and t ′ , and type derivations Φ and Φ ′ of t and t ′ respectively, we say that Φ reduces to where β,ν,ξ denotes the lifting to multisets of the basic rewriting rules introduced above by applying the same rule to all the elements of the multiset. This gives the reduction relation → β on trees. A reduction sequence on derivation trees contracting only redexes in typed positions is dubbed a typed reduction sequence.

Weak-Head Neededness and Typed Occurrences
This section presents one of our main results. It establishes a connection between weak-head needed redexes and typed redex occurrences. More precisely, we first show in Sec. 6.1 that every weak-head needed redex occurrence turns out to be a typed occurrence, whatever its type derivation is. The converse does not however hold. But, we show in Sec. 6.2 that any typed occurrence in a special kind of typed derivation (that we call principal) corresponds to a weak-head needed redex occurrence. We start with a technical lemma. Lemma 4. Let r : Φ t → β Φ t ′ and p ∈ oc(t) such that p = r and p = r0. Then, p ∈ TOC(Φ t ) iff there exists p ′ ∈ p/r such that p ′ ∈ TOC(Φ t ′ ).
Proof. If p = ǫ the result holds since ǫ/r = {ǫ} and ǫ ∈ TOC(Φ) for every possible Φ by definition. Then, assume p = ǫ. We proceed by induction on r.
r = 1r ′ . This case is symmetric to the one presented above. We have t = t 1 t 2 and t ′ = t 1 t ′ 2 with r ′ : t 2 → β t ′ 2 , and ) i∈I . Then, if p = 0q (i.e. r ≤ p) we may conclude by definition with p/r = {p}. Otherwise, p = 1q and p ∈ TOC for some k ∈ I. Thus, the result follows by definition from the inductive hypothesis.

Weak-Head Needed Redexes are Typed
In order to show that every weak-head needed redex occurrence corresponds to a typed occurrence in some type derivation we start by proving that typed occurrences do not come from untyped ones.
Theorem 4. Let r be a weak-head needed redex in t. Let Φ be a type derivation of t. Then, r ∈ TOC(Φ).
Proof. By Thm. 1, r is used in the weak-head reduction from t to t ′ ∈ WHNF β . By Rem. 1, the weak-head reduction contracts only typed redexes. Thus, r or some of its residuals is a typed occurrence in its corresponding derivation tree. Finally, we conclude by Lem. 5, r ∈ TOC(Φ).

Principally Typed Redexes are Weak-Head Needed
As mentioned before, the converse of Thm. 4 does not hold: there are some typed occurrences that do not correspond to any weak-head needed redex occurrence. This can be illustrated in the following examples (recall Φ KIΩ defined in Sec. 4): Indeed, the occurrence 0 (resp 1) in the term λy.KIΩ (resp. y (KIΩ)) is typed but not weak-head needed, since both terms are already in weak-head normal form. Fortunately, typing relates to redex occurrences if we restrict type derivations to principal ones: given a term t in weak-head β-normal form, the derivation Φ ⊲ V Γ ⊢ t : τ is normal principally typed if: Given a weak-head normalising term t such that Φ t ⊲ V Γ ⊢ t : τ , we say that Note in particular that the previous definition does not depend on the chosen weak-head normal form t ′ : suppose t ′′ ∈ whnf β (t) is another weak-head normal form of t, then t ′ and t ′′ are convertible terms by the Church-Rosser property [7] so that t ′ can be normal principally typed iff t ′′ can, by Thm. 2 and 3. Lemma 6. Let Φ t be a type derivation with subject t and r ∈ roc(t) ∩ TOC(Φ t ).
The notions of leftmost and weak-head needed reductions on (untyped) terms naturally extends to typed reductions on tree derivations. We thus have: Lemma 7. Let t be a weak-head normalising term and Φ t be principally typed. Then, a leftmost typed reduction sequence starting at Φ t is weak-head needed.
Proof. By induction on the leftmost typed sequence (called ρ). If ρ is empty the result is immediate. If not, we show that t has a typed weak-head needed redex (which is leftmost by definition) and conclude by inductive hypothesis. Indeed, assume t ∈ WHNF β . By definition Φ t is normal principally typed and thus it has no typed redexes. This contradicts ρ being non-empty. Hence, t has a weak-head redex r (i.e. t / ∈ WHNF β ). Moreover, r is both typed (by Rem. 1) and weak-head needed (by Lem. 2). Thus, we conclude.
Theorem 5. Let t be a weak-head normalising term, Φ t be principally typed and r ∈ roc(t) ∩ TOC(Φ t ). Then, r is a weak-head needed redex in t.
Proof. Let ρ : Φ t ։ β Φ t ′ be the leftmost typed reduction sequence where Φ t ′ is normal. Note that Φ t ′ exists by definition of principally typed. By Lem. 7, ρ is a weak-head needed reduction sequence. Moreover, by Lem. 6, r is used in ρ. Hence, r is a weak-head needed redex in t.
As a direct consequence of Thm. 4 and 5, given a weak-head normalising term t, the typed redex occurrences in its principally typed derivation (which always exists) correspond to its weak-head needed redexes. Hence, system V allows to identify all the weak-head needed redexes of a weak-head normalising term.

Characterising Weak-Head Needed Normalisation
This section presents one of the main pieces contributing to our observational equivalence result. Indeed, we relate typing with weak-head neededness by showing that any typable term in system V is normalising for weak-head needed reduction. This characterisation highlights the power of intersection types. We start by a technical lemma.
Proof. By induction on Φ analysing the last rule applied.
Let ρ : t 1 ։ β t n . We say that ρ is a left-to-right reduction sequence iff for every i < n if r i : t i → β t i+1 and l i is to the left of r i then, for every j > i such that r j : t j → β t j+1 we have that r j / ∈ {l i }/ρ ij where ρ ij : t i ։ β t j is the corresponding subsequence of ρ. In other words, for every j and every i < j, r j is not a residual of a redex to the left of r i (relative to the given reduction subsequence from t i to t j ) [7].
Left-to-right reductions define in particular standard strategies, which give canonical ways to construct reduction sequences from one term to another: Theorem 6 ( [7]). If t ։ β t ′ , there exists a left-to-right reduction from t to t ′ .
Proof. ⇒) By Thm. 2 we know that the strategy reducing only typed redex occurrences is normalising, i.e. there exist t ′ and Φ ′ such that t ։ β t ′ , Φ ′ ⊲ V Γ ⊢ t ′ : τ and Φ ′ normal. Then, by Lem. 8, t ′ ∈ WHNF β . By Thm. 6, there exists a left-to-right reduction ρ : t ։ β t ′ . Let us write ρ : t = t 1 ։ β t n ։ β t ′ such that t 1 , . . . , t n−1 / ∈ WHNF β and t n ∈ WHNF β . We claim that all reduction steps in t 1 ։ β t n are leftmost. Assume towards a contradiction that there exists k < n such that r : t k → β t k+1 and r is not the leftmost redex of t k (written l k ). Since ρ is a left-to-right reduction, no residual of l k is contracted after the k-th step. Thus, there is a reduction sequence from t k / ∈ WHNF β to t n ∈ WHNF β such that l k is not used in it. This leads to a contradiction with l k being weak-head needed in t k by Lem. 2.
This section describes the syntax and the operational semantics of the call-byneed lambda-calculus introduced in [1]. It is more concise than previous specifications of call-by-need [3,2,15,10], but it is operationally equivalent to them [6], so that our results could also be presented by using alternative specifications.
Given a countable infinite set X of variables x, y, z, . . . we define different syntactic categories for terms, values, list contexts, answers and need contexts: The call-by-need calculus, introduced in [1], is given by the set of terms T e and the reduction relation → need , the union of → dB and → lsv , which are, respectively, the closure by need contexts of the following rewriting rules: These rules avoid capture of free variables. An example of need-reduction sequence is the following, where the redex of each step is underlined for clearness: (λx 1 .I (x 1 I)) (λy.I y) → dB (I (x 1 I))[ As for call-by-name, reduction preserves free variables, i.e. t → need t ′ implies fv(t) ⊇ fv(t ′ ). Notice that call-by-need reduction is also weak, so that answers are not need-reducible.
The results in Sec. 7 are used here to prove soundness and completeness of callby-need w.r.t weak-head neededness, our second main result. More precisely, a call-by-need interpreter stops in a value if and only if the weak-head needed reduction stops in a value. This means that call-by-need and call-by-name are observationally equivalent.
Formally, given a reduction relation R on a term language T , and an associated notion of context for T , we define t to be observationally equivalent to u, written t ∼ =R u, iff C t ∈ WN R ⇔ C u ∈ WN R for every context C. In order to show our final result we resort to the following theorem: Theorem 8 ( [14]). 1. Let t ∈ T a . Then, Φ ⊲ V Γ ⊢ t : τ iff t ∈ WN name . 2. For all terms t and u in T a , t ∼ =name u iff t ∼ =need u.
These observations allows us to conclude: Theorem 9. For all terms t and u in T a , t ∼ =whnd u iff t ∼ =need u.
Proof. By Thm. 8:2 it is sufficient to show t ∼ =whnd u iff t ∼ =name u. The proof proceeds as follows:

Conclusion
We establish a clear connection between the semantical standard notion of neededness and the syntactical concept of call-by-need. The use of non-idempotent types -a powerful technique being able to characterise different operational properties-provides a simple and natural tool to show observational equivalence between these two notions. We refer the reader to [5] for other proof techniques (not based on intersection types) used to connect semantical notions of neededness with syntactical notions of lazy evaluation.
An interesting (and not difficult) extension of our result in Sec. 6 is that call-by-need reduction (defined on λ-terms with explicit substitutions) contracts only dB weak-head needed redexes, for an appropriate (and very natural) notion of weak-head needed redex for λ-terms with explicit substitutions. A technical tool to obtain such a result would be the type system A [14], a straightforward adaptation of system V to call-by-need syntax.
Given the recent formulation of strong call-by-need [6] describing a deterministic call-by-need strategy to normal form (instead of weak-head normal form), it would be natural to extend our technique to obtain an observational equivalence result between the standard notion of needed reduction (to full normal forms) and the strong call-by-need strategy. This remains as future work.