This paper explores the challenges and solutions related to naïve type conversions in functional programming languages, specifically focusing on space efficiency in type checking. It discusses the principles of gradual typing, which merges dynamic and static typing to facilitate software evolution. The authors present a new approach to type casts, emphasizing their role in enhancing program safety and efficiency. By generalizing casts to coercions and modifying their representation, the paper addresses the potential for space leaks and proposes techniques for runtime optimization.
01 / 66Space-Efficient Gradual Typing in Functional Programming
1 / 17
Télécharger la présentation
Space-Efficient Gradual Typing in Functional Programming
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
F I N
Plus de contenu associé
Transcription de la présentation
Space-Efficient Gradual Typing David Herman Northeastern University Aaron Tomb, Cormac Flanagan University of California, Santa Cruz
The point Naïve type conversions in functional programming languages are not safe for space. But they can and should be.
Static semantics (Siek & Taha) Type compatibility ≠ subtyping! T ~: T T ~: ? ? ~: T T1 ~: S1 S2 ~: T2 (S1→S2) ~: (T1→T2)
Static semantics (Siek & Taha) Cast insertion E ⊢ e1↪ t1 : (S→T) E ⊢ e2↪ t2 : S′ S′ ~: S E ⊢ (e1 e2) ↪ (t1 (<S> t2)) : T E ⊢ e ↪ t : T cast argument expression
Casts in functional languages <Int>n → n <Int>v → error: “v not an Int”(if v∉Int) <σ→τ>λx:?.e →λz:σ.<τ>((λx:?.e) z) Very useful, very popular… unsafe for space. fresh, typed proxy cast result
More space leaks fun evenk(n : Int, k : ? → ?) = if (n = 0) then k(true) else oddk(n – 1, k) fun oddk(n : Int, k : Bool → Bool) = if (n = 0) then k(false) else evenk(n – 1, k)
More space leaks fun evenk(n : Int, k : ? → ?) = if (n = 0) then k(true) else oddk(n – 1, <Bool→Bool>k) fun oddk(n : Int, k : Bool → Bool) = if (n = 0) then k(false) else evenk(n – 1, <?→?>k)
Space-efficient gradual typing • Generalize casts to coercions(Henglein, 1994) • Change representation of casts from <τ> to <c> • Merge casts at runtime: This coercion can be simplified! merged before evaluating e
Space-efficient gradual typing • Generalize casts to coercions(Henglein, 1994) • Change representation of casts from <τ> to <c> • Merge casts at runtime:
Static semantics Type compatibility E ⊢ e1 : (S→T) E ⊢ e2 : S′ S′ ~: S E ⊢ (e1 e2) : T
Static semantics Type compatibility T ~: T T ~: ? ? ~: T T1 ~: S1 S2 ~: T2 (S1→S2) ~: (T1→T2)
Static semantics Cast insertion E ⊢ e1↪ t1 : (S→T) E ⊢ e2↪ t2 : S′ c=coerce(S′, S) E ⊢ (e1 e2) ↪ (t1 (<c> t2)) : T E ⊢ e ↪ t : T computes a type coercion replaces the type cast with a coercion
Henglein’s coercions c ::= Succ | Fail | D! | D? | Fun c c | c◦c D ::= Int | Bool | Fun coerce(T, T) = Succ coerce(Int, ?) = Int! coerce(?, Int) = Int?
Henglein’s coercions c ::= Succ | Fail | D! | D? | Fun c c | c◦c D ::= Int | Bool | Fun coerce(S1→S2, T1→T2) =Funcoerce(T1, S1) coerce(S2, T2) coerce(?, T1→T2) =coerce(?→?, T1→T2)◦Fun? coerce(T1→T2, ?) =Fun!◦coerce(T1→T2, ?→?)
Coercion normalization c◦Succ = c Succ◦c = c c◦Fail = Fail Fail◦c = Fail D?◦D! = Succ Int?◦Bool! = Fail (Fun d1 d2)◦(Fun c1 c2) = Fun (c1◦d1) (d2◦c2)