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 PresentationGiorgio Orsi
 
What's next in Julia
What's next in JuliaWhat's next in Julia
What's next in JuliaJiahao Chen
 
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 DataArtem Lutov
 
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 SystemsHolistic Benchmarking of Big Linked Data
 
Inductive Entity Typing Alignment
Inductive Entity Typing AlignmentInductive Entity Typing Alignment
Inductive Entity Typing AlignmentGiuseppe Rizzo
 
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...Adila Krisnadhi
 
Entity Retrieval (SIGIR 2013 tutorial)
Entity Retrieval (SIGIR 2013 tutorial)Entity Retrieval (SIGIR 2013 tutorial)
Entity Retrieval (SIGIR 2013 tutorial)krisztianbalog
 
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...Jennifer D'Souza
 
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 computationSampath Kumar S
 
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 textJennifer D'Souza
 
Stack implementations
Stack implementationsStack implementations
Stack implementationsRajendran
 
1.2. introduction to automata theory
1.2. introduction to automata theory1.2. introduction to automata theory
1.2. introduction to automata theorySampath Kumar S
 

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

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 HozoKouji Kozaki
 
Lecture14 xing fei-fei
Lecture14 xing fei-feiLecture14 xing fei-fei
Lecture14 xing fei-feiTianlu Wang
 
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 termsKow Kuroda
 
地理的知識グラフを取り込んだニューラル文書ジオロケーションモデル
地理的知識グラフを取り込んだニューラル文書ジオロケーションモデル地理的知識グラフを取り込んだニューラル文書ジオロケーションモデル
地理的知識グラフを取り込んだニューラル文書ジオロケーションモデルTakashi Inui
 

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

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Recently uploaded (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

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