logical types for untyped languages
play

Logical Types for Untyped Languages Sam Tobin-Hochstadt & - PowerPoint PPT Presentation

Logical Types for Untyped Languages Sam Tobin-Hochstadt & Matthias Felleisen PLT @ Northeastern University ICFP, September 27, 2010 Types for Untyped Languages: Ruby [Furr et al 09] Perl [Tang 06] Thorn [Wrigstad et al 09]


  1. Logical Types for Untyped Languages Sam Tobin-Hochstadt & Matthias Felleisen PLT @ Northeastern University ICFP, September 27, 2010

  2. Types for Untyped Languages: • Ruby [Furr et al 09] • Perl [Tang 06] • Thorn [Wrigstad et al 09] • ActionScript [Adobe 06] • Typed Racket

  3. Types for Untyped Languages: • Reynolds 68 • Cartwright 75 • Wright & Cartwright 94 • Henglein & Rehof 95

  4. "Some account should be taken of the premises in conditional expressions." Reynolds, 1968

  5. "Type testing predicates aggravate the loss of static type information." Henglein & Rehof, 1995

  6. Types and Predicates

  7. (define-type Peano (U 'Z (List 'S Peano))) (: convert : Peano -> Number) (define (convert n) (cond [(symbol? n) 0] [else (add1 (convert (rest n)))]))

  8. (define-type Peano (U 'Z (List 'S Peano))) (: convert : Peano -> Number) (define (convert n) n (cond [(symbol? n) 0] [else (add1 (convert (rest n)))])) n : Peano n : Peano

  9. (define-type Peano (U 'Z (List 'S Peano))) (: convert : Peano -> Number) (define (convert n) (cond [(symbol? n) 0] n [else (add1 (convert (rest n)))])) n : Peano n : Peano

  10. (define-type Peano (U 'Z (List 'S Peano))) (: convert : Peano -> Number) (define (convert n) (cond [(symbol? n) 0] 0 [else (add1 (convert (rest n)))])) n : 'Z n : 'Z

  11. (define-type Peano (U 'Z (List 'S Peano))) (: convert : Peano -> Number) (define (convert n) (cond [(symbol? n) 0] [else (add1 (convert (rest n)))])) n n : (List 'S Peano) n : List 'S Peano

  12. (: combine : (U String Symbol) (U String Symbol) -> String) (define (combine s s*) (cond [(and (string? s) (string? s*)) (string-append s s*)] [(string? s) (string-append s (symbol->string s*))] [(string? s*) (string-append (symbol->string s) s*)] [else (string-append (symbol->string s) (symbol->string s*))]))

  13. (: combine : (U String Symbol) (U String Symbol) -> String) (define (combine s s*) s s* (cond [(and (string? s) (string? s*)) (string-append s s*)] [(string? s) (string-append s (symbol->string s*))] [(string? s*) (string-append (symbol->string s) s*)] [else (string-append (symbol->string s) (symbol->string s*))])) s : (U String Symbol) s : U String Symbol s* : (U String Symbol) s* : U String Symbol

  14. (: combine : (U String Symbol) (U String Symbol) -> String) (define (combine s s*) (cond [(and (string? s) (string? s*)) (string-append s s*)] s s* [(string? s) (string-append s (symbol->string s*))] [(string? s*) (string-append (symbol->string s) s*)] [else (string-append (symbol->string s) (symbol->string s*))])) s : String s : String s* : String s* : String

  15. (: combine : (U String Symbol) (U String Symbol) -> String) (define (combine s s*) (cond [(and (string? s) (string? s*)) (string-append s s*)] [(string? s) (string-append s (symbol->string s*))] s s* [(string? s*) (string-append (symbol->string s) s*)] [else (string-append (symbol->string s) (symbol->string s*))])) s : String s : String s* : Symbol s* : Symbol

  16. (: combine : (U String Symbol) (U String Symbol) -> String) (define (combine s s*) (cond [(and (string? s) (string? s*)) (string-append s s*)] [(string? s) (string-append s (symbol->string s*))] [(string? s*) (string-append (symbol->string s) s*)] s s* [else (string-append (symbol->string s) (symbol->string s*))])) s : Symbol s : Symbol s* : String s* : String

  17. (: combine : (U String Symbol) (U String Symbol) -> String) (define (combine s s*) (cond [(and (string? s) (string? s*)) (string-append s s*)] [(string? s) (string-append s (symbol->string s*))] [(string? s*) (string-append (symbol->string s) s*)] [else (string-append (symbol->string s) s (symbol->string s*))])) s* s : Symbol s : Symbol s* : Symbol s* : Symbol

  18. Types and Propositions

  19. (define-type Peano (U 'Z (List 'S Peano))) (: convert : Peano -> Number) (define (convert n) (cond [(symbol? n) 0] [else (add1 (convert (rest n)))]))

  20. (define-type Peano (U 'Z (List 'S Peano))) (: convert : Peano -> Number) (define (convert n) (cond [(symbol? n) 0] [else (add1 (convert (rest n)))])) add1 convert rest n n : (List 'S Peano) n : List 'S Peano

  21. (define-type Peano (U 'Z (List 'S Peano))) (: convert : Peano -> Number) (define (convert n) (cond [(symbol? n) 0] [else (add1 (convert (rest n)))])) add1 convert rest n ⊢ (List 'S Peano) @ n ⊢ List 'S Peano @ n

  22. (define-type Peano (U 'Z (List 'S Peano))) (: convert : Peano -> Number) (define (convert n) (cond [(symbol? n) 0] symbol? n [else (add1 (convert (rest n)))])) ⊢ Symbol @ n ⊢ (List 'S Peano) @ n

  23. (define-type Peano (U 'Z (List 'S Peano))) (: convert : Peano -> Number) (define (convert n) (cond [(symbol? n) 0] symbol? n [else (add1 (convert (rest n)))])) ⊢ Peano @ n ⊢ Symbol @ n ⊢ Symbol @ n ⊢ (List 'S Peano) @ n

  24. (define-type Peano (U 'Z (List 'S Peano))) (: convert : Peano -> Number) (define (convert n) (cond [(symbol? n) 0] symbol? n [else (add1 (convert (rest n)))])) ⊢ (U 'Z (List 'S Peano)) @ n ⊢ Symbol @ n ⊢ Symbol @ n ⊢ (List 'S Peano) @ n

  25. (: combine : (U String Symbol) (U String Symbol) -> String) (define (combine s s*) (cond [(and (string? s) (string? s*)) (string-append s s*)] [(string? s) (string-append s (symbol->string s*))] [(string? s*) (string-append (symbol->string s) s*)] [else (string-append (symbol->string s) (symbol->string s*))]))

  26. (: combine : (U String Symbol) (U String Symbol) -> String) (define (combine s s*) (cond [(and (string? s) (string? s*)) (string-append s s*)] string-append s s* [(string? s) (string-append s (symbol->string s*))] [(string? s*) (string-append (symbol->string s) s*)] [else (string-append (symbol->string s) (symbol->string s*))])) ⊢ String @ s ⊢ String @ s* ⊢ String @ s ⊢ String @ s*

  27. (: combine : (U String Symbol) (U String Symbol) -> String) (define (combine s s*) (cond [(and (string? s) (string? s*)) string? s string? s* (string-append s s*)] [(string? s) (string-append s (symbol->string s*))] [(string? s*) (string-append (symbol->string s) s*)] [else (string-append (symbol->string s) (symbol->string s*))])) ⊢ String @ s ∧ String @ s* String @ s String @ s* ⊢ String @ s ⊢ String @ s*

  28. (: combine : (U String Symbol) (U String Symbol) -> String) (define (combine s s*) (cond [(and (string? s) (string? s*)) (string-append s s*)] [(string? s) (string-append s (symbol->string s*))] string-append s symbol->string s* [(string? s*) (string-append (symbol->string s) s*)] [else (string-append (symbol->string s) (symbol->string s*))])) ⊢ Symbol @ s* Symbol @ s*

  29. (: combine : (U String Symbol) (U String Symbol) -> String) (define (combine s s*) (cond [(and (string? s) (string? s*)) and string? s string? s* (string-append s s*)] [(string? s) string? s (string-append s (symbol->string s*))] [(string? s*) (string-append (symbol->string s) s*)] [else (string-append (symbol->string s) (symbol->string s*))])) ⊢ String @ s ⊢ String @ s ⊃ String @ s* String @ s ⊃ String @ s* String @ s ⊢ Symbol @ s*

  30. (string? s )

  31. (string? s ) String @ s

  32. (string? s ) String @ s | String @ s

  33. (x:Any -> Bool : String@x | String@x) x:Any -> Bool : String@x | String@x s s (string? string? s ) s String @ s | String @ s

  34. Latent Propositions (x:Any -> Bool : String@x | String@x) Objects x:Any -> Bool : String@x | String@x s s (string? string? s ) s String @ s | String @ s Propositions

  35. Latent Propositions (x:Any -> Bool : String@x | String@x) Objects x:Any -> Bool : String@x | String@x car(s) car(s) (string? (car s)) string? car s String @ car(s) | String @ car(s) Propositions

  36. ( λ ([s : (Pair Any Any)]) (string? (car s))) String @ car(s) | String @ car(s)

  37. ( λ ([s : (Pair Any Any)]) (string? (car s))) (s:(Pair Any Any) -> Bool : String @ car(s) | String @ car(s))

  38. Propositional Logic

  39. Judgments Γ ⊢ e : T ; φ 1 | φ 2 ; o

  40. Judgments Γ ⊢ e : T ; φ 1 | φ 2 ; o e ::= n | c | ( λ x : T . e) | (e e) | (if e e e)

  41. Judgments Γ ⊢ e : T ; φ 1 | φ 2 ; o T ::= Number | (U T ...) | #t | #f | (x:T -> T : φ | φ )

  42. Judgments Γ ⊢ e : T ; φ 1 | φ 2 ; o φ ::= T@ π (x) | T@ π (x) | φ 1 ∨ φ 2 | φ 1 ∧ φ 2 | φ 1 ⊃ φ 2

  43. Judgments Γ ⊢ e : T ; φ 1 | φ 2 ; o Γ ::= x:T ...

  44. Judgments Γ ⊢ e : T ; φ 1 | φ 2 ; o Γ ::= x:T T@ π (x) ...

  45. Judgments Γ ⊢ e : T ; φ 1 | φ 2 ; o Γ ::= x:T T@ π (x) φ ...

  46. Judgments Γ ⊢ φ

  47. Judgments Γ ⊢ φ Number @ x ∨ String @ y , Number @ x ⊢ String @ y

  48. Typing (if e 1 e 2 e 3 )

  49. Typing Γ , φ + ⊢ e 2 : T ; φ 1+ | φ 1- ; o Γ , φ - ⊢ e 3 : T ; φ 2+ | φ 2- ; o Γ ⊢ e 1 : T' ; φ + | φ - ; o' (if e 1 e 2 e 3 )

  50. Typing Γ , φ + ⊢ e 2 : T ; φ 1+ | φ 1- ; o Γ , φ - ⊢ e 3 : T ; φ 2+ | φ 2- ; o Γ ⊢ e 1 : T' ; φ + | φ - ; o' Γ ⊢ (if e 1 e 2 e 3 ) : T ; φ 1+ ∨φ 2+ | φ 1- ∨φ 2- ; o

  51. Typing Γ ⊢ x : T

  52. Typing Γ ⊢ T x Γ ⊢ x : T

  53. Evaluation

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend