1 / 14

Late Typing for Loosely Coupled Recursion

Late Typing for Loosely Coupled Recursion. Ravi Chugh. JavaScript. var tick = function (n) { return n > 0 ? "tick " + tock(n) : ""; }; var tock = function (n) { return "tock " + tick(n-1); }; tick(2); // "tick tock tick tock ". λ-Calc + Refs.

garth-wall
Download Presentation

Late Typing for Loosely Coupled Recursion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Late Typingfor Loosely CoupledRecursion Ravi Chugh

  2. JavaScript var tick = function (n) { return n > 0 ? "tick " + tock(n) : ""; }; var tock = function (n) { return "tock " + tick(n-1); }; tick(2); // "tick tock tick tock "

  3. λ-Calc + Refs let (tick,tock) = (ref undef, ref undef) tick := \n. n > 0 ? "tick " + !tock n : "" tock := \n. "tock " + !tick (n-1) !tick 2 // "tick tock tick tock "

  4. λ-Calc + Refs let (tick,tock) = (ref undef, ref undef) tick := \n. n > 0 ? "tick " + !tock n : "" tock := \n. "tock " + !tick (n-1) !tick 2 // "tick tock tick tock "

  5. Simply-Typed λ-Calc + Refs val tick : ref (int -> str) let tick = ref (\_. "") val tock : ref (int -> str) let tock = ref (\_. "") tick := \n. n > 0 ? "tick " + !tock n : "" tock := \n. "tock " + !tick (n-1) !tick 2 // "tick tock tick tock "

  6. Simply-Typed λ-Calc + Refs val tick : ref (int -> str) let tick = ref (\_. "") val tock : ref (int -> str) let tock = ref (\_. "") tick := \n. n > 0 ? "tick " + !tock n : "" tock := \n. "tock " + !tick (n-1) !tick 2 // "tick tock tick tock "

  7. “Open” Function Types (Γ) => T -> U

  8. “Open” Function Types (Γ) => T -> U Guarantee Rely

  9. let tick = ref undefined let tock = ref undefined val f_tick : (*tock: int -> str) => int -> str let f_tick n = n > 0 ? "tick " + !tock n : "" val f_tock : (*tick: int -> str) => int -> str let f_tock n = "tock " + !tick (n-1) tick := f_tick // Rely: { *tick: int -> str , *tock: int -> str } // Guar: { *tick: int -> str , *tock: undefined } !tick 2 // ill-typed; run-time crash!

  10. let tick = ref undefined let tock = ref undefined val f_tick : (*tock: int -> str) => int -> str let f_tick n = n > 0 ? "tick " + !tock n : "" val f_tock : (*tick: int -> str) => int -> str let f_tock n = "tock " + !tick (n-1) tick := f_tick tock := f_tock // Rely: { *tick: int -> str , *tock: int -> str } // Guar: { *tick: int -> str , *tock: int -> str } !tick 2 // well-typed; "tick tock tick tock "

  11. “Open” Function Types (Γ) => T -> U Guarantee Rely “Late” Checking at Calls

  12. λ-Calc + Recds let tick this n = n > 0 ? "tick " + this.tock this n : "" let tock this n - "tock " + this.tick this (n-1) let obj = { tick = tick ; tock = tock } obj.tick obj 2 // "tick tock tick tock "

  13. λ-Calc + Recds tick : (ς: {tock: ς->int->str}) => ς -> int -> str let tick this n = n > 0 ? "tick " + this.tock this n : "" tock : (ς: {tick: ς->int->str}) => ς -> int -> str let tock this n - "tock " + this.tick this (n-1) let obj = { tick = tick ; tock = tock } // Rely: { tick: ς->int->str, tock: ς->int->str } // Guar: { tick: ς->int->str, tock: ς->int->str } obj.tick obj 2 // "tick tock tick tock "

  14. Late Typingfor Loosely CoupledRecursion (Γ) => T -> U

More Related