1 / 30

CS 476 – Programming Language Design

CS 476 – Programming Language Design. William Mansky. Lambda Calculus: Types. The basic (“untyped”) lambda calculus has no meaningful types – everything is a function, and any function can be applied to anything as an argument But what if we add other kinds of values?

moneil
Download Presentation

CS 476 – Programming Language Design

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. CS 476 – Programming Language Design William Mansky

  2. Lambda Calculus: Types • The basic (“untyped”) lambda calculus has no meaningful types – everything is a function, and any function can be applied to anything as an argument • But what if we add other kinds of values? • Next language: lambda calculus with numbers e.g.

  3. Lambda Calculus + Ints L ::= <ident> | <ident>. L | LL| <#> | L + L Values are either functions or ints: 4 int int int int (int int) (int int) (int int)

  4. Lambda Calculus + Ints L ::= <ident> | <ident>. L | LL| <#> | L + L T ::= int | TT Values are either functions or ints: 4 int int int int (int int) (int int) (int int)

  5. Simply Typed Lambda Calculus L ::= <ident> | <ident>:T. L | LL| <#> | L + L T ::= int | TT Values are either functions or ints: 4 int int int int (int int) (int int) (int int)

  6. Simply Typed Lambda Calculus: Types L ::= <ident> | <ident>:T. L | LL| <#> | L + L T ::= int | TT

  7. Limitations of Simple Types • Not every lambda-term is well typed

  8. Limitations of Simple Types • Not every lambda-term is well typed

  9. Limitations of Simple Types • Not every lambda-term is well typed

  10. Limitations of Simple Types • Not every lambda-term is well typed

  11. Limitations of Simple Types • Not every lambda-term is well typed can’t be the same as !

  12. Limitations of Simple Types • Not every lambda-term is well typed • Untyped lambda terms can run forever, but simply-typed lambda terms always terminate! • This means simply-typed lambda calculus is not Turing-complete

  13. Simply Typed Lambda Calculus: Types L ::= <ident> | <ident>:T. L | LL| <#> | L + L T ::= int | TT

  14. Simply Typed Lambda Calculus: Types

  15. Limitations of Simple Types • Not every lambda-term is well typed • Untyped lambda terms can run forever, but simply-typed lambda terms always terminate! • This means simply-typed lambda calculus is not Turing-complete • Typed languages don’t automatically include infinite loops/recursion • But we can add it in as a separate feature

  16. Typed Lambda Calculus with Recursion L ::= <ident> | <ident>:T. L | LL| <#> | L + L | L – L | ifzeroL then L else L |let rec <ident> : T = L in L let rec f : int -> int = x : int. ifzero x then 1 else x * f (x – 1) in f 5

  17. Typed Lambda Calculus with Recursion L ::= <ident> | <ident>:T. L | LL| <#> | L + L | L – L | ifzeroL then L else L |let rec <ident> : T = L in L

  18. Typed Lambda Calculus with Recursion L ::= <ident> | <ident>:T. L | LL| <#> | L + L | L – L | ifzeroL then L else L |let rec <ident> : T = L in L

  19. Typed Lambda Calculus with Recursion L ::= <ident> | <ident>:T. L | LL| <#> | L + L | L – L | ifzeroL then L else L |let rec <ident> : T = L in L

  20. Typed Lambda Calculus with Recursion L ::= <ident> | <ident>:T. L | LL| <#> | L + L | L – L | ifzeroL then L else L |let rec <ident> : T = L in L

  21. Typed Lambda Calculus with Recursion L ::= <ident> | <ident>:T. L | LL| <#> | L + L | L – L | ifzeroL then L else L |let rec <ident> : T = L in L let rec f = x. ifzero x then 1 else x * f (x – 1) in f 5 (x. ifzero x then 1 else x * f (x – 1)) 5 -> … -> 5 * f 4 -> ? But what is f?

  22. Typed Lambda Calculus with Recursion L ::= <ident> | <ident>:T. L | LL| <#> | L + L | L – L | ifzeroL then L else L |let rec <ident> : T = L in L let rec f = x. ifzero x then 1 else x * f (x – 1) in f 5 let rec f = x. ifzero x then 1 else x * f (x – 1) in (x. ifzero x then 1 else x * f (x – 1)) 5

  23. Typed Lambda Calculus with Recursion L ::= <ident> | <ident>:T. L | LL| <#> | L + L | L – L | ifzeroL then L else L |let rec <ident> : T = L in L let rec f = x. ifzero x then 1 else x * f (x – 1) in (x. ifzero x then 1 else x * f (x – 1)) 5

  24. Typed Lambda Calculus with Recursion L ::= <ident> | <ident>:T. L | LL| <#> | L + L | L – L | ifzeroL then L else L |let rec <ident> : T = L in L let rec f = x. ifzero x then 1 else x * f (x – 1) in 5 * f 4

  25. Typed Lambda Calculus with Recursion L ::= <ident> | <ident>:T. L | LL| <#> | L + L | L – L | ifzeroL then L else L |let rec <ident> : T = L in L let rec f = x. ifzero x then 1 else x * f (x – 1) in 5 * (x. ifzero x then 1 else x * f (x – 1)) 4

  26. Typed Lambda Calculus with Recursion L ::= <ident> | <ident>:T. L | LL| <#> | L + L | L – L | ifzeroL then L else L |let rec <ident> : T = L in L

More Related