SlideShare a Scribd company logo
1 of 25
Download to read offline
Polymorphism




Michal P´se (CTU in Prague)
        ıˇ                     Object Programming Lect. 2: Subtyping   October 5, 2010   2 / 16
Languages




Languages are either
      monomorphic—every value and variable has only one type or




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   3 / 16
Languages




Languages are either
      monomorphic—every value and variable has only one type or
      polymorphic—values and variables may have multiple types.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   3 / 16
Types of Polymorphism




     Universal
            Parametric
            Inclusion
     Ad hoc
            Overloading
            Coercion




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   4 / 16
Subtyping




Michal P´se (CTU in Prague)
        ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   5 / 16
Subsumption Principle




Definition (Subsumption principle)
If σ is a subtype of τ , then a value of type σ may be provided whenever a
value of type τ is required.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   6 / 16
Subsumption Principle




Definition (Subsumption principle)
If σ is a subtype of τ , then a value of type σ may be provided whenever a
value of type τ is required.
                                       e : σ σ <: τ
                                            e:τ




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   6 / 16
Liskov Substitution Principle




Definition (Liskov substitution principle)
Let q(x) be a property provable about objects x of type τ . Then q(y )
should be true for objects y of type σ where σ is a subtype of τ .




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   7 / 16
Liskov Substitution Principle




Definition (Liskov substitution principle)
Let q(x) be a property provable about objects x of type τ . Then q(y )
should be true for objects y of type σ where σ is a subtype of τ .

                                 ∀x : τ : q(x) σ <: τ
                                      ∀y : σ : q(y )




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   7 / 16
Subsumption of Constructed Types




What are the requirements for subsumption of
     function type,




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   8 / 16
Subsumption of Constructed Types




What are the requirements for subsumption of
     function type,
     product type,




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   8 / 16
Subsumption of Constructed Types




What are the requirements for subsumption of
     function type,
     product type,
     intersection type and




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   8 / 16
Subsumption of Constructed Types




What are the requirements for subsumption of
     function type,
     product type,
     intersection type and
     union type?




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   8 / 16
Record Type




                                   {foo : S, bar : T }




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   9 / 16
Universally Qualified Type




                                            ∀t.S(t)
where S(t) is a type expression constructed from basic types and type
variable t.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   10 / 16
Reference Type




                                              Ref t
Note: references in most languages are actually unions of a reference type
and the unit type.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   11 / 16
Array Type




                                           Array t




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   12 / 16
Subsumption of Constructed Types (II)




What are the requirements for subsumption of
     record type and




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   13 / 16
Subsumption of Constructed Types (II)




What are the requirements for subsumption of
     record type and
     universally qualified type, reference type and array type?




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   13 / 16
Subtyping and Objects




     Object are records, therefore
     method’s return types may change covariantly,
     types of method parameters may change contravariantly and




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   14 / 16
Subtyping and Objects




     Object are records, therefore
     method’s return types may change covariantly,
     types of method parameters may change contravariantly and
     field types are reference types, therefore may not change at all.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   14 / 16
Subtyping and Objects




     Object are records, therefore
     method’s return types may change covariantly,
     types of method parameters may change contravariantly and
     field types are reference types, therefore may not change at all.
     Instances of generic classes are not compatible either.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   14 / 16
This Type




                                               this
Always denotes the type of the enclosing class.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   15 / 16
See




Cardelli, L. and Wegner, P. On understanding types, data abstraction,
and polymorphism. ACM Computing Surveys 17, 4 (December 1985),
471-523. http://doi.acm.org/10.1145/6041.6042




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 2: Subtyping   October 5, 2010   16 / 16

More Related Content

What's hot

X Som Graduation Presentation
X Som   Graduation PresentationX Som   Graduation Presentation
X Som Graduation Presentation
Giorgio Orsi
 
What's next in Julia
What's next in JuliaWhat's next in Julia
What's next in Julia
Jiahao Chen
 

What's hot (15)

X Som Graduation Presentation
X Som   Graduation PresentationX Som   Graduation Presentation
X Som Graduation Presentation
 
What's next in Julia
What's next in JuliaWhat's next in Julia
What's next in Julia
 
StaTIX - Statistical Type Inference on Linked Data
StaTIX - Statistical Type Inference on Linked DataStaTIX - Statistical Type Inference on Linked Data
StaTIX - Statistical Type Inference on Linked Data
 
Link Discovery Tutorial Part III: Benchmarking for Instance Matching Systems
Link Discovery Tutorial Part III: Benchmarking for Instance Matching SystemsLink Discovery Tutorial Part III: Benchmarking for Instance Matching Systems
Link Discovery Tutorial Part III: Benchmarking for Instance Matching Systems
 
Inductive Entity Typing Alignment
Inductive Entity Typing AlignmentInductive Entity Typing Alignment
Inductive Entity Typing Alignment
 
Link Discovery Tutorial Part II: Accuracy
Link Discovery Tutorial Part II: AccuracyLink Discovery Tutorial Part II: Accuracy
Link Discovery Tutorial Part II: Accuracy
 
OWLED 2015 - "OWL Capabilities and Limitation: Typecasting and Ontology Patte...
OWLED 2015 - "OWL Capabilities and Limitation: Typecasting and Ontology Patte...OWLED 2015 - "OWL Capabilities and Limitation: Typecasting and Ontology Patte...
OWLED 2015 - "OWL Capabilities and Limitation: Typecasting and Ontology Patte...
 
Entity Retrieval (SIGIR 2013 tutorial)
Entity Retrieval (SIGIR 2013 tutorial)Entity Retrieval (SIGIR 2013 tutorial)
Entity Retrieval (SIGIR 2013 tutorial)
 
Pattern-based Acquisition of Scientific Entities from Scholarly Article Title...
Pattern-based Acquisition of Scientific Entities from Scholarly Article Title...Pattern-based Acquisition of Scientific Entities from Scholarly Article Title...
Pattern-based Acquisition of Scientific Entities from Scholarly Article Title...
 
0.0 Introduction to theory of computation
0.0 Introduction to theory of computation0.0 Introduction to theory of computation
0.0 Introduction to theory of computation
 
Perspectives on mining knowledge graphs from text
Perspectives on mining knowledge graphs from textPerspectives on mining knowledge graphs from text
Perspectives on mining knowledge graphs from text
 
Stack implementations
Stack implementationsStack implementations
Stack implementations
 
1.2. introduction to automata theory
1.2. introduction to automata theory1.2. introduction to automata theory
1.2. introduction to automata theory
 
Link Discovery Tutorial Part I: Efficiency
Link Discovery Tutorial Part I: EfficiencyLink Discovery Tutorial Part I: Efficiency
Link Discovery Tutorial Part I: Efficiency
 
Link Discovery Tutorial Part V: Hands-On
Link Discovery Tutorial Part V: Hands-OnLink Discovery Tutorial Part V: Hands-On
Link Discovery Tutorial Part V: Hands-On
 

Similar to Subtyping (7)

Reclassification
ReclassificationReclassification
Reclassification
 
Type Systems
Type SystemsType Systems
Type Systems
 
Ontology Building and its Application using Hozo
Ontology Building and its Application using HozoOntology Building and its Application using Hozo
Ontology Building and its Application using Hozo
 
Inheritance
InheritanceInheritance
Inheritance
 
Lecture14 xing fei-fei
Lecture14 xing fei-feiLecture14 xing fei-fei
Lecture14 xing fei-fei
 
A look inside the distributionally similar terms
A look inside the distributionally similar termsA look inside the distributionally similar terms
A look inside the distributionally similar terms
 
地理的知識グラフを取り込んだニューラル文書ジオロケーションモデル
地理的知識グラフを取り込んだニューラル文書ジオロケーションモデル地理的知識グラフを取り込んだニューラル文書ジオロケーションモデル
地理的知識グラフを取り込んだニューラル文書ジオロケーションモデル
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 

Subtyping

  • 1.
  • 2. Polymorphism Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 2 / 16
  • 3. Languages Languages are either monomorphic—every value and variable has only one type or Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 3 / 16
  • 4. Languages Languages are either monomorphic—every value and variable has only one type or polymorphic—values and variables may have multiple types. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 3 / 16
  • 5. Types of Polymorphism Universal Parametric Inclusion Ad hoc Overloading Coercion Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 4 / 16
  • 6. Subtyping Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 5 / 16
  • 7. Subsumption Principle Definition (Subsumption principle) If σ is a subtype of τ , then a value of type σ may be provided whenever a value of type τ is required. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 6 / 16
  • 8. Subsumption Principle Definition (Subsumption principle) If σ is a subtype of τ , then a value of type σ may be provided whenever a value of type τ is required. e : σ σ <: τ e:τ Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 6 / 16
  • 9. Liskov Substitution Principle Definition (Liskov substitution principle) Let q(x) be a property provable about objects x of type τ . Then q(y ) should be true for objects y of type σ where σ is a subtype of τ . Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 7 / 16
  • 10. Liskov Substitution Principle Definition (Liskov substitution principle) Let q(x) be a property provable about objects x of type τ . Then q(y ) should be true for objects y of type σ where σ is a subtype of τ . ∀x : τ : q(x) σ <: τ ∀y : σ : q(y ) Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 7 / 16
  • 11. Subsumption of Constructed Types What are the requirements for subsumption of function type, Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 8 / 16
  • 12. Subsumption of Constructed Types What are the requirements for subsumption of function type, product type, Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 8 / 16
  • 13. Subsumption of Constructed Types What are the requirements for subsumption of function type, product type, intersection type and Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 8 / 16
  • 14. Subsumption of Constructed Types What are the requirements for subsumption of function type, product type, intersection type and union type? Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 8 / 16
  • 15. Record Type {foo : S, bar : T } Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 9 / 16
  • 16. Universally Qualified Type ∀t.S(t) where S(t) is a type expression constructed from basic types and type variable t. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 10 / 16
  • 17. Reference Type Ref t Note: references in most languages are actually unions of a reference type and the unit type. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 11 / 16
  • 18. Array Type Array t Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 12 / 16
  • 19. Subsumption of Constructed Types (II) What are the requirements for subsumption of record type and Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 13 / 16
  • 20. Subsumption of Constructed Types (II) What are the requirements for subsumption of record type and universally qualified type, reference type and array type? Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 13 / 16
  • 21. Subtyping and Objects Object are records, therefore method’s return types may change covariantly, types of method parameters may change contravariantly and Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 14 / 16
  • 22. Subtyping and Objects Object are records, therefore method’s return types may change covariantly, types of method parameters may change contravariantly and field types are reference types, therefore may not change at all. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 14 / 16
  • 23. Subtyping and Objects Object are records, therefore method’s return types may change covariantly, types of method parameters may change contravariantly and field types are reference types, therefore may not change at all. Instances of generic classes are not compatible either. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 14 / 16
  • 24. This Type this Always denotes the type of the enclosing class. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 15 / 16
  • 25. See Cardelli, L. and Wegner, P. On understanding types, data abstraction, and polymorphism. ACM Computing Surveys 17, 4 (December 1985), 471-523. http://doi.acm.org/10.1145/6041.6042 Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 2: Subtyping October 5, 2010 16 / 16