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

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
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
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Recently uploaded (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
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
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

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