CSE-321 Programming Languages Polymorphism POSTECH May 15, 2006 박성우.

Slides:



Advertisements
Similar presentations
Sml2java a source to source translator Justin Koser, Haakon Larsen, Jeffrey Vaughan PLI 2003 DP-COOL.
Advertisements

Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Types and Programming Languages Lecture 15 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Modern Programming Languages, 2nd ed.
Type Systems and Object- Oriented Programming (III) John C. Mitchell Stanford University.
Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
Pedigree Types Yu David Liu, Johns Hopkins University / SUNY Binghamton Scott F. Smith, Johns Hopkins University July 7, IWACO’08.
CSE-321 Programming Languages Predicative Polymorphic -Calculus POSTECH May 23, 2007 박성우.
C12, Polymorphism “many forms” (greek: poly = many, morphos = form)
CSE 425: Semantics II Implementing Scopes A symbol table is in essence a dictionary –I.e., every name appears in it, with the info known about it –Usually.
Functional Design and Programming Lecture 1: Functional modeling, design and programming.
Parametric Polymorphism COS 441 Princeton University Fall 2004.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
C++ Training Datascope Lawrence D’Antonio Lecture 3 An Overview of C++
CSE 130 : Winter 2006 Programming Languages Ranjit Jhala UC San Diego Lecture 7: Polymorphism.
1 Functional Programming and ML. 2 What’s wrong with Imperative Languages? State State Introduces context sensitivity Introduces context sensitivity Harder.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
C++ fundamentals.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
Types(2). 2 Recursive Problems  One or more simple cases of the problem have a straightforward, nonrecusive solution  The other cases can be redefined.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Type Equivalence Rules Ada –Strict name equivalence except for almost everything Unique array constructors give rise to unique types Subtypes can create.
Polymorphism Lecture-10. Print A Cheque A Report A Photograph PrintCheque() PrintReport() PrintPhoto() Printing.
1 SML fn x => e e 1 e 2 0, 1, 2,..., +, -,... true, false, if e then e else e patterns datatypes exceptions structures functors fun f x = e variables.
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Effective C#, Chapter 1: C# Language Elements Last Updated: Fall 2011.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
Copyright © Curt Hill Structured Data What this course is about.
CSCI-383 Object-Oriented Programming & Design Lecture 23.
CSE 332: C++ template examples Concepts and Models Templates impose requirements on type parameters –Types that are plugged in must meet those requirements.
Universal Types Report by Matthias Horbach. Contents Types of Polymorphism System F Basic Properties Erasure Impredicativity Parametricity.
CSE-321 Programming Languages -Calculus (II) POSTECH March 27, 2006 박성우.
CS212: Object Oriented Analysis and Design
CSE-321 Programming Languages Introduction to Functional Programming POSTECH March 7, 2007 박성우.
Implementing a Dependently Typed λ -Calculus Ali Assaf Abbie Desrosiers Alexandre Tomberg.
1 CSE 331 Generics (Parametric Polymorphism) slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Polymorphism CMPS Poly-morphism Means “many-forms” Means different things in biology, chemistry, computer science Means different things to functional.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
CSCI-383 Object-Oriented Programming & Design Lecture 25.
Essential Ada Terminology copyright © Michael B. Feldman, All Rights Reserved.
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
CSE-321 Programming Languages Abstract Machine E POSTECH May 1, 2006 박성우.
CSE-321 Programming Languages Introduction to Functional Programming POSTECH March 8, 2006 박성우.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L05-1 September 21, 2006http:// Types and Simple Type.
CSE-321 Programming Languages Simply Typed -Calculus
ML: a quasi-functional language with strong typing
1Z0-808 Exam : Java SE 8 Programmer I
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Section 11.1 Class Variables and Methods
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Autumn 2018.
CMSC 202 Lesson 22 Templates I.
Agenda SML Docs First-Class Functions Examples Standard Basis
Agenda SML Docs First-Class Functions Examples Standard Basis
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Zach Tatlock Winter 2018.
CSE 341 Section 3 Nick Mooney Spring 2017.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2017.
Templates I CMSC 202.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2013.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2019.
Abstract Types Defined as Classes of Variables
Presentation transcript:

CSE-321 Programming Languages Polymorphism POSTECH May 15, 2006 박성우

2 Polymorphism The same piece of code can be reused for different types of objects –parameteric polymorphism –ad hoc polymorphism –crafty polymorphism

3 Parametric Polymorphism Operates on all types of objects in a uniform way. C++ templates –The same C++ template is instantiated to different classes. –cannot exploit specific properties of a given type. Java generics (J2SE 5.0) –another name for polymorphism similar to C++ templates

4 Ad hoc Polymorphism Different behavior depending on the type of objects it operates on Operator overloading + operator in SML ; val it = 2 : int ; val it = 2.0 : real

5 Outline Polymorphism V System F - syntax and reduction rules –extension of the untyped -calculus with parametric polymorphism Crafty polymorphism System F - type system

6 Type of Two tasks: 1.bind variable x to some type 2.decide the type of the resultant expression Candidates (for the simply typed -calculus)

7 Idea: use "any type"  Read  as "any type" expressiontype

8 Ambiguity

9 How to distinguish between  and  ?

10 Identity Function Again Let's apply the identity function to true.

11 Type Application

12 System F Impredicative Polymorphic -calculus

13 Reduction Rules for System F

14 Outline Polymorphism V System F - syntax and reduction rules V Crafty polymorphism –extremely dangerous for programming System F - type system

15 Polymorph in Warcraft II Polymorph Cost: 2000 Gold Mana 200 Range: 10 Time to Upgrade: 200 Time Units. Permanent effect You may cast polymorph on your ally units!

16 Polymorph in Warcraft III Temporary effect –60 seconds

17 Polymorph in World of Warcraft?

18 Outline Polymorphism V System F - syntax and reduction rules V Crafty polymorphism V System F - type system

19 Composing Two Functions  !  makes sense only after both  and  are declared. –the order of elements in a typing context matters.

20 Typing Contexts Ordered sets

21 Valid or Invalid?

22 Typing Rules

23 Example

24 Substitution Lemmas As usual, except:

25 Type Safety