Cse 321 programming languages simply typed calculus
This presentation is the property of its rightful owner.
Sponsored Links
1 / 29

CSE-321 Programming Languages Simply Typed  -Calculus PowerPoint PPT Presentation


  • 93 Views
  • Uploaded on
  • Presentation posted in: General

CSE-321 Programming Languages Simply Typed  -Calculus. 박성우. POSTECH March 28, 2007.  -Calculus. Abstract syntax Operational semantics (call-by-value). Simulating Base Types. Booleans Natural numbers Fixed point combinator. Motivation. The  -calculus is expressive.

Download Presentation

CSE-321 Programming Languages 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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Cse 321 programming languages simply typed calculus

CSE-321 Programming LanguagesSimply Typed -Calculus

박성우

POSTECH

March 28, 2007


Calculus

-Calculus

  • Abstract syntax

  • Operational semantics (call-by-value)


Simulating base types

Simulating Base Types

  • Booleans

  • Natural numbers

  • Fixed point combinator


Motivation

Motivation

  • The -calculus is expressive.

    • booleans, integers, lists, recursive functions, ...

  • But it is highly inefficient to program in the -calculus.

    • Why not just use instead of ?

  • So we introduce a type system!


Simply typed calculus

Simply Typed -Calculus

  • An extension of the untyped-calculus with types

  • Assumes a fixed set of base types

    • E.g.

      • base type

      • primitive constructs

  • A subset of Standard ML


Outline

Outline

  • Introduction V

  • The simply typed -calculus

    • Abstract syntax

    • Operational semantics

    • Type system

  • Type safety


Abstract syntax

Abstract Syntax


What if there is no base type

What if there is no base type?

No interesting expression!


Outline1

Outline

  • Introduction V

  • The simply typed -calculus

    • Abstract syntax V

    • Operational semantics

    • Type system

  • Type safety


Simply untyped calculus

Simply Untyped -Calculus


Reduction rules for booleans

Reduction Rules for Booleans


Capture avoiding substitutions

Capture-Avoiding Substitutions

  • Completely analogous


Free variables

Free Variables

  • Completely analogous


Outline2

Outline

  • Introduction V

  • The simply typed -calculus

    • Abstract syntax V

    • Operational semantics V

    • Type system

  • Type safety


What is the type of

What is the type of ?

Answer:


How to find the type of

How to find the type of

  • Assume that the type of x is A.

    • okay

  • Find the type of x.

    • A

  • Build a function type

    • A ! A

Need to make assumptions on types of variables!


Type system

Type System

  • Typing context

  • Typing judgment


Typing rules top down

Typing Rules --- Top-down


Typing rules bottom up

Typing Rules --- Bottom-up


Typing rules for booleans

Typing Rules for Booleans


Typing derivation

Typing Derivation


Typing derivation1

Typing Derivation


Outline3

Outline

  • Introduction V

  • The simply typed -calculus V

    • Abstract syntax V

    • Operational semantics V

    • Type system V

  • Type safety


Unsafe operations in c

Unsafe Operations in C

  • Adding two pointers

  • Subtracting an integer from a string

    • which is okay, but likely to be unintended

  • Null-pointer dereferencing

    • Argh... segmentation fault!

  • Using an integer as a destination address in a function call

  • ...


Assignment 3

Assignment 3+

  • Count the number of hours that you spend before getting your Matrix program to typecheck.

    • Example:

      • 0am: You start.

      • 10am: Your program compiles with no type errors.

  • Then count the number of extra hours that you spend before completing Assignment 3.


Type safety

Type Safety

  • Slogan"well-typed expressions never go wrong"

  • Two theorems

    • Type preservation:"A well-typed expression reduces to another expression of the same type."

    • Progress:"A well-typed expression does not get stuck: either it is a value or reduces to another expression."


Type preservation progress

Type Preservation + Progress

  • A well-typed expression e:

    • If it is a value, we are finished.

    • If it is not,

      • It reduces to another e' [Progress]

      • e' has the same type as e.[Type preservation]


Type safety1

Type Safety

  • Type preservation

  • Progress


Proof of type safety

Proof of Type Safety

  • Use the rule induction.

  • In the next lecture!


  • Login