1 / 33

CSE-321 Programming Languages Extensions to the Simply Typed  -Calculus

CSE-321 Programming Languages Extensions to the Simply Typed  -Calculus. 박성우. POSTECH April 10, 2006. Abstract Syntax. Operational Semantics. Type System. Outline. Product types pairs generalized product types unit type Sum types Fixed point construct. Pairs in SML.

Download Presentation

CSE-321 Programming Languages Extensions to the Simply Typed  -Calculus

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. CSE-321 Programming LanguagesExtensions to the Simply Typed -Calculus 박성우 POSTECH April 10, 2006

  2. Abstract Syntax

  3. Operational Semantics

  4. Type System

  5. Outline • Product types • pairs • generalized product types • unit type • Sum types • Fixed point construct

  6. Pairs in SML - (1, true); val it = (1,true) : int * bool - #1 (1, true) ; val it = 1 : int - #2 (1, true) ; val it = true : bool

  7. Abstract Syntax and Typing Rules

  8. Eager Reduction Rules

  9. Lazy Reduction Rules

  10. Outline • Product types • pairs V • generalized product types • unit type • Sum types • Fixed point construct

  11. Tuples in SML - (1, true, "hello", fn x : int => x); val it = (1,true,"hello",fn) : int * bool * string * (int -> int) - #1 (1, true, "hello", fn x : int => x); val it = 1 : int - #2 (1, true, "hello", fn x : int => x); val it = true : bool - #3 (1, true, "hello", fn x : int => x); val it = "hello" : string

  12. Generalized Product Types

  13. Generalized Product Types • We have n components. • n = 2 • pair types • n > 2 • tuple types • n = 1 • seems irrelevant • n = 0?

  14. n = 0

  15. Outline • Product types • pairs V • generalized product types V • unit type • Sum types • Fixed point construct

  16. Unit in SML - (); val it = () : unit

  17. n = 0: Nullary Product Type • We need n elements to build a tuple: • I want to extract the i-th element where 1 ·i : No elimination rule for the unit type!

  18. Type unit: No Elim; Only Intro

  19. Outline • Product types V • pairs • generalized product types • unit type • Sum types • Fixed point construct

  20. Datatypes in SML - datatype t = Inl of int | Inr of bool; datatype t = Inl of int | Inr of bool - val x = Inl 1; val x = Inl 1 : t - val y = Inr true; val y = Inr true : t - case (Inl 1) of Inl x => x | Inr _ => 0; val it = 1 : int - case (Inr true) of Inl x => x | Inr _ => 0; val it = 0 : int

  21. Datatypes in SML 2007 - datatype 'int + bool' = Inl of int | Inr of bool; datatype 'int + bool' = Inl of int | Inr of bool - val x = Inl 1; val x = Inl 1 : 'int + bool' - val y = Inr true; val y = Inr true : 'int + bool' - case (Inl 1) of Inl x => x | Inr _ => 0; val it = 1 : int - case (Inr true) of Inl x => x | Inr _ => 0; val it = 0 : int

  22. Sum Types: Two Alternatives

  23. Reduction Rules

  24. bool = unit + unit

  25. n = 0: Nullary Sum Type

  26. What about Elimination Rule?

  27. Type void: No Intro; Only Elim

  28. Why do we need the Elim rule then? • void type is not found in SML.

  29. Outline • Product types V • pairs • generalized product types • unit type • Sum types V • Fixed point construct

  30. Recursion? • Why not use the fixed point combinator? • It does not typecheck in the simply typed -calculus. • f has type A and also A ! A.

  31. Fixed Point Construct

  32. Recursive Functions in SML

  33. Mutually Recursive Functions in SML

More Related