• Aucun résultat trouvé

Intersection Types for the Computational lambda-Calculus

N/A
N/A
Protected

Academic year: 2022

Partager "Intersection Types for the Computational lambda-Calculus"

Copied!
6
0
0

Texte intégral

(1)

Intersection Types for the Computational λ-Calculus

Extended Abstract

Ugo de’Liguoro and Riccardo Treglia

Dipartimento di Informatica, Universit`a degli Studi di Torino, Corso Svizzera 185, 10149 Torino, Italy

ugo.deliguoro@unito.it riccardo.treglia@unito.it

The computational λ-calculus was introduced by Moggi [5,6] as a meta- language to describe non functional effects in programming languages via an incremental approach. The basic idea is to distinguish among values of some typeD and computations over such values, the latter having typeT D. Seman- tically T is a monad, endowing D with a richer structure such that operations over computations can be seen as algebras of T. Any D is embedded into T D and there is a universal way to extend any morphism inD→T Eto a morphism in T D→T E.

In Wadler’s formulation [7], at the ground of Haskell implementation, a monad is a triple (T,unit, ?) where T is a type constructor, and for all types D, E, unitD : D → T D and ?D,E : T D×(D → T E) → T E are such that (omitting subscripts and writing? as an infix operator):

(unit d)? f =f d, a ?unit =a, (a ? f)? g=a ? λλ d.(f d ? g).

Instances of monads are partiality, exceptions, input/output, store, non deter- minism, continuations.

Aim of our work is to investigate the monadic approach to effectfull functional languages in the untyped case. Much as the untypedλ-calculus can be seen as a calculus with a single typeD / D→D, which is interpreted by a reflexive object in a suitable category, the untyped computationalλ-calculusλuc has two types:

the type of valuesDand the type of computationsT D. The typeD is a retract ofD→T D, which is the call-by-value analogous of the reflexive object (see [5], sec. 5). This leads to the following definition:

Definition 1 (The untyped computationalλ-calculus).Theuntyped com- putationalλ-calculus, shortlyλuc, is a calculus of two sorts of expressions:

Val : V, W ::=x|λx.M (values) Com: M, N ::=unitV |M ? V (computations) wherexranges over a denumerable set Var of variables.

Copyright c2019 for this paper by its authors. Use permitted under Creative Com- mons License Attribution 4.0 International (CC BY 4.0)

(2)

Areduction relation −→ ⊆ Com×Com is defined as follows:

c) unitV ?(λx.M)→M[V /x]

(?−red) M −→M0 ⇒M ? V −→M0? V

whereM[V /x] denotes the capture avoiding substitution ofV for all free occur- rences of xinM.

Terms of the calculus can be interpreted into anyD'D→T D (where we restrict to extensional models for simplicity) via the mappings [[V]]Dρ ∈D and [[M]]T Dρ ∈T D, whereρ∈EnvD=Var→D by:

[[x]]Dρ =ρ(x) [[unitV]]T Dρ =unit[[V]]Dρ [[λx.M]]Dρ =λλ d∈D.[[M]]T Dρ[x7→d] [[M ? V]]T Dρ = [[M]]T Dρ ? [[V]]Dρ where ρ[x7→d](y) =ρ(y) ify 6≡x, it is equal todotherwise. We therefore dub (extensional)T-modelin a cartesian closed categoryDa tuple (D, T, Φ, Ψ) such that T is a monad over DandD'D→T Dvia the morphismsΦ, Ψ =Φ−1. Proposition 1. If M −→ N then [[M]]T Dρ = [[N]]T Dρ for any T-model D and ρ∈EnvD.

An intersection type system for λ

uc

To study T-models we use intersection types, because they are at the same time a formal system to reason on terms and a tool to bridge reduction and operational semantics of the calculus to its models. As shown in [3] reasoning over generic monads is challenging, and indeed a major issue of the present work is to complement Dal Lago’s and others contributions by Coppo-Dezani approach to the study of Scott’sD models of the untypedλ-calculus.

LetTypeVarbe a countable set of type variables, ranged over byα; then we define the following languages of types via the grammar:

ValType: δ::=α|δ→τ|δ∧δ|ωV (value types) ComType: τ ::=T δ|τ∧τ |ωC (computation types) Over types we consider the preorders≤Vand≤Cmaking∧into a meet operator and such that:

δ≤V ωV (δ→τ)∧(δ→τ0)≤Vδ→(τ∧τ0) δ0Vδ τ≤Cτ0 δ→τ≤Vδ0→τ0

τ≤CωC T δ∧T δ0CT(δ∧δ0) δ≤Vδ0 T δ≤CT δ0 ωVVωV →ωC

Now we are ready to define the intersection type assignment for λuc and the generic monadT:

(3)

Definition 2 (Type assignment). A basis is a finite set of typings Γ = {x1 : δ1, . . . xn : δn} with pairwise distinct variables xi, whose domain is the set dom (Γ) = {x1, . . . , xn}. A basis determines a function from variables to types such thatΓ(x) =δ if x:δ∈Γ,Γ(x) =ωV otherwise.

Ajudgment is an expression of either shapesΓ `V :δ orΓ `M :τ. It is derivableif it is the conclusion of a derivation according to the rules:

x:δ∈Γ Γ `x:δ

Γ, x:δ`M :τ Γ `λx.M :δ→τ

Γ `V :δ Γ `unitV :T δ

Γ `M :T δ Γ `V :δ→τ Γ `M ? V :τ whereΓ, x:δ=Γ∪ {x:δ} with x:δ6∈Γ, and the rules:

Γ `P:ω

Γ `P :σ Γ `P :σ0 Γ `P :σ∧σ0

Γ `P :σ σ≤σ0 Γ `P :σ0

where either P ∈ Val , ω ≡ ωV, σ, σ0 ∈ ValType and ≤=≤V or P ∈ Com, ω≡ωC,σ, σ0∈ComType and ≤=≤C.

Then by a standard technique, that is by proving suitable Generation and Substitution Lemmas, we establish:

Theorem 1 (Subject reduction). Γ `M :τ & M −→N ⇒Γ `N :τ.

Type assignment and T -models

As a first step we interpret types as certain subsets ofD andT D, according to the sortsValTypeandComTyperespectively. Let (D, T, Φ, Ψ) be aT-model and d, d0 ∈D; we abbreviate d·d0 =Φ(d)(d0). Letξ∈TypeEnvD=TypeVar→2D; then the followings are natural requirements for the type interpretation mappings [[·]]D:ValType×TypeEnvD→2D and [[·]]T D :ComType×TypeEnvD→2T D:

[[α]]Dξ =ξ(α) [[δ→τ]]Dξ ={d∈D| ∀d0∈[[δ]]Dξ d·d0∈[[τ]]T Dξ } [[ωV]]Dξ =D [[δ∧δ0]]Dξ = [[δ]]Dξ ∩[[δ0]]Dξ

[[ωC]]T Dξ =T D [[τ∧τ0]]T Dξ = [[τ]]T Dξ ∩[[τ0]]T Dξ

Further we call these interpretationsmonadicif [[T δ]]T Dξ satisfies:

1. d∈[[δ]]Dξ ⇒unitd∈[[T δ]]T Dξ

2. d∈[[δ0→T δ]]Dξ & a∈[[T δ0]]T Dξ ⇒a ? d∈[[T δ]]T Dξ

The main problem with monadic interpretations is that the clauses above are not inductive, as they would be if we had typesωV=VωV →T ωVandT ωVonly.

However, working in a category of domains and with anω-continuous monadT we can build a T-model D = limDn, whereD0 is some fixed domain, and Dn+1 = [Dn → T Dn] is such that for alln, Dn/ Dn+1 is an embedding. As a consequence we haveD'[D→T D]. We say thatDis alimitT-model.

More importantly with such aT-model we can stratify the above clauses by means of approximate type interpretations [[δ]]Dξn ⊆ Dn and [[τ]]T Dξ n ⊆ T Dn, that now can be defined by induction overn∈N.

(4)

Theorem 2. The mappings [[δ]]Dξ = lim[[δ]]Dξn and [[τ]]T Dξ = lim[[τ]]T Dξ n are monadic type interpretations. In particular for any ξ∈EnvD:

1. [[δ→τ]]Dξ={d∈D| ∀d0 ∈[[δ]]Dξ d(d0)∈[[τ]]T Dξ } 2. [[T δ]]T Dξ = {unitd∈T D| d∈[[δ]]Dξ} ∪

{a ? d∈T D| ∃δ0. d∈[[δ0 →T δ]]Dξ & a∈[[T δ0]]T Dξ } Now, writingρ, ξ |=D Γ if ρ(x)∈[[Γ(x)]]Dξ for all x∈dom (Γ), we may set Γ |=DV :δ(Γ |=DM :τ) ifρ, ξ|=DΓ implies [[V]]Dρ ∈[[δ]]Dξ ([[M]]T Dρ ∈[[τ]]T Dξ ).

Also for any classCofT-models we writeΓ |=C V :δ(Γ |=M :τ) ifΓ |=DV :δ (Γ |=DM :τ) for all D∈ C.

Theorem 3 (Soundness).If[[δ]]Dξ and[[τ]]T Dξ are monadic w.r.t. anyT-model D∈ C then

Γ `V :δ ⇒ Γ |=C V :δ and Γ `M :τ ⇒ Γ |=C M :τ.

In particular, by Theorem 2, we may takeCas the set of limitT-models.

Completeness and computational adequacy

Toward completeness, we first concentrate on the category D of ω-algebraic lattices, whose objects are known to be presentable as the poset of filters over a meet-semilattice, or equivalently over a preorder whose quotient is such; the ω in the name means that the Scott topology of a domain inDhas a countable basis, formed by the upward cones of compact points. Then any axiomatization Th= (T,≤Th) of a preorder over a language T of intersection types making∧ into the meet and ω the top, will generate such a domain, and vice versa: we call DTh =F(Th) the domain of filters w.r.t.≤Th ordered by subset inclusion, andThD the theory of the restriction of the order inD to the compactsK(D).

ThereforeDThD =F(ThD)'D which we abbreviate byFD and identify with D itself.

LetThV= (ValType,≤V) andThC= (ComType,≤C) and setD=DThV and T D=DThC: thenThVis a continuous EATS (see e.g. [1] ch. 3, where continuity is expressed by condition (Frefl) of Prop. 3.3.18), hence the space of continuous functions D →T D is representable in D, and actually isomorphic to it. On the other hand the theoryThCis parametric inThV. More precisely given a type theory Th we can use the axioms ofThC to form a new theory we call T(Th);

then we can define a mapping Tamong objects of D byTD =DT(Th) where Th=ThD.

Theorem 4. Define unitFD:FD→ FT D and?FD,E :FT D× FD→TE → FTE by:

unitFDd=↑ {T δ∈ TTD|δ∈d} t ?FD,Ee=↑ {τ ∈ TTE| ∃δ→τ∈e. T δ∈t}

Then(T,unitF, ?F) is a monad overD. HenceD is aT-model.

Strictly speaking to enforce extensionality of the filter model,ThVmust be extended to the theoryThηV by adding suitable axioms: see [4] for the precise treatment.

(5)

By stratifying types according to the rank map:r(α) =r(ωV) =r(ωC) = 0, r(σ∧σ0) = max(r(σ), r(σ0)),r(δ→τ) = max(r(δ)+1, r(τ)) andr(T δ) =r(δ)+1, and taking≤n=≤{σ|r(σ)≤n}(for both≤V and≤C) we obtain theoriesThn and a chain of domains Dn = F(Thn) such that D = limDn is a limit T- model. Consequently, we can extend the proof in [2] to our calculus obtaining:

Theorem 5 (Completeness). Let C be the class of limitT-models. Then Γ |=C V :δ ⇒ Γ `V :δ and Γ |=CM :τ ⇒ Γ `M :τ.

Corollary 1 (Subject expansion). IfΓ `M :τ andN −→M thenΓ `N : τ.

Finally letT erm0=Val0∪Com0 be the set of closed terms.

Definition 3. Let ⇓ ⊆Com0×Val0 be the smallest relation satisfying:

unitV ⇓V

M ⇓V N[V /x]⇓W M ? λx.N ⇓W

Then it is easily seen thatM ⇓V if and only ifM −→ unitV. We abbreviate M⇓ ⇔ ∃V. M ⇓V.

We say thatτ∈ComTypeisnon trivialifωC6≤Cτ. Then by adapting Tait’s computability technique, we eventually have:

Theorem 6. For allM ∈Com0 we have:

M⇓ ⇔ ∃τnon trivial. `M :τ

Corollary 2 (Computational Adequacy). In the modelD we have that M⇓ ⇔[[M]]T D6=⊥T D

From the proof of Theorem 6 we learn that the fact thatT ωVis not equated to ωC inThCis an essential ingredient; indeed this corresponds to the fact that the generic monadT is assumed to be non trivial (hence not the identity monad), so thatT D6'D. This supports the intuition that aT-model equating computations to (the image of) values is not computationally adequate w.r.t. weak normal forms.

For details we refer the reader to the full paper [4].

(6)

References

1. Amadio, R., Curien, P.L.: Domains and lambda-calculi. Cambridge University Press (1998)

2. Barendregt, H., Coppo, M., Dezani-Ciancaglini, M.: A filter lambda model and the completeness of type assignment. Journal of Symbolic Logic48(4), 931–940 (1983) 3. Dal Lago, U., Gavazzo, F., Levy, P.B.: Effectful applicative bisimilarity: Monads, relators, and howe’s method. In: Proc. of Logic in Computer Science, LICS 2017, Reykjavik, Iceland, June 20-23, 2017. pp. 1–12 (2017)

4. de’Liguoro, U., Treglia, R.: Intersection Types for the Computational lambda- Calculus (Jul 2019), https://arxiv.org/abs/1907.05706, unpublished

5. Moggi, E.: Computational Lambda-calculus and Monads. Report ECS-LFCS-88-66, University of Edinburgh, Edinburgh, Scotland (Oct 1988)

6. Moggi, E.: Notions of Computation and Monads. Information and Computation93, 55–92 (1991)

7. Wadler, P.: Monads for Functional Programming. In: Advanced Functional Pro- gramming, First International Spring School on Advanced Functional Programming Techniques-Tutorial Text. Lecture Notes in Computer Science, vol. 925, pp. 24–52.

Springer-Verlag (1995)

Références

Documents relatifs

We can see that programming in the Calculus of Con- structions is quite verbose: programs have arguments that are indeed only static information (type decorations, proof

We show that the permutative λ -calculus preserves β -strong normalisation and is Church-Rosser modulo the equivalences, the strongest possible form of confluence for a

Delia KESNER IRIF, CNRS et Universit ´e Paris kesner@irif.fr www.irif.fr/˜kesner.. The Untyped

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des

Le pic de dureté enregistré est plus supérieur comparativement aux pics de dureté des autres tôles (2, 4, 7 et 8) sans cuivre. Cette amélioration de durcissement est justifiée par

Le kaolin a présenté une zone de cisaillement hétérogène (Figure 7.43), du point de vue angle d’orientation de la matrice argileuse (compris entre 35° et 55°). Au dessous de

Hence since the birth of functional programming there have been several theoretical studies on extensions of the λ-calculus in order to account for basic algebra (see for

However, we do not show how to extend our source language, since a generalization of bi-directional type checking to local type inference [13] in the presence of poly-