2/6/20161 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

4/11/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Exercise 1 Generics and Assignments. Language with Generics and Lots of Type Annotations Simple language with this syntax types:T ::= Int | Bool | T =>
Proofs and Programs Wei Hu 11/01/2007. Outline  Motivation  Theory  Lambda calculus  Curry-Howard Isomorphism  Dependent types  Practice  Coq Wei.
Cs776 (Prasad)L4Poly1 Polymorphic Type System. cs776 (Prasad)L4Poly2 Goals Allow expression of “for all types T” fun I x = x I : ’a -> ’a Allow expression.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Axiomatic Semantics Dr. M Al-Mulhem ICS
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Thirteen conditional expressions: letting programs make “decisions”
7/2/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
CSE 311 Foundations of Computing I Lecture 6 Predicate Logic, Logical Inference Spring
9/18/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
10/14/20151 Programming Languages and Compilers (CS 421) Grigore Rosu 2110 SC, UIUC Slides by Elsa Gunter, based.
10/15/20151 Programming Languages and Compilers (CS 421) William Mansky Based in part on slides by Mattox.
Patterns in OCaml functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are.
05/31/101 Programming Languages and Compilers (CS 421)‏ Munawar Hafiz 2219 SC, UIUC Based in part on slides by.
A Third Look At ML Chapter NineModern Programming Languages, 2nd ed.1.
CSE 311 Foundations of Computing I Lecture 7 Logical Inference Autumn 2012 CSE
CS6133 Software Specification and Verification
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
CMSC 330: Organization of Programming Languages Operational Semantics a.k.a. “WTF is Project 4, Part 3?”
10/16/081 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
CSED101 INTRODUCTION TO COMPUTING FUNCTION ( 함수 ) 유환조 Hwanjo Yu.
CMSC 330: Organization of Programming Languages Operational Semantics.
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
3/8/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman, as updated.
1 Propositional Proofs 1. Problem 2 Deduction In deduction, the conclusion is true whenever the premises are true.  Premise: p Conclusion: (p ∨ q) 
3/20/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
6/21/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
Foundations of Computing I CSE 311 Fall Announcements Homework #2 due today – Solutions available (paper format) in front – HW #3 will be posted.
7/7/20161 Programming Languages and Compilers (CS 421) Dennis Griffith 0207 SC, UIUC Based in part on slides by Mattox.
10/1/20161 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Programming Languages and Compilers (CS 421)
Relational Operator and Operations
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
(State) Model-Based Approaches I Software Specification Lecture 35
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
ML: a quasi-functional language with strong typing
Propositional Calculus: Boolean Functions and Expressions
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Propositional Calculus: Boolean Functions and Expressions
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
CSE 311 Foundations of Computing I
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Madhusudan Parthasarathy
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421) #3: Closures, evaluation of function applications, order of evaluation #4: Evaluation and Application.
Madhusudan Parthasarathy (madhu) 3112 Siebel Center
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Presentation transcript:

2/6/20161 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox Beckman, as updated by Vikram Adve and Gul Agha

2/6/ Format of Type Judgments A type judgement has the form  |- exp :   is a typing environment Supplies the types of variables and functions  is a list of the form [ x : ,... ] exp is a program expression  is a type to be assigned to exp |- pronounced “turnstyle”, or “entails” (or “satisfies”)

2/6/ Axioms - Constants |- n : int (assuming n is an integer constant) |- true : bool |- false : bool These rules are true with any typing environment n is a meta-variable

2/6/ Axioms – Variables (Monomorphic Rule) Notation: Let  (x) =  if x :    and there is no x :  to the left of x :  in  Variable axiom:  |- x :  if  (x) = 

2/6/ Simple Rules - Arithmetic Primitive operators (   { +, -, *, …}) :  |- e 1 :   |- e 2 :  (  ):       |- e 1  e 2 :  Relations ( ˜  {, =, = }):  |- e 1 :   |- e 2 :   |- e 1 ˜ e 2 :bool For the moment, think  is int

2/6/ Simple Rules - Booleans Connectives  |- e 1 : bool  |- e 2 : bool  |- e 1 && e 2 : bool  |- e 1 : bool  |- e 2 : bool  |- e 1 || e 2 : bool

2/6/ Type Variables in Rules If_then_else rule:  |- e 1 : bool  |- e 2 :   |- e 3 :   |- (if e 1 then e 2 else e 3 ) :   is a type variable (meta-variable) Can take any type at all All instances in a rule application must get same type Then branch, else branch and if_then_else must all have same type

2/6/ Function Application Application rule:  |- e 1 :  1   2  |- e 2 :  1  |- (e 1 e 2 ) :  2 If you have a function expression e 1 of type  1   2 applied to an argument of type  1, the resulting expression has type  2

2/6/ Fun Rule Rules describe types, but also how the environment  may change Can only do what rule allows! fun rule: [x :  1 ] +  |- e :  2  |- fun x -> e :  1   2

2/6/ Fun Examples [y : int ] +  |- y + 3 : int  |- fun y -> y + 3 : int  int [f : int  bool] +  |- f 2 :: [true] : bool list  |- (fun f -> f 2 :: [true]) : (int  bool)  bool list

2/6/ (Monomorphic) Let and Let Rec let rule:  |- e 1 :  1 [x :  1 ] +  |- e 2 :  2  |- (let x = e 1 in e 2 ) :  2 let rec rule: [x:  1 ] +  |- e 1 :  1 [x:  1 ] +  |- e 2 :  2  |- (let rec x = e 1 in e 2 ) :  2

2/6/ Example Which rule do we apply? ? |- (let rec one = 1 :: one in let x = 2 in fun y -> (x :: y :: one) ) : int  int list

2/6/ Example Let rec rule: 2 [one : int list] |- 1 (let x = 2 in [one : int list] |- fun y -> (x :: y :: one)) (1 :: one) : int list : int  int list |- (let rec one = 1 :: one in let x = 2 in fun y -> (x :: y :: one) ) : int  int list

2/6/ Proof of 1 Which rule? [one : int list] |- (1 :: one) : int list

2/6/ Proof of 1 Application 3 4 [one : int list] |- [one : int list] |- ((::) 1): int list  int list one : int list [one : int list] |- (1 :: one) : int list

2/6/ Proof of 3 Constants Rule [one : int list] |- (::) : int  int list  int list 1 : int [one : int list] |- ((::) 1) : int list  int list

2/6/ Proof of 4 Rule for variables [one : int list] |- one:int list

2/6/ Proof of 2 5 [x:int; one : int list] |- Constant fun y -> (x :: y :: one)) [one : int list] |- 2:int : int  int list [one : int list] |- (let x = 2 in fun y -> (x :: y :: one)) : int  int list

2/6/ Proof of 5 ? [x:int; one : int list] |- fun y -> (x :: y :: one)) : int  int list

2/6/ Proof of 5 ? [y:int; x:int; one : int list] |- (x :: y :: one) : int list [x:int; one : int list] |- fun y -> (x :: y :: one)) : int  int list

2/6/ Proof of [y:int; x:int; one : int list] |- ((::) x):int list  int list (y :: one) : int list [y:int; x:int; one : int list] |- (x :: y :: one) : int list [x:int; one : int list] |- fun y -> (x :: y :: one)) : int  int list

2/6/ Proof of 6 Constant Variable […] |- (::) : int  int list  int list […; x:int;…] |- x:int [y:int; x:int; one : int list] |- ((::) x) :int list  int list

2/6/ Proof of 7 Pf of 6 [y/x] Variable [y:int; …] |- ((::) y) […; one: int list] |- :int list  int list one: int list [y:int; x:int; one : int list] |- (y :: one) : int list

2/6/ Curry - Howard Isomorphism Type Systems are logics; logics are type systems Types are propositions; propositions are types Terms are proofs; proofs are terms Functions space arrow corresponds to implication; application corresponds to modus ponens

2/6/ Curry - Howard Isomorphism Modus Ponens A  B A B Application  |- e 1 :     |- e 2 :   |- (e 1 e 2 ) : 

2/6/ Mia Copa The above system can’t handle polymorphism as in OCAML No type variables in type language (only meta- variable in the logic) Would need: Object level type variables and some kind of type quantification let and let rec rules to introduce polymorphism Explicit rule to eliminate (instantiate) polymorphism