Improving Scala's Safe Type-Level Abstraction

Size: px
Start display at page:

Download "Improving Scala's Safe Type-Level Abstraction"

Transcription

1 Seminar: Program Analysis and Transformation University of Applied Sciences Rapperswil Improving Scala's Safe Type-Level Abstraction Stefan Oberholzer, Dez 2010 Abstract Scala cannot nd all type errors at the code line they are made. In case of methods taking an abstract function, it is possible to rene the function type in a sub-class in a way that is not allowed. This error can only be detected at the place where a class implements this abstract method. In this document I will introduce the Scalina calculus that denes un-members, which allow that types can only be rened in a contravariant way. Scalina's solution has only a few implicit declarations because of this it requires about twice as much code as it would require in Scala. Nevertheless I beliefe that this could be a real gain for Scala's type system. 1 Introduction Scala is a purely object oriented programmining language, supporting also functional features. Scala has many useful features. Some of them still have minor problems not yet solved. One of this problems is that its type system is not able to identify all errors in type denitions in the class where they are made. A solution for this is proposed in the paper Safe type-level abstraction in Scala [MPO08] is presented in this document. An example where the problem in Scala occures can be seen in section 2.1. This introduction will give a short overview about Scala, variance, type systems and abstraction types. In section 2 I will provide a short overview about the type-level abstraction in Scala followed by an example illustrating a weakness of Scala. Section 3 will introduce Scalina, a purely object-oriented calculus used to prove that the explained type-level abstraction works. Afterwards in section 4 I will explain the type-levels used by Scalina to implement its type soundness. I will also explain how this object-oriented calculus can provide functional programming aspects. At the end in section 6 I will make a short conclusion about the abstraction mechanism introduced in Scalina. 1.1 Used type hierarchy for explenations In this document I will use the type hierarchy in Figure 1 for the example UML diagrams. Please be aware that this class hierarchy does not match the one of Scala or Scalina. I use this because it is easy imaginable. 1.2 Terms, types and kinds Terms, types and kinds are the basic constructs of programming languages. Some 1

2 Terms are components of variables or objects in a programming language. In our example, the HashSet object with the label lst is a term. Each value object in the HashSet is also a term. As you can see the amount of dierent terms in an application can only be determined at runtime. Figure 1: Type hierarchy for UML examples knowledge about terms, types and kinds is essential for the understanding of this paper. In this chapter I will give a short overview about terms, types and kinds using the example code in Listing 10. class MyClass{ def GenerateIntervalList(in : Int): HashSet[Int] ={ val lst : HashSet[Int] = new for { HashSet[Int](); value <- 0 to in{ lst += value; return lst; Listing 1: Term, types and kinds example Types are used to describe the type of a term. Like terms they can also be used like a variable. In our example the GenerateIntervalList method is a type. The classes MyClass and HashSet are also types. As you can see, the number of dierent types is specied at compile time. Kinds are the type of a type. They are the constructs allowed by the programming language. They can not be dened in the program code. A programming language may contain a kind hierarchy, comparable with the ones for types. The class MyClass is a structural kind, as the class construct is a kind. It is also a nominal kind because it has a name. As it does not contain any abstract types, it is a concrete kind too. The used kinds in this document are described in Table 1. The Class MyClass consists of the method GenerateIntervalList. This method takes an Int as argument and returns a HashSet containing all values from 0 to the number given in the parameter. 2

3 Kind Interval kind Description Interval kinds dene that the dened types have to be between its bounds. An example of this would be [mysubclass, myclass] that denes the possible classes that have to be super types of mysubclass and sub-types of myclass. Structural kind Structural kinds dene the form of a type. This is mostly used in functional programming. For example the function maptostring(input : Integer) : String denes a function of kind Integer -> String. Nominal kind Concrete kind A nominal Kind denes a type identied by its name A concrete kind declares types in which all types and terms are concrete. Table 1: Used Kinds 1.3 Type systems in programming languages Type systems are used in programming languages to dene the range of values a type can have. Modern programming languages have polymorphic type systems. They allow to dene code with the same behaviour for dierent types [Pie02]. Listing 5 shows an example without polymorphism. class NonPolymorphicExample { def mapintegertostring( a : Integer) : String = { a.tostring def mapdoubletostring(a : double) : String = { a.tostring Listing 2: Example without polymorphism The class NonPolymorphicExample contains two methods. Both of them map the parameter value to a String by using the tostring method. This is required because only a polymorphic type system would allow to de- ne a method for multiple types. In this chapter I will describe the most important categories of polymorphic type systems. These categories are not exclusive. Modern programming languages implement a combination of them. Parametric polymorphism Parametric polymorphism allows to write a single piece of code typted by using variables in place of actual types [Pie02]. An example can be seen in Listing 4. ParametricPolymorphismExample{ def map[a](a : A) : String = {a.tostring(); Listing 3: Parametric example polymorphism In this example the class contains only one method. As in the non-polymorphic example the method maps the parameter to a String value by using the tostring method. The dierence to the non-polymorphic class is that only one method is needed. The method takes a parameter of any type and maps it to a String by calling the tostring method. Ad-hoc polymorphism Ad-hoc polymorphism allows a function or method to work with several dierent types that might even behave in an unrelated way [CW85]. Overloading is the most common form of ad-hoc polymorphism. This allows a single function symbol to be associated with multiple implementations, each of it diering in the arguments taken. The compiler or 3

4 the runtime system decides which method to use, based on the arguments [Pie02]. Listing 6 shows an example of overloading. class OverloadingExample { def maptointeger( a : Double) : Int { a.toint; def maptointeger(a : String) : Int { new Integer(a) Listing 4: Overloading example In this case there are two methods with the same name but dierent parameter types behaving dierently. One method converts the value to an Int by calling the toint method and the other does the same with a String by using the constructor of Integer. So the body of both methods is dierent. As the body can be dierent both methods could also do something completely dierent. 1.5 Variance In the previous chapter I described the dierent types of type systems. Variance is an important topic in polymorphic type systems, as it describes which types are allowed. In this section I will describe the three variance types: covariance, contravariance and invariance Covariance Covariance means that the type hierarchy is in direction of the substitution hierarchy. This is the most common kind of variance. A sub-class implements all methods and elds of its super-class. So at every place where a class is required, instances of classes extending this class can be taken. Figure 2 shows an example for a covariant return type. The class ConcreteElement is a sub-type of the class AbstractElement. So are return types, Integer is a sub class of Number. Sub-type polymorphism Sub-type polymorphism means that a method taking a class A as parameter can also take any sub-class of A as parameter [Pie02]. This behaviour is standard in most of the object oriented programming languages. For example if there is a method with the signature map(a : Number) : String, the method can get a Number or an Integer, that is a sub-class of Number, as parameter. 1.4 Abstraction types There are two main systems of abstraction in current programming languages. Functional abstraction and object oriented abstraction. In functional abstraction the abstraction is over values. Parametric polymorphism (see section 1.3) is an example of functional abstraction. Object oriented abstraction uses abstract types and sub-typing to dene the abstraction. An example of this is sub-type polymorphism (see section 1.3). Figure 2: Covariance example Contravariance Contravariance means that the type hierarchy is against the direction of the substitution hierarchy. Variable types behave contravariant. If a variable is dened as subclass and no methods of the sub-class are required, the type of the super-class could be taken instead to dene the variable. Figure 3 shows an example for a contravariant method parameter. As in the 4

5 covariance example, ConcreteElement is a sub-class of AbstractElement. The type in this example is contravariant, this means that the parameter type of the method in ConcreteElement is a super-type of the parameter in AbstractElement. Figure 4: Invariance example Scala interacts with code written in Java Figure 3: Contravariance example Invariant Invariant means that the types in the superclass and the sub-class are equal. An example of this are arrays. The type of an array can not be casted to a super type. If this would be possible a dierent sub-type of the super type could be added into the array. It can also not be casted to a sub-type as it may already contain values of the type it had before. Figure 4 shows another example of this. The type parameter of the map method is the same in AbstractElement and ConcreteElement. 1.6 Scala As already mentioned Scala supports objectoriented and functional programming features. Scala was released by the EPFL 1 in January 2004 with the ability to compile to JVM platform compliant code. The second edition of Scala was released in Scala has the following key aspects [OAC + 06]: 1 École Polytechnique Fédéral de Lausanne Every value is an object and every operation is a method call Functions are rst-class values The abstraction concept is uniform for both, types and values Flexible modular mixin-composition constructs for composing classes and traits are included Object decomposition by pattern matching is supported Patterns and expressions are generalized to support the treatment of XML documents External extensions of components using views are allowed Scala has no interfaces. Instead it has traits, which behave like interfaces with the dierence that traits can contain implementations of methods. Due to the fact that a trait is like an interface, a class can implement multiple traits. 2 Type-Level Abstraction in Scala Scala supports object-oriented and functional programming features and abstraction 5

6 Figure 5: Type hierarchy of Scala mechanisms for values and types [OAC + 06]. As a result of this Scala can abstract over methods, parameters and classes. All of them can be passed as parameter to methods. Scala can dene generic types as covariant, contravariant and invariant. The abststract class Any is the root of Scala's type hierarchy. This means that any class is implicit dened as a sub class of Any. The trait Nothing is the bottom of Scala's type hierarchy. This means that any class is a super-class of Nothing. Scala's type hierarchy can be seen in Figure 5 [OAC + 06]. 2.1 Problems of Scala's type-level abstraction Scala does not allow to dene types as contravariant. This leads to the problem described in this section Example To show an existing problem in Scala I will take an extraction of the UML diagram of a possible UI Element implementation. The UML can be seen in Figure 6. I will describe a trait hierarchy dening a mapping method. To dene this I will have to de- ne a trait hierarchy. The super-class de- nes a trait that has to be implemented by the classes that can be taken as input and output of the map method. To have some specialications of this map method the trait is extended by two other traits. One of them is correct, while the other contains a failure in the variance of the input type. In the following I will describe each of the classes and explain the error. NumberElement The trait NumberElement denes an element that has something to do with a number. It just denes a generic type that has to be a sub-type of Number. NumberSelectionElement The sub-trait NumberSelectionElement is the most important trait in this diagram. It represents a NumberElement that can be selected. NumberSelectionElement denes a type Container that has to be a sub-type of NumberElement. This type is used as return type for the map method. This method takes a function that converts a variable of type T to type B. As it can be seen in the denition of the generic types, T and B must be of the type NumberElement. IntegerSelectionElement The trait IntegerSelectionElement is a subtrait of NumberSelectionElement. It denes that the map method has to return an IntegerSelectionElement. As IntegerSelectionElement is a sub-type of NumberElement this is no problem. As second binding IntegerSelectionElment denes that T has to be an Integer or a sub-type of 6

7 Figure 6: Erroneous UML diagram of Example it. This binding should not be allowed, as it strenghenes the restrictions on allowed method accepts. Let's assume an implementation of this method and an instance of this implementation is assigned to a variable of the type NumberSelectionElement. In this case the compiler would allow to pass a function converting a Double value to the type B, even though the implementation does not allow it. Scala is only able to detect this error when an implementation of the trait IntegerSelectionElement is created but not when the trait is implemented. In simple designs like the one of the example this is no real problem. In more complex designs it can happen that a lot of work was done taking this as basic before the error is detected. So solving the error might take a lot of time that would not have been required if the error would have been detected earlier. GenericNumberSelectionElement The trait GenericNumberSelectionElement shows a correct sub-trait of NumberSelectionElement binding the types. As T cannot be dened in a contravariant way, T can only be dened invariant. If contravariants would be allowed, T could also be dened contravariant, because this would allow to loosen the restrictions of the allowed functions. This can be allowed because the denition of the sub-class still allows all functions allowed by the super-class. I will show now the same example with contravariants allowed. Solution In the UML in Figure 7 I will de- ne contravariant types using the :> sign. Figure 7 shows the example UML with contravariants. Using this class hierarchy the compiler is able to detect the error while compiling the trait IntegerSelectionElement. This time the type T in NumberElement is de- ned as contravariant. Because of this a covariant renement as it was made in the trait IntegerSelectionElement is not allowed. Instead of this a binding as made in GenericNumberSelectionElement is now allowed. This is allowed because it loosens the restrictions of the map method. GenericNumberSelectionElement now takes any function converting any input type to another input type. Scalina is able to dene contravariants. So it allows to detect this error in the denition of the trait IntegerSelectionElement. 3 Scalina Scalina is a calculus modelling a core subset of Scala, used to prototype new features for Scala [Sca09]. In the implementation case used in the paper Safe Type-level Abstraction in Scala [MPO08] Scalina is used to show that it is possible to check the type-level abstraction at compile time of a class by introducing contravariants. As Scalina is only used to 7

8 Figure 7: Correct UML diagram of Example show that the concept introduced in the paper [MPO08] works I will only describe the important constructs used in Scalina. 3.1 Type-level abstraction in Scalina Scalina's type system uses kinds, types and terms. All terms in Scalina are objects. While terms are only used for computation, types are used for classication and computation. Kinds are used for classication only [MPO08]. The prove of the paper [MPO08] is restricted to statically bound members. So the examples in this document will be restricted to statically bound members too Members and un-members Scala denes members as types or terms belonging to an other type. Un-members are members with a type not yet specied. That means that the type of an un-member has to be specied later in a contravariant way. The term un-type and un-kind are used for un-members of the type or kind. For example the un-type of Integer, can be rened with Integer or any super type of it. 4 Type-Levels used in Scalina In this section I will describe the type-levels used to introduce contravariant declarations. I will only describe the most important def- Symbol Description T type or un-type S type or un-type R structural type new T instantiation of T p.type singleton type (short form of p.type#l) T R T expands to R at runtime Γ Under the assumptions in Γ Un[T ] Untype T. Table 2: Symbols initions. The full set of denitions is in the paper [MPO08]. Table 2 describes the symbols used for formal denitions. 4.1 Terms A term is an instantiation of a type. To instantiate a type and thus creating a term all un-members have to be rened. Because of this terms do not contain any un-types. Scalina is purely object-oriented, so a term is always an object specied by its path 2 and type. The most important denitions in the paper[mpo08] are: Any term can be expanded to its type at runtime. I will show this by using the 2 A path is the the full identication fo a term or type. For example scala.collection.mutable.hashset is the path for the type HashSet 8

9 example of a singleton lookup: T R (new T ).type R This means in words: When T expands to R at runtime the type of instance of T also expands to R at runtime. In the singleton case this is easy to understand as the type must be known to instantiate the singleton. So it is easy to get the real type of the singleton term. It can be checked that only un-members can be rened and every un-member is only rened once. 4.2 Types Types are used to dene terms. The abstraction mechanisms for types are similar to the ones used for terms. In addition to this it is possible to dene members, un-members and abstract members for types. Scalina also diers between structural types and nominal types. Un-types are used as classiers of value un-members. Type member selection is only allowed on types that consist only of concrete members. By denition singletons are always type safe because a singleton can only be created when all members are concrete 3. Because of the same reason it is also safe to assume that the self variable 4 does not contain any un-members. For simplicity Scalina does not allow variance for constructors. In the following I will list the most important denitions made in the paper [MPO08]. A type T can be normalized to T'. In a normalized type all member selections have been performed, all renments have been made and all compositions of structural types have also been made concrete. 3 The type contains no abstract members 4 variable that points to the own object. In Scala the implicit variable "this" is the self variable To get all the members in a type it can be expanded to its structural type. Un-types can only be rened with contravariant types. Γ T <: S Un[S] <: Un[T ] This means in words: Under the assumptions in Γ, T is a sub-type of S. So the un-type of S is a sub-type of the un-type of T. In other words: S is de- ned as super type of the type T. As unmembers have to be rened contravariantly the un-member of type S is a subtype of the un-member of type T. This is because all types that can be taken to rene the un-member of S can also be used to rene the un-member of type T. The type hierarchy between S and T can only be used to rene T. A type member becomes invariant as soon as it is made concrete. 4.3 Kinds Kinds describe which members may be selected on the types they classify. Interval (In(S, T)) kinds take over the role of bounds. For example In(S, T) means that type members are supertypes of S and sub-types of T. Types containing at least the member of kind R are described by the structural kind (Struct(R)). Nominal kinds (Nominal(R)) are like structural kinds with the dierence that they mark concrete type bindings. As last, concrete kinds (concrete(r)) are used to mark types that have at least all members in R specied. So types with all members bound must be a sub-type of the self type declared in R. Types may only be instantiated or used as target for type member selection, if all types are bound. As in Scala, Scalina uses Any and Nothing as upper and lower bound for kinds. 9

10 5 Functional programming with OO Type Systems In this chapter I will explain how functional programming can be implemented with object oriented programming languages by adding syntactic sugar to them. As Scalina is object oriented this can also be done in its case. To do this an interface for functions can be created containing multiple generic types. One for the output and the rest can be used to dene the input. The interface also contains an apply method that will implement the logic of the function. By adding syntactic sugar it can be allowed that the apply method is taken implicit if no other method is written and the class implements the function interface. The full prove for this can be found in the paper [MPO08]. I will take the following definition out of the mapping in the paper to show the behaviour with the apply method. T T {val a : Un[ T ]; val apply : T in the paper [MPO08] the solution requires twice as much code as it would require in a Scala implementation that does a similar thing. From my point of view the gain of nding the error at the place it is made is not worth the eort of twice as much code. In most of the cases it will take more time to write twice as much code than to remove the error that might be in the code. As Scalina is only a core calculus with only a few syntactic sugar and nearto no implicit denitions, it might be possible to reduce the required code to an amount close to the one required by Scala. If this would be possible, it were a great improvement for Scala. The function T-> T' takes an argument of type T and returns a value of type T'. It is mapped as a method taking a value a that is an un-member of the type T and a value apply that has the type T' [MPO08]. 6 Conclusion In this document I have shown how Scalina implements contravariant type denitions. Using this denitions it is possible to identify all type errors at the place they are made. With the current solution in Scala it can happen that a developer implements a complex type hierarchy, only containing abstract types, without having any compile error. When he tries to make an erroneous class concrete afterwards, he will get an error. Finding an error so late can mean that a big eort has to be taken to correct the error. The type-level abstraction of Scalina solves this problem but as it can be seen 10

11 References [CW85] Luca Cardelli and Peter Wegner. On understanding types, data abstraction, and polymorphism. Computing Surveys, 17(4):471522, December [MPO08] Adriaan Moors, Frank Piessens, and Martin Odersky. Safe type-level abstraction in scala. ACM, January [OAC + 06] Martin Odersky, Philippe Altherr, Vincent Crement, Julian Dragos, Gilles Dubochet, Burak Emir, Sean McDirmid, Stéphane Micheloud, Nikolay Mihaylov, Michel Schinz, Erik Stenman, Lex Spoon, and Matthias Zenger. An overview of the scala programming language. Technical Report Second Edition, École Polytechnique Fédéral de Lausanne (EPFL), 1015 Lausanne, Switzerland, [Pie02] Benjamin C. Pierce. Types and Programming Languages. MIT Press, [Sca09] Scalina. Scalina google code project [Online; read state 06-nov-2009]. 11

To What Extend Is Type Inference for Parameteric Polymorphism Possible in the Presence of Ad-Hoc and Subtype Polymorphism

To What Extend Is Type Inference for Parameteric Polymorphism Possible in the Presence of Ad-Hoc and Subtype Polymorphism To What Extend Is Type Inference for Parameteric Polymorphism Possible in the Presence of Ad-Hoc and Subtype Polymorphism Daniel Marty University of Applied Sciences Rapperswil Supervised by Prof. Dr.

More information

Functions and Objects. Week 7: Symbolic Computation

Functions and Objects. Week 7: Symbolic Computation Week 7: Symbolic Computation In the previous weeks, we've seen the essential elements of modern functional programming: Functions (rst class) Types (parametric) Pattern Matching Lists This week, we'll

More information

Software Engineering: Design & Construction

Software Engineering: Design & Construction Software Engineering: Design & Construction Department of Computer Science Software Technology Group Practice Exam May 22, 2015 First Name Last Name Matriculation Number Course of Study Department Signature

More information

Programming in Scala Second Edition

Programming in Scala Second Edition Programming in Scala Second Edition Martin Odersky, Lex Spoon, Bill Venners artima ARTIMA PRESS WALNUT CREEK, CALIFORNIA Contents Contents List of Figures List of Tables List of Listings Foreword Foreword

More information

Exercise 8 Parametric polymorphism November 18, 2016

Exercise 8 Parametric polymorphism November 18, 2016 Concepts of Object-Oriented Programming AS 2016 Exercise 8 Parametric polymorphism November 18, 2016 Task 1 Consider the following Scala classes: class A class B extends A class P1[+T] class P2[T

More information

INF 212/CS 253 Type Systems. Instructors: Harry Xu Crista Lopes

INF 212/CS 253 Type Systems. Instructors: Harry Xu Crista Lopes INF 212/CS 253 Type Systems Instructors: Harry Xu Crista Lopes What is a Data Type? A type is a collection of computational entities that share some common property Programming languages are designed to

More information

INF 212 ANALYSIS OF PROG. LANGS Type Systems. Instructors: Crista Lopes Copyright Instructors.

INF 212 ANALYSIS OF PROG. LANGS Type Systems. Instructors: Crista Lopes Copyright Instructors. INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright Instructors. What is a Data Type? A type is a collection of computational entities that share some common property Programming

More information

Dependent Object Types - A foundation for Scala's type system

Dependent Object Types - A foundation for Scala's type system Dependent Object Types - A foundation for Scala's type system Draft of January 14, 2010 Do Not Distrubute Martin Odersky, Georey Alan Washburn EPFL Abstract. 1 Introduction This paper presents a proposal

More information

CSCI-GA Final Exam

CSCI-GA Final Exam CSCI-GA 2110-003 - Final Exam Instructor: Thomas Wies Name: Sample Solution ID: You have 110 minutes time. There are 7 assignments and you can reach 110 points in total. You can solve the exercises directly

More information

301AA - Advanced Programming [AP-2017]

301AA - Advanced Programming [AP-2017] 301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2017-12: Polymorphisms

More information

The Scala Experiment {

The Scala Experiment { The Scala Experiment { Can We Provide Better Language Support for Component Systems? Martin Odersky EPFL 1 Component software { state of the art In principle, software should be constructed from re-usable

More information

Static type safety guarantees for the operators of a relational database querying system. Cédric Lavanchy

Static type safety guarantees for the operators of a relational database querying system. Cédric Lavanchy Static type safety guarantees for the operators of a relational database querying system Cédric Lavanchy June 6, 2008 Contents 1 Previous work 2 2 Goal 3 3 Theory bases 4 3.1 Typing a relation...........................

More information

Part III. Chapter 15: Subtyping

Part III. Chapter 15: Subtyping Part III Chapter 15: Subtyping Subsumption Subtype relation Properties of subtyping and typing Subtyping and other features Intersection and union types Subtyping Motivation With the usual typing rule

More information

An Approach to Behavioral Subtyping Based on Static Analysis

An Approach to Behavioral Subtyping Based on Static Analysis TACoS 04 Preliminary Version An Approach to Behavioral Subtyping Based on Static Analysis Francesco Logozzo 1 STIX - École Polytechnique F-91128 Palaiseau, France Abstract In mainstream object oriented

More information

Object Oriented Issues in VDM++

Object Oriented Issues in VDM++ Object Oriented Issues in VDM++ Nick Battle, Fujitsu UK (nick.battle@uk.fujitsu.com) Background VDMJ implemented VDM-SL first (started late 2007) Formally defined. Very few semantic problems VDM++ support

More information

Type Hierarchy. Lecture 6: OOP, autumn 2003

Type Hierarchy. Lecture 6: OOP, autumn 2003 Type Hierarchy Lecture 6: OOP, autumn 2003 The idea Many types have common behavior => type families share common behavior organized into a hierarchy Most common on the top - supertypes Most specific at

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

Subtyping. Lecture 13 CS 565 3/27/06

Subtyping. Lecture 13 CS 565 3/27/06 Subtyping Lecture 13 CS 565 3/27/06 Polymorphism Different varieties of polymorphism: Parametric (ML) type variables are abstract, and used to encode the fact that the same term can be used in many different

More information

Part III Chapter 15: Subtyping

Part III Chapter 15: Subtyping Part III Chapter 15: Subtyping Subsumption Subtype relation Properties of subtyping and typing Subtyping and other features Intersection and union types Subtyping Motivation With the usual typing rule

More information

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

Universe Type System for Scala. Daniel Schregenberger. Master Thesis

Universe Type System for Scala. Daniel Schregenberger. Master Thesis Universe Type System for Scala Daniel Schregenberger Master Thesis Software Component Technology Group Department of Computer Science ETH Zurich http://sct.inf.ethz.ch/ September 2006 - June 2007 Supervised

More information

Programming Languages & Paradigms PROP HT Abstraction & Modularity. Inheritance vs. delegation, method vs. message. Modularity, cont d.

Programming Languages & Paradigms PROP HT Abstraction & Modularity. Inheritance vs. delegation, method vs. message. Modularity, cont d. Programming Languages & Paradigms PROP HT 2011 Abstraction & Modularity Lecture 6 Inheritance vs. delegation, method vs. message Beatrice Åkerblom beatrice@dsv.su.se 2 Modularity Modularity, cont d. Modular

More information

Some instance messages and methods

Some instance messages and methods Some instance messages and methods x ^x y ^y movedx: dx Dy: dy x

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Week 13 - Part 1 Thomas Wies New York University Review Last lecture Object Oriented Programming Outline Today: Scala Sources: Programming in Scala, Second

More information

Overview. Elements of Programming Languages. Objects. Self-Reference

Overview. Elements of Programming Languages. Objects. Self-Reference Overview Elements of Programming Languages Lecture 10: James Cheney University of Edinburgh October 23, 2017 Last time: programming in the large Programs, packages/namespaces, importing Modules and interfaces

More information

Jam: A Smooth Extension With Java Mixins

Jam: A Smooth Extension With Java Mixins Jam: A Smooth Extension With Java Mixins Davide Ancona, Giovanni Lagorio, Ellena Zucca Presentation created by Left-out Jam abstract syntax Formal definitions of Jam static semantics Formal definitions

More information

More Relationships Between Classes

More Relationships Between Classes More Relationships Between Classes Inheritance: passing down states and behaviors from the parents to their children Interfaces: grouping the methods, which belongs to some classes, as an interface to

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Lecture 14: Design Workflow Department of Computer Engineering Sharif University of Technology 1 UP iterations and workflow Workflows Requirements Analysis Phases Inception Elaboration

More information

Computer Science 225 Advanced Programming Siena College Spring Topic Notes: Inheritance

Computer Science 225 Advanced Programming Siena College Spring Topic Notes: Inheritance Computer Science 225 Advanced Programming Siena College Spring 2017 Topic Notes: Inheritance Our next topic is another that is fundamental to object-oriented design: inheritance. Inheritance allows a programmer

More information

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes Java Curriculum for AP Computer Science, Student Lesson A20 1 STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes INTRODUCTION:

More information

COMP 250 Fall inheritance Nov. 17, 2017

COMP 250 Fall inheritance Nov. 17, 2017 Inheritance In our daily lives, we classify the many things around us. The world has objects like dogs and cars and food and we are familiar with talking about these objects as classes Dogs are animals

More information

Objects, Subclassing, Subtyping, and Inheritance

Objects, Subclassing, Subtyping, and Inheritance Objects, Subclassing, Subtyping, and Inheritance Brigitte Pientka School of Computer Science McGill University Montreal, Canada In these notes we will examine four basic concepts which play an important

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

Scala. Fernando Medeiros Tomás Paim

Scala. Fernando Medeiros Tomás Paim Scala Fernando Medeiros fernfreire@gmail.com Tomás Paim tomasbmp@gmail.com Topics A Scalable Language Classes and Objects Basic Types Functions and Closures Composition and Inheritance Scala s Hierarchy

More information

Parametric polymorphism and Generics

Parametric polymorphism and Generics Parametric polymorphism and Generics Today s Lecture Outline Parametric polymorphism Java generics Declaring and instantiating generics Bounded types: restricting instantiations Generics and subtyping.

More information

OO Technology: Properties and Limitations for Component-Based Design

OO Technology: Properties and Limitations for Component-Based Design TDDD05 Component-Based Software OO Technology: Properties and Limitations for Component-Based Design Interfaces Design by by Contract Syntactic Substitutability Inheritance Considered Harmful Fragile Base

More information

Practice for Chapter 11

Practice for Chapter 11 Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing

More information

Lecture 13: Subtyping

Lecture 13: Subtyping Lecture 13: Subtyping Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Programming Languages Pratikakis (CSD) Subtyping CS546, 2018-2019 1 / 15 Subtyping Usually found

More information

A Type is a Set of Values. Here we declare n to be a variable of type int; what we mean, n can take on any value from the set of all integer values.

A Type is a Set of Values. Here we declare n to be a variable of type int; what we mean, n can take on any value from the set of all integer values. Types A Type is a Set of Values Consider the statement: Read Chapter 6 int n; Here we declare n to be a variable of type int; what we mean, n can take on any value from the set of all integer values. Also

More information

Week 3: Functions and Data. Working with objects. Members of an object. = n 1d 2 n 2 d 1. + n 2. = n 1d 2. = n 1n 2 / n 2. = n 2

Week 3: Functions and Data. Working with objects. Members of an object. = n 1d 2 n 2 d 1. + n 2. = n 1d 2. = n 1n 2 / n 2. = n 2 Week 3: Functions and Data In this section, we'll learn how functions create and encapsulate data structures. Exemple : Rational Numbers We want to design a package for doing rational arithmetic. A rational

More information

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Atelier Java - J1. Marwan Burelle.  EPITA Première Année Cycle Ingénieur. marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 3 4 Plan 1 2 3 4 A Bit of History JAVA was created in 1991 by James Gosling of SUN. The first public implementation (v1.0) in 1995.

More information

CS205: Scalable Software Systems

CS205: Scalable Software Systems CS205: Scalable Software Systems Lecture 4 September 14, 2016 Lecture 4 CS205: Scalable Software Systems September 14, 2016 1 / 16 Quick Recap Things covered so far Problem solving by recursive decomposition

More information

Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview

Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3 Course Code: GK1965 Overview Java 8 Essentials for OO Developers is a three-day, fast-paced, quick start to Java 8 training

More information

Week 3: Functions and Data

Week 3: Functions and Data Week 3: Functions and Data In this section, we'll learn how functions create and encapsulate data structures. Exemple : Rational Numbers We want to design a package for doing rational arithmetic. A rational

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Recursive Types and Subtyping

Recursive Types and Subtyping Recursive Types and Subtyping #1 One-Slide Summary Recursive types (e.g., list) make the typed lambda calculus as powerful as the untyped lambda calculus. If is a subtype of then any expression of type

More information

Foo A Minimal Modern OO Calculus

Foo A Minimal Modern OO Calculus Foo A Minimal Modern OO Calculus Prodromos Gerakios George Fourtounis Yannis Smaragdakis Department of Informatics University of Athens {pgerakios,gfour,smaragd}@di.uoa.gr 1 / 24 What A core OO calculus

More information

COS 320. Compiling Techniques

COS 320. Compiling Techniques Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly

More information

First IS-A Relationship: Inheritance

First IS-A Relationship: Inheritance First IS-A Relationship: Inheritance The relationships among Java classes form class hierarchy. We can define new classes by inheriting commonly used states and behaviors from predefined classes. A class

More information

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes

More information

Featherweight Scala. Week 14

Featherweight Scala. Week 14 Featherweight Scala Week 14 1 Today Previously: Featherweight Java Today: Featherweight Scala Live research, unlike what you have seen so far. Focus today on path-dependent types Plan: 1. Rationale 2.

More information

Concepts of Object-Oriented Programming Peter Müller

Concepts of Object-Oriented Programming Peter Müller Concepts of Object-Oriented Programming Peter Müller Chair of Programming Methodology Autumn Semester 2017 1.2 Introduction Core Concepts 2 Meeting the Requirements Cooperating Program Parts with Well-Defined

More information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered

More information

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A. HAS-A Relationship Association is a weak relationship where all objects have their own lifetime and there is no ownership. For example, teacher student; doctor patient. If A uses B, then it is an aggregation,

More information

Dependent Object Types - A foundation for Scala s type system

Dependent Object Types - A foundation for Scala s type system Dependent Object Types - A foundation for Scala s type system Draft of September 9, 2012 Do Not Distrubute Martin Odersky, Geoffrey Alan Washburn EPFL Abstract. 1 Introduction This paper presents a proposal

More information

The Trouble with Types

The Trouble with Types The Trouble with Types Martin Odersky EPFL and Typesafe Types Everyone has an opinion on them Industry: Used to be the norm (C/C++, Java). Today split about evenly with dynamic. Academia: Static types

More information

Lecture Outline. Parametric Polymorphism and Java Generics. Polymorphism. Polymorphism

Lecture Outline. Parametric Polymorphism and Java Generics. Polymorphism. Polymorphism Lecture Outline Parametric Polymorphism and Java Generics Parametric polymorphism Java generics Declaring and instantiating generics Bounded types: restricting instantiations Generics and subtyping. Wildcards

More information

Object Model. Object Oriented Programming Spring 2015

Object Model. Object Oriented Programming Spring 2015 Object Model Object Oriented Programming 236703 Spring 2015 Class Representation In Memory A class is an abstract entity, so why should it be represented in the runtime environment? Answer #1: Dynamic

More information

Harvard School of Engineering and Applied Sciences Computer Science 152

Harvard School of Engineering and Applied Sciences Computer Science 152 Harvard School of Engineering and Applied Sciences Computer Science 152 Lecture 17 Tuesday, March 30, 2010 1 Polymorph means many forms. Polymorphism is the ability of code to be used on values of different

More information

Lecture 09: Introduction to Scala

Lecture 09: Introduction to Scala Lecture 09: Introduction to Scala Computer Science Department, University of Crete Multicore Processor Programming Based on slides by D. Malayeri, S.D. Vick, P. Haller, and M. Madsen Pratikakis (CSD) Scala

More information

Chapter 5. Inheritance

Chapter 5. Inheritance Chapter 5 Inheritance Objectives Know the difference between Inheritance and aggregation Understand how inheritance is done in Java Learn polymorphism through Method Overriding Learn the keywords : super

More information

Let us dene the basic notation and list some results. We will consider that stack eects (type signatures) form a polycyclic monoid (introduced in [NiP

Let us dene the basic notation and list some results. We will consider that stack eects (type signatures) form a polycyclic monoid (introduced in [NiP Validation of Stack Eects in Java Bytecode Jaanus Poial Institute of Computer Science University of Tartu, Estonia e-mail: jaanus@cs.ut.ee February 21, 1997 Abstract The Java language is widely used in

More information

Java Wildcards Meet Definition-Site Variance

Java Wildcards Meet Definition-Site Variance Java Wildcards Meet Definition-Site Variance John Altidor 1 Christoph Reichenbach 2,1 Yannis Smaragdakis 3,1 1 University of Massachusetts 2 Google 3 University of Athens Outline Motivation for Variance.

More information

CS-XXX: Graduate Programming Languages. Lecture 23 Types for OOP; Static Overloading and Multimethods. Dan Grossman 2012

CS-XXX: Graduate Programming Languages. Lecture 23 Types for OOP; Static Overloading and Multimethods. Dan Grossman 2012 CS-XXX: Graduate Programming Languages Lecture 23 Types for OOP; Static Overloading and Multimethods Dan Grossman 2012 So far... Last lecture (among other things): The difference between OOP and records

More information

Advanced oo concepts Specialization of behaviour? Multiple inheritance - alternatives to. Inner classes Classes

Advanced oo concepts Specialization of behaviour? Multiple inheritance - alternatives to. Inner classes Classes Types and Classes I II From predefined (simple) and user-defined (composite) types via Abstract data types Advanced oo concepts Specialization of behaviour? Multiple inheritance - alternatives to Inner

More information

Don t Believe the Hype. CS152: Programming Languages. Lecture 21 Object-Oriented Programming. Class-based OOP. So what is OOP?

Don t Believe the Hype. CS152: Programming Languages. Lecture 21 Object-Oriented Programming. Class-based OOP. So what is OOP? Don t Believe the Hype CS152: Programming Languages Lecture 21 Object-Oriented Programming Dan Grossman Spring 2011 OOP lets you: 1. Build some extensible software concisely 2. Exploit an intuitive analogy

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2018 Lecture 7b Andrew Tolmach Portland State University 1994-2018 Dynamic Type Checking Static type checking offers the great advantage of catching errors early And

More information

CSE Lecture 7: Polymorphism and generics 16 September Nate Nystrom UTA

CSE Lecture 7: Polymorphism and generics 16 September Nate Nystrom UTA CSE 3302 Lecture 7: Polymorphism and generics 16 September 2010 Nate Nystrom UTA 2 Polymorphism poly = many morph = shape Allow a variable to contain values with different types 3 Subtype polymorphism

More information

Programming Languages Lecture 15: Recursive Types & Subtyping

Programming Languages Lecture 15: Recursive Types & Subtyping CSE 230: Winter 2008 Principles of Programming Languages Lecture 15: Recursive Types & Subtyping Ranjit Jhala UC San Diego News? Formalize first-order type systems Simple types (integers and booleans)

More information

Exercise 8 Parametric polymorphism November 17, 2017

Exercise 8 Parametric polymorphism November 17, 2017 Concepts of Object-Oriented Programming AS 2017 Exercise 8 Parametric polymorphism November 17, 2017 Task 1 Implement a list in Java or C# with two methods: public void add(int i, Object el) public Object

More information

Official Survey. Cunning Plan: Focus On Objects. The Need for a Calculus. Object Calculi Summary. Why Not Use λ-calculus for OO?

Official Survey. Cunning Plan: Focus On Objects. The Need for a Calculus. Object Calculi Summary. Why Not Use λ-calculus for OO? Modeling and Understanding Object-Oriented Oriented Programming Official Survey Please fill out the Toolkit course survey 40142 CS 655-1 Apr-21-2006 Midnight May-04-2006 9am Why not do it this evening?

More information

Type Systems. Today. 1. Organizational Matters. 1. Organizational Matters. Lecture 1 Oct. 20th, 2004 Sebastian Maneth. 1. Organizational Matters

Type Systems. Today. 1. Organizational Matters. 1. Organizational Matters. Lecture 1 Oct. 20th, 2004 Sebastian Maneth. 1. Organizational Matters Today Type Systems 1. Organizational Matters 2. What is this course about? 3. Where do types come from? 4. Def. of the small language Expr. Its syntax and semantics. Lecture 1 Oct. 20th, 2004 Sebastian

More information

Design Pattern and Software Architecture: IV. Design Pattern

Design Pattern and Software Architecture: IV. Design Pattern Design Pattern and Software Architecture: IV. Design Pattern AG Softwaretechnik Raum E 3.165 Tele.. 60-3321 hg@upb.de IV. Design Pattern IV.1 Introduction IV.2 Example: WYSIWYG Editor Lexi IV.3 Creational

More information

Concepts of Object-Oriented Programming Peter Müller

Concepts of Object-Oriented Programming Peter Müller Concepts of Object-Oriented Programming Peter Müller Chair of Programming Methodology Autumn Semester 2017 1.2 Introduction Core Concepts 2 Meeting the Requirements Cooperating Program Parts with Well-Defined

More information

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 18 Thursday, March 29, 2018 In abstract algebra, algebraic structures are defined by a set of elements and operations

More information

Exercise 6 Multiple Inheritance, Multiple Dispatch and Linearization November 4, 2016

Exercise 6 Multiple Inheritance, Multiple Dispatch and Linearization November 4, 2016 Concepts of Object-Oriented Programming AS 2016 Exercise 6 Multiple Inheritance, Multiple Dispatch and Linearization November 4, 2016 Task 1 Consider the following C++ program: class X X(int p) : fx(p)

More information

Overview. Elements of Programming Languages. Objects. Self-Reference

Overview. Elements of Programming Languages. Objects. Self-Reference Overview Elements of Programming Languages Lecture 11: James Cheney University of Edinburgh November 3, 2015 Last time: programming in the large Programs, packages/namespaces, importing Modules and interfaces

More information

Inheritance, Polymorphism, and Interfaces

Inheritance, Polymorphism, and Interfaces Inheritance, Polymorphism, and Interfaces Chapter 8 Inheritance Basics (ch.8 idea) Inheritance allows programmer to define a general superclass with certain properties (methods, fields/member variables)

More information

Programming Kotlin. Familiarize yourself with all of Kotlin s features with this in-depth guide. Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI

Programming Kotlin. Familiarize yourself with all of Kotlin s features with this in-depth guide. Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI Programming Kotlin Familiarize yourself with all of Kotlin s features with this in-depth guide Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI Programming Kotlin Copyright 2017 Packt Publishing First

More information

Inheritance and object compatibility

Inheritance and object compatibility Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not the other way around Examples: reference/pointer can

More information

Compilers and computer architecture: Semantic analysis

Compilers and computer architecture: Semantic analysis 1 / 1 Compilers and computer architecture: Semantic analysis Martin Berger Alex Jeffery October 2018 Recall the function of compilers 2 / 1 3 / 1 Recall the structure of compilers Source program Lexical

More information

An Introduction to Subtyping

An Introduction to Subtyping An Introduction to Subtyping Type systems are to me the most interesting aspect of modern programming languages. Subtyping is an important notion that is helpful for describing and reasoning about type

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

Data Structures (list, dictionary, tuples, sets, strings)

Data Structures (list, dictionary, tuples, sets, strings) Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access

More information

CPS 506 Comparative Programming Languages. Programming Language

CPS 506 Comparative Programming Languages. Programming Language CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support

More information

[ L5P1] Object-Oriented Programming: Advanced Concepts

[ L5P1] Object-Oriented Programming: Advanced Concepts [ L5P1] Object-Oriented Programming: Advanced Concepts Polymorphism Polymorphism is an important and useful concept in the object-oriented paradigm. Take the example of writing a payroll application for

More information

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example Overview Elements of Programming Languages Lecture 11: Object-oriented functional programming James Cheney University of Edinburgh October 30, 2017 We ve now covered: basics of functional programming (with

More information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information

More information

Type Systems. Pierce Ch. 3, 8, 11, 15 CSE

Type Systems. Pierce Ch. 3, 8, 11, 15 CSE Type Systems Pierce Ch. 3, 8, 11, 15 CSE 6341 1 A Simple Language ::= true false if then else 0 succ pred iszero Simple untyped expressions Natural numbers encoded as succ succ

More information

Recursive Types and Subtyping

Recursive Types and Subtyping Recursive Types and Subtyping #1 One-Slide Summary Recall: Recursive types (e.g., τ list) make the typed lambda calculus as powerful as the untyped lambda calculus. If τ is a subtype of σ then any expression

More information

CSE1720. General Info Continuation of Chapter 9 Read Chapter 10 for next week. Second level Third level Fourth level Fifth level

CSE1720. General Info Continuation of Chapter 9 Read Chapter 10 for next week. Second level Third level Fourth level Fifth level CSE1720 Click to edit Master Week text 08, styles Lecture 13 Second level Third level Fourth level Fifth level Winter 2014! Thursday, Feb 27, 2014 1 General Info Continuation of Chapter 9 Read Chapter

More information

Object Model. Object Oriented Programming Winter

Object Model. Object Oriented Programming Winter Object Model Object Oriented Programming 236703 Winter 2014-5 Class Representation In Memory A class is an abstract entity, so why should it be represented in the runtime environment? Answer #1: Dynamic

More information

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods. Inheritance Inheritance is the act of deriving a new class from an existing one. Inheritance allows us to extend the functionality of the object. The new class automatically contains some or all methods

More information

Subtyping and Objects

Subtyping and Objects Subtyping and Objects Massimo Merro 20 November 2017 Massimo Merro Data and Mutable Store 1 / 22 Polymorphism So far, our type systems are very rigid: there is little support to code reuse. Polymorphism

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Type Inference Some statically typed languages, like ML (and to a lesser extent Scala), offer alternative

More information

Unifying functional and object-oriented programming with Scala 齐琦, 海南大学计算机发展前沿系列课程

Unifying functional and object-oriented programming with Scala 齐琦, 海南大学计算机发展前沿系列课程 Unifying functional and object-oriented programming with Scala, 海南大学计算机发展前沿系列课程 2 原文引用 Odersky, M. and T. Rompf (2014). "Unifying functional and objectoriented programming with Scala." Communications of

More information

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106 CS 565: Programming Languages Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106 Administrivia Who am I? Course web page http://www.cs.purdue.edu/homes/peugster/cs565spring08/ Office hours By appointment Main

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1 Object-Oriented Languages and Object-Oriented Design Ghezzi&Jazayeri: OO Languages 1 What is an OO language? In Ada and Modula 2 one can define objects encapsulate a data structure and relevant operations

More information