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

Size: px
Start display at page:

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

Transcription

1 To What Extent 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. Farhad D. Mehta Seminar Spring 2017 Abstract The aim of this paper is to compare the capabilities of type inference in different contexts. While complete type inference is possible in pure functional programming, mainstream languages still lack this feature and only slowly make progress in this area. The problems and limitations arising if subtype polymorphism and overloading, basic features in object-oriented programming, are components in such languages, are captured and analyzed in this paper. Finally, the type inference capabilities of modern multi-paradigm languages like Scala and Swift are studied and compared to type inference available in Haskell. 1 Introduction Type inference for functional languages is common nowadays and is finding a way into mainstream languages with subtypes like Java (SE 7) and C++ (11) to get rid of the tedious task of adding type annotations to every identifier [Pot01]. Languages with a shorter history than above-mentioned languages, for example, Scala and Swift, offer type inference since their first release. Even though, their type systems were constructed with type inference in mind, they do not provide this to the same extent as representatives of pure functional programming languages. Definition 1 (Type Inference) Reconstructing the type information of terms without type annotations in their external form (the language programmers use to write the code) at compile time, is called type reconstruction or type inference. In explicitly typed languages, where the external and the internal form both contain type annotations, type inference is equivalent to the identity function. [PT00] Modern programming languages offer different kinds of polymorphism to write generic code and therefore avoid code duplication. The term polymorphism is confusing and refers to different forms of polymorphism depending on the context. In functional programming, the term mostly is associated with parametric polymorphism while object-oriented programmers link it to subtype polymorphism and call parametric polymorphism generics [Pie02]. It is common to differentiate three kinds of polymorphism [Sut15]. Definition 2 (Parametric Polymorphism) If a function is defined over a range of types and acts the same for each type, it is called parametric polymorphism [WB89]. Definition 3 (Ad-hoc Polymorphism) In contrast to parametric polymorphism, a different meaning for the same function name can be achieved by overloading a meaning for each combination of the arguments. That means the function is acting differently for each type [CW85]. 1

2 Definition 4 (Subtype Polymorphism) Subtype polymorphism introduces a hierarchy S <: T that allows substituting values of a supertype T by values of a subtype S. This is based on the Liskov substitution principle [Lar11]. instances. The following sections cover the question how polymorphism affects the possibility to infer types and how modern programming languages combine different kinds of polymorphism. With Haskell as the representative for functional languages and Scala and Swift for multi-paradigm languages, the capability of type inference depending on the presence of subtype polymorphism is scrutinized. Section 2 gives an overview of the Hindley-Milner type system for parametric polymorphism. In section 3, the problem occurring if the Hindley- Milner type system is extended with ad-hoc polymorphism is discussed and solutions therefor are analyzed. The complexity of type inference in the presence of subtype polymorphism and why it is not possible to infer a most general type is shown in section 4. A lot of research was done in System F and many functional languages uses a type system similar to System F. Section 5 shows why type inference in System F is undecidable and how this affects Haskell whose core coincides with a fragment of System F. How modern multiparadigm languages are still able to offer type inference is shown in section 6. It deals with local type inference which is used in Swift and Scala. 2 Hindley-Milner This section serves to give an introduction to the Hindley-Milner type system which is named after its inventors J. Roger Hindley and Robin Milner. With the Hindley-Milner type system, an approach to parametric polymorphism is available that infers the most general type of a given program if such a type exists. It first appeared in Standard ML and can be found in Haskell and other functional languages in an extended form [Wie11]. Definition 5 (Principal Type) Alongside the interpreted base types, an infinite collection of 2 uninterpreted types, also called principal types or most general types, exist. Principal types serve as type variables that can be instantiated with other types. It has all other types that are possible as The function λx : t.x has the type t t and represents the identity function for all elements of t, independently of what t may be [Pie02]. The annotation :t specifies the type of the argument that the function can be applied to. 2.1 Complete Type Inference Defining an inference rule for recursive functions involves a problem. Inferring the type of the newly bound identifier needs the type of the expression on the right-hand side which however requires the type of the newly bound identifier. This problem is solved by dividing type inference into the phases constraint generation and generalization [Wie11]. During constraint generation, each expression is analyzed which results in a constraint set C. Constraints are statements about the types of an expression. The order of the traversal does not matter [Kri14]. Definition 6 (Constraint Set C) A set of equations is called a constraint set. If the substitution instances σs and σt are identical, the equation is said to unify. A substitution σ satisfies C if every equation unifies [Pie02]. Definition 7 (Substitution S) A substitution S is a finite mapping from type variables to types. A single untyped function has infinitely many types. (a b) a b (1) If the type (1) where s and t correspond to type variables is given, it has every type that is a substitution instance of it. The types shown in (2) and (3) are therefore valid types for this untyped function. (Int Bool) Int Bool (2) (F loat Int) F loat Int (3)

3 Given a type expression σ and a substitution S, the type expression Sσ is obtained by replacing each variable t in σ with S(t) [Mit91]. In the generalization phase, a unification (solving the constraints) of the constraint set C is done, which results in a type substitution σ. If the unification is successful, σ is the principal unifier to the constraint set C. After applying this unifier to a type τ, it yields the principal type τ p [Wie11]. How parametric polymorphism works in Haskell is shown in the following example without going into detail. Example 1 Everytime an unknown type is encountered, a new principal type gets introduced (in this example, a new type is introduced in alphabetical order, but it does not matter how the names are chosen). The function swap shown in Listing 1 has two parameters, so its type has to be a b c. The second argument has to be a list (denoted by [ ] and (x:xs)). With this information, the principal type c has to be a list type [d]. Further, f has to be a function that takes an element of that list and returns an element of type e. The type returned by the map function has to be a list of type e. The most general type therefore is (d e) [d] [e]. 1 mymap f [ ] = [ ] 2 mymap f ( x : xs ) = f x : mymap f xs Listing 1: Map function in Haskell and ad-hoc polymorphism is that only one algorithm is used for parametric polymorphic functions, whereas a different algorithm may be used for an overloaded function depending on its types [HHPJW96]. 3.1 Early Approaches The equality operation is used in this section to show the limitations of the ad-hoc polymorphism before Haskell introduced type classes. The equality operation has distinct implementations associated with it. Int Int Bool (4) F loat F loat Bool (5) The types shown in (4) and (5) represent two types for the same operation. The first and simplest approach is to overload equality without adding abstract or function types as it was done in the first version of Standard ML. With this approach, it is possible to check for equality of integers (2*8 == 16) or characters ( A == B ). But it is not possible to define a function like figured in Listing 2 and call it as shown in Listing 3. 1 member [ ] y = False 2 member ( x : xs ) y = ( x == y ) 3 member xs y Listing 2: Function member in a functional language 3 Extending Hindley-Milner with ad-hoc polymorphism In this section, problems arising by adding ad-hoc polymorphism to Hindley-Milner and the solution provided with type classes are presented. Type classes are an approach to add ad-hoc polymorphism to the Hindley-Milner type system. Before the time of Haskell, there was no standard approach to overloading. The difference between parametric polymorphism 3 1 member [ 4, 9, 8 ] 9 2 member Member? b Listing 3: Calling the function member A second approach is to make it work with all types (fully polymorphic). Listing 4 shows the type of the equality operation. 1 (==) : : a > a > Bool Listing 4: Signature of the equality operation

4 The type of the member function defined in Listing 3 with this approach is figured in Listing 5. 1 member : : [ a ] > a > Bool. Listing 5: Signature of the function member with the second approach However, not all types possess a meaningful implementation for equality. The equality of functions, for example, is undecidable because it is a form of the halting problem. The third approach is to limit polymorphism instead of making the equality fully polymorphic. This is done by adding an equality type variable and is the current approach in Standard ML. Listing 6 shows how such a type looks. 1 (==) : : a (==) > a (==) > Bool Listing 6: Signature of the equality operation with an equality type variable Applying equality on a function type or an abstract type causes a type error because there is no substitution available [WB89]. Definition 8 (Equality Type Variable) Other than principal types, equality type variables can only be substituted by types that admit equality. 3.2 Type Classes Type classes bring parametric and ad-hoc polymorphism, two kinds of polymorphism that were separated, together. The idea is to generalize the approach of equality types to allow user-defined collections of types. Type signatures and names of the class are provided in a class declaration as shown in Listing 7. 1 class Eq a where 2 (==), (/=) : : a > a > Bool 3 x /= y = not ( x == y ) 4 x == y = not ( x /= y ) Listing 7: Class declaration in Haskell It means that a belongs to the class Eq if the equality operation (==) or (/=) with the signature a a Bool is defined on it. It also provides a default implementation of (/=) or (==) in case that one operation is implemented. This reduces the operations that must be implemented to conform to the type class. Additionally, to the class declaration (Listing 8), there is an instance declaration in which implementations of all class operations for a given type are provided. The instance declaration says that the type Int belongs to the type class Eq and the implementation of the equality is given by the function primeqint which has to be of type (Int Int Bool). 1 instance Eq Int where 2 (==) = primeqint 3 instance Eq Char where 4 (==) = primeqchar 5 instance Eq Bool where 6 (==) = primeqbool Listing 8: Instance declaration in Haskell If the type is Char or Bool the implementation can be found in primeeqchar respectively primeqbool instead. The function primeqbool could be implemented like figured in Listing 9. If the first argument is true, the id function is called on the second argument, else the not function is called which returns true if the argument is false and vice versa. 1 primeqbool : : Bool > Bool > Bool 2 primeqbool true = id 3 primeqbool false = not Listing 9: Example implementation of primeqbool Listing 10 shows the signature that the function defined in Listing 2 has in Haskell. The type variable a can only be substituted with types that belong to the class Eq. 1 member : : Eq a => [ a ] > a > Bool Listing 10: Signature of the function member in Haskell 4

5 3.2.1 Superclasses Sometimes it makes sense to require type classes that were already defined when constructing new type classes. 1 class ( Eq a ) => Ord a where 2 (<) : : a > a > Bool 3 (<=) : : a > a > Bool 4 5 instance Ord Int where 6 ( <) = primltint 7 (<=) = primleint Listing 11: Superclass of Eq The term (Eq a) in Listing 11 is called a context of the type and limits the type of a to those admitting equality. Thus, if the operations (==), (<) and (<=) are defined on a type, the type is an instance of the type class Ord. This allows simpler signatures to be inferred. The inferred signature of the function defined in Listing 12 which is using Eq and Ord is shown in Listing search = \ x ys > not ( null ys ) && 2 ( x == head ys 3 ( x < head ys && search x ( tail ys ) ) ) Listing 12: Function search in Haskell Without superclasses, the context would be (Eq a, Ord a). The hierarchy formed by superclasses must be a directed acyclic graph [HHPJW96]. 1 search : : Ord a => a > [ a ] > Bool Listing 13: Signature of the function search in Haskell Translation It is possible to translate a program with type classes to an equivalent program without overloading during the inference process. This program without overloading is then typable in the Hindley-Milner type system. All the instance declarations generate a corresponding dictionary declaration. Overloaded functions will be translated to functions without overloading using this dictionary. The class dictionary contains tuples of functions and sub-dictionaries for all its functions and operators. This allows calling specific 5 functions depending on the type of the input and the operator. dicteqint =, primeqint dictordint = primeqint, primltint, primleint A dictionary is built using e 1...e n. The dictionary dictordint contains a dictionary dicteqint (the dictionary for instances of Eq Int) for its superclass and methods for (<) and (<=). To extract a method from the corresponding dictionary, a selector is offered for each operation in a class. There is also a selector for each superclass to extract the superclass dictionary from the subclass dictionary. The selectors for the class Eq and Ord look like following [HHPJW96]: (==) = \, == == geteqf romord = \ dicteq, <, <= dicteq (<) = \ dicteq, <, <= < (<=) = \ dicteq, <, <= <= Listing 14 shows the translation of the function search defined in Listing search = \ dord x ys > not ( null ys )&& 2 ((==) ( geteqfromord dord ) x ( head ys ) 3 (( <) dord x ( head ys )&& 4 search dord x ( tail ys ) ) ) Listing 14: Translation of the function search 4 Type Inference with Subtype Polymorphism Subtyping and overloading are basic features of typed, object-oriented programming languages. In section 3, a solution to enrich the Hindley- Milner type system with ad-hoc polymorphism was presented. The focus in this section is the complexity and the possibility to obtain most general types of expressions including additional subtype assumptions. 4.1 Complexity The typability of the simply typed lambda calculus can be reduced to unification [ASU86]. This

6 subsection shows that a problem exists to which type inference in the presence of subtyping can be reduced to and shows in which complexity class the problem belongs. Definition 9 (TIS) The decision problem for type inference in the presence of subtyping (TIS) is defined as follows: Is M typable over Σ for a given signature Σ and a term M. A signature Σ consists of a set B of base types, a partial order on this B ( B ) and a set T of pairs c, σ where c is a term constant and σ is a ground type (no type variable). Definition 10 (SSI) The satisfiability of subtype inequalities (SSI) is a decision problem of the following form: Is I satisfiable in B for a given finite partial order B and a system I of inequalities? A partial order on a set S is given if the relation has following properties: (i) Reflexivity: x x for all x S (ii) Antisymmetry: a b and b implies a = b (iii) Transitivity: a b and b c implies a c Figure 1: The relation among complexity classes [psp] 4.2 Most General Type In this subsection, it is shown that it is impossible to find a most general type in the presence of subtyping. The untyped lambda calculus with following grammar will be used to demonstrate examples with subtype polymorphism: M := x MM λx.m A polynomial time reduction from the decision problem for type inference in the presence of subtyping to the satisfiability of subtype inequalities (TIS m SSI) and vice versa (SSI m TIS) exist. The problems are therefore proven to be algorithmically equivalent and the lower bound of SSI can be transferred to TIS. The lower bound of SSI is known to be PSPACE hard [HM95]. Definition 11 (PSPACE hard) PSPACE is the class of problems solvable in polynomial space with unlimited time available. An NP problem has a certificate with polynomial size such that the problem can be solved in polynomial time if the certificate is known. Since checking if the certificate is valid takes polynomial time, it takes polynomial space as well. Therefore, no problem in NP is harder than any problem in PSPACEhard [Aar]. It is not known but conjectured that PSPACE > NP as shown in Figure 1. The first term x may be any variable. The application of the function M to an argument M is denoted by MM and the function obtained by treating M as a function of x as λx.m. Function application is left-associative, that means wxyz is the same as ((wx)y)z. A lambda abstraction extends as far to the right as possible. The term λx.λy.y corresponds to λx.(λy.y) [Mit91]. Example 2 Let M = λf.λ.xλy.k(f x)(f y) where K is the combinator (λx.(λy.x)) that returns the first argument and discards the second. With Hindley-Milner the typing for the term M is: (e d) e e d (6) 6

7 The typing (6) was received in the same manner as described in section 2. If the coercion set C is nonempty for example {s u, t u, v w}, and the argument x has type s and the argument y has type t, a possible typing for M is: (u v) s t w (7) Per definition, the most general typing has all other possible typings as an instance. However, there is no substitution S such that Sσ = σ where σ corresponds to the typing shown in (6) and σ to (7) [HM95]. Therefore, the type (9) is contained in (10) but neither the containment shown in (14) nor the containment in (15) is valid [Mit91]. Int Int Real Real (14) Real Real Int Int (15) 5 Undecidability in System F The second-order polymorphic lambda calculus also known as System F was independently invented by Girard and Reynolds. Both formulated the system in the Church-style where type an- Definition 12 (Coercion Set C) A Coercion notations are explicitly added to terms. This set C is a set of coercions. The coercions, in section deals with the System F in the Currystyle where type annotations are omitted. The this case, are subtype assertions between arbitrary types. A subtype assertion has the form σ τ, type systems used in functional programming languages are often related to System F. In software where σ and τ are base types. engineering, programmers wish to avoid code duplications. System F exhibits parametric polymor- Example 3 Given a function f that has the type shown in (8), the expression λx.k.x(fx) and the phism and all computations on typable λ-terms containment Int Real. are guaranteed to halt. Although this property gets destroyed by adding features that allow nontermination, it still can be helpful for handling Real Bool (8) subexpressions which do not use those features. Haskell is a functional language that uses a type The combinator K has the types listed in (9) - system whose core coincides with a fragment of (11) in this context. System F [Wel99]. Int Int (9) Int Real (10) Definition 13 (TYP) The typability problem is defined as follows: Do assumptions A and a type τ exist such that A M : τ is derivable? Real Real (11) The type σ τ is a functional type which takes arguments of type σ and results in a type τ. If subtyping is regarded as an ordering, then the arrow operator is antimonotonic in its first argument (12) and monotonic in its second argument (13). if σ ρ then ρ τ σ τ (12) if σ ρ then τ σ τ ρ (13) Definition 14 (TC) The type checking problem is defined as follows: Is A M : τ derivable for arbitrarily chosen assumptions A and type τ? Definition 15 (SUP) The semi-unification is a generalization for matching and unification for a given pair of terms s and t. Do substitutions ρ and σ exist such that ρ(σ(s)) = σ(t)? Unification solves equations by finding all substitutions that make the term equal. Matching solves equations where only one term has to be instantiated by the substitution [KMNS91]. 7

8 SUP is reducible to TC in System F (SUP TC). A proof that SUP is undecidable can be found in [KTU90]. Moreover, it is also proven that TC is reducible to TYP. Therefore, TC and TYP are algorithmically equivalent and undecidable in System F [Wel99]. It was mentioned that Haskell s core coincides with a fragment of System F. Does that mean Haskell s type system is undecidable as well? TYP is decidable for the simply typed lambda calculus [Hin69]. The problems TC and TYP are undecidable in System F that uses types of finite rank 3 [Wel99]. Haskell s types are Rank-1 types. The Haskell type shown in (16) implies that the type variables are universally quantified like figured in (17). a b a (16) ab.a b a (17) If appears on the right-hand side of the arrow operator, it can be floated out. That means the signature shown in (18) is equivalent to the signature (17) and therefore a Rank-1 type as well. a.a ( b.b a) (18) (19) is a Rank-2 type because there are two levels of universal quantification [ran]. ( a.a a) ( b.b b) (19) Some explicit type annotations are required for Rank-N type reconstruction. Haskell s types are limited to Rank-1 types and is therefore decidable. 6 Local Type Inference In section 4, it was shown that type inference is undecidable in the presence of subtype 8 polymorphism. This section focuses on local type inference which is used in Scala and Swift. It only recovers type annotations with information from adjacent nodes in the syntax tree. Because only local information is used, long distance constraints such as unification variables are not taken into consideration [PT00]. The reason Scala does not have Hindley/Milner type inference is that it is very difficult to combine with features such as overloading (the ad-hoc variant, not type classes) [...] and subtyping. [...] I m just saying it s very difficult to make this work well in practice, where one needs to have small type expressions, and good error messages. - Martin Odersky, designer of Scala [Ode08] Scala s type inference aims to provide the same level of comfort as languages like Haskell with complete type inference. The restriction to a local context allows combining subtype polymorphism with type inference in the style of Hindley-Milner. The idea behind this is to use type annotations in some situations which are not common and rarely occur but provide type inference for desirable cases such as: Types of local bindings. Types of parameters of anonymous functions. Type arguments in applications of polymorphic functions. Bound variables of top-level functions should remain explicitly annotated because type annotation in that position serve as useful documentation which also is considered good practice in Haskell or other languages with complete type inference [Wie11]. 6.1 Local Type Argument Synthesis In this subsection, a type inference technique is introduced which deals with inferring type arguments in applications of polymorphic functions. The polymorphic identity function id has the type t t as shown in Definition 5. The goal is

9 to allow applying the identity function without the need of a type argument. It should be possible to use id(8) instead of id[int](8). The first problem is to decide where type arguments have been omitted and therefore need to be synthesized. It is easy to see that if a function is defined polymorphic and no explicit type argument is given, it has to be synthesized [PT00]. The second problem is that a number of different type arguments could be picked for a particular application. This is solved by picking the type argument that yields the best type for the result. Following example shows how the best type is chosen: Example 4 The containment Int Real is given. Both id[int](x) and id[real](x) are possible completions for id(8). In this case, Int is chosen over Real since Int is more informative. In subsection 4.2, it was shown that such a best type does not always exist. Following example shows the problem again: Example 5 The containment Int Real and a function f with type t (t t) are given. Two possible completions for f() are f[int]() and f[real](). The result types Int Int and Real Real are incompatible. Therefore, the type argument synthesis will fail. 6.2 Bidirectional Checking Bidirectional checking deals with inferring the types on bound variables in anonymous function abstractions as well as on local variable bindings. The type checker needs to operate in two distinct modes: synthesis and checking [PT00]. The typing judgment known from the simply typed lambda calculus (20) has to be replaced. Γ e : τ (20) Instead of trying to figure out the type of an expression, the idea behind bidirectional typing judgments is to use two directions of information. The first direction is synthesizing types. The other direction is checking expressions against already known types. Definition 16 (Context Γ) The context Γ represents the type declarations of the free variables (variables not bound by a lambda abstraction) used in a program. Γ (21) Γ, x : τ (22) (21) shows an empty context, while (22) is a context with the assumption that the free variable x is of type τ. The direction of the arrow shows which parts of the judgment are inputs and which are outputs. In (23), τ is unknown and has to be figured out, as in type inference (synthesis). The rule shown in (24) does only make sure that e does conform to the already known type τ (checking) [Dun12]. Γ e τ (23) Γ e τ (24) For function application a simple heuristic is used: The type of the function is always synthesized first. The information is then used to check the argument expression. Example 6 Given are the function f with type (25) and the application (26) (Int Int) Int (25) f(fun(x : Int)x) (26) Because the type of the function f is known, the type of fun(x: Int)x has to be Int Int. That means x has to be of type Int as well (Real would also be possible, but it always takes the most specific). Therefore, the type annotation can be omitted like shown in (27). f(fun(x)x) (27) 9

10 During type checking of (27), the type of f is synthesized by looking it up in the context. With this resulting information, the type checker switches into checking mode where fun(x)x is checked against the type Int Int [PT00]. 7 Conclusion The Hindley-Milner algorithm allows global type inference for functional programming and infers a general type if such a type exists. Extending Hindley-Milner with type classes, which adds adhoc polymorphism to the type system does not harm this property. However, Hindley-Milner is not decidable if subtype polymorphism is present. With subtyping values may have multiple types. Finding a most general type for a value that may have multiple types is undecidable. Moreover, the set of constraints no longer consists of simple equations. Instead, a set of inequations has to be solved. The complexity therefore increases. If higher-ranked types with a rank k>2 are available in a type system, it is also undecidable. Languages like Scala are offering type inference with a reduced scope while supporting subtyping and overloading at the same time. However, it is not guaranteed anymore that the chosen type is the best type in all cases. 10

11 References [Aar] [CW85] [Dun12] Scott Aaronson. P, np, and friends. democritus/lec6.html [accessed: May 17]. Luca Cardelli and Peter Wegner. On understanding types, data abstraction, and polymorphism. ACM Comput. Surv., 17(4): , December Joshua Dunfield. Bidirectional typechecking. November [HHPJW96] Cordelia V. Hall, Kevin Hammond, Simon L. Peyton Jones, and Philip L. Wadler. Type classes in haskell. ACM Trans. Program. Lang. Syst., 18(2): , March [Hin69] R. Hindley. The principal typescheme of an object in combinatory logic. Trans. Amer. Math. Soc, 146:29 60, December [HM95] My Hoang and John C. Mitchell. Lower bounds on type inference with subtypes. In Proceedings of the 22Nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 95, pages , New York, NY, USA, ACM. [KMNS91] Deepak Kapur, David Musser, Paliath Narendran, and Jonathan Stillman. Semi-unification. Theoretical Computer Science, 81(2): , [Kri14] Shriram Krishnamurthi. A tour of scala /Type_Inference.html [accessed: Apr 17]. [KTU90] [Lar11] [Mit91] A. J. Kfoury, J. Tiuryn, and P. Urzyczyn. The undecidability of the semiunification problem. In Proceedings of the Twenty-second Annual ACM Symposium on Theory of Computing, STOC 90, pages , New York, NY, USA, ACM. Hupel Lars. Type classes and subtyping. June John C. Mitchell. Type inference with simple subtypes. J. Funct. Program., 1(3): , [Ode08] Martin Odersky. Universal type inference is a bad thing blog/scala/universal-typeinference-is-a-bad-thing [accessed: Mar 17]. [Pie02] Benjamin C. Pierce. Types and Programming Languages. Cambridge, MA, USA, [Pot01] François Pottier. Simplifying subtyping constraints: A theory. Information and Computation, 170(2): , [psp] Pspace. org/wiki/pspace [accessed: May 17]. [PT00] Benjamin C. Pierce and David N. Turner. Local type inference. ACM Trans. Program. Lang. Syst., 22(1):1 44, January [ran] Rank-n types. haskell.org/rank-n_types [accessed: May 17]. [Sut15] Toni Suter. Polymorphism [WB89] P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad hoc. In Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming 11

12 Languages, POPL 89, pages 60 76, New York, NY, USA, ACM. [Wel99] J.B. Wells. Typability and type checking in system f are equivalent and undecidable. Annals of Pure and Applied Logic, 98(1): , [Wie11] Sebastian Wiesner. Type Inference

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

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy 06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 6: Polymorphic Type Systems 1. Polymorphic

More information

Programming Language Concepts: Lecture 19

Programming Language Concepts: Lecture 19 Programming Language Concepts: Lecture 19 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 19, 01 April 2009 Adding types

More information

Lambda Calculus and Type Inference

Lambda Calculus and Type Inference Lambda Calculus and Type Inference Björn Lisper Dept. of Computer Science and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ August 17, 2007 Lambda Calculus and Type

More information

Types and Type Inference

Types and Type Inference Types and Type Inference Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on the course homepage Outline General discussion

More information

ML Has Principal Typings

ML Has Principal Typings Electronic Notes in Theoretical Computer Science 38 (2005) URL: http://www.elsevier.nl/locate/entcs/volume38.html ML Has Principal Typings Carlos Camarão and Lucília Figueiredo Abstract Is there a type

More information

Types and Type Inference

Types and Type Inference CS 242 2012 Types and Type Inference Notes modified from John Mitchell and Kathleen Fisher Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on Web!! Outline General discussion of

More information

Constrained Types and their Expressiveness

Constrained Types and their Expressiveness Constrained Types and their Expressiveness JENS PALSBERG Massachusetts Institute of Technology and SCOTT SMITH Johns Hopkins University A constrained type consists of both a standard type and a constraint

More information

Type Systems, Type Inference, and Polymorphism

Type Systems, Type Inference, and Polymorphism 6 Type Systems, Type Inference, and Polymorphism Programming involves a wide range of computational constructs, such as data structures, functions, objects, communication channels, and threads of control.

More information

Overloading, Type Classes, and Algebraic Datatypes

Overloading, Type Classes, and Algebraic Datatypes Overloading, Type Classes, and Algebraic Datatypes Delivered by Michael Pellauer Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. September 28, 2006 September 28, 2006 http://www.csg.csail.mit.edu/6.827

More information

Derivation for the Necessity of Recursive Types and its Basic Usage

Derivation for the Necessity of Recursive Types and its Basic Usage Derivation for the Necessity of Recursive Types and its Basic Usage Philipp Koster Supervised by Prof. Dr. Farhad D. Mehta Seminar AT 2016 1 Abstract This paper derives the need for recursive types by

More information

Let Arguments Go First

Let Arguments Go First Let Arguments Go First Ningning Xie and Bruno C. d. S. Oliveira The University of Hong Kong {nnxie,bruno}@cs.hku.hk Abstract. Bi-directional type checking has proved to be an extremely useful and versatile

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

Arbitrary-rank polymorphism in (GHC) Haskell

Arbitrary-rank polymorphism in (GHC) Haskell Arbitrary-rank polymorphism in (GHC) Haskell CAS 743 Stephen Forrest 20 March 2006 Damas-Milner Type System A Damas-Milner type system (also called Hindley-Milner) is a traditional type system for functional

More information

Where is ML type inference headed?

Where is ML type inference headed? 1 Constraint solving meets local shape inference September 2005 2 Types are good A type is a concise description of the behavior of a program fragment. Typechecking provides safety or security guarantees.

More information

Type Processing by Constraint Reasoning

Type Processing by Constraint Reasoning , Martin Sulzmann, Jeremy Wazny 8th November 2006 Chameleon Chameleon is Haskell-style language treats type problems using constraints gives expressive error messages has a programmable type system Developers:

More information

Lambda Calculus and Type Inference

Lambda Calculus and Type Inference Lambda Calculus and Type Inference Björn Lisper Dept. of Computer Science and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ October 13, 2004 Lambda Calculus and Type

More information

Type Checking and Inference Are Equivalent in Lambda Calculi with Existential Types

Type Checking and Inference Are Equivalent in Lambda Calculi with Existential Types Type Checking and Inference Are Equivalent in Lambda Calculi with Existential Types Yuki Kato and Koji Nakazawa Graduate School of Informatics, Kyoto University, Kyoto 606-8501, Japan Abstract. This paper

More information

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

More information

Simple Unification-based Type Inference for GADTs

Simple Unification-based Type Inference for GADTs Simple Unification-based Type Inference for GADTs Stephanie Weirich University of Pennsylvania joint work with Dimitrios Vytiniotis, Simon Peyton Jones and Geoffrey Washburn Overview Goal: Add GADTs to

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

Type Classes and Instance Chains: A Relational Approach. John Garrett Morris

Type Classes and Instance Chains: A Relational Approach. John Garrett Morris Type Classes and Instance Chains: A Relational Approach by John Garrett Morris A dissertation submitted in partial fulfillment of the requirements for the degree of Doctor of Philosophy in Computer Science

More information

TYPE INFERENCE. François Pottier. The Programming Languages Mentoring ICFP August 30, 2015

TYPE INFERENCE. François Pottier. The Programming Languages Mentoring ICFP August 30, 2015 TYPE INFERENCE François Pottier The Programming Languages Mentoring Workshop @ ICFP August 30, 2015 What is type inference? What is the type of this OCaml function? let f verbose msg = if verbose then

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

Let Arguments Go First

Let Arguments Go First Let Arguments Go First Ningning Xie (B) and Bruno C. d. S. Oliveira The University of Hong Kong, Pokfulam, Hong Kong {nnxie,bruno}@cs.hku.hk Abstract. Bi-directional type checking has proved to be an extremely

More information

Types, Type Inference and Unification

Types, Type Inference and Unification Types, Type Inference and Unification Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Cornell CS 6110 Summary (Functional Programming) Lambda Calculus Basic ML Advanced ML: Modules, References,

More information

Type Checking and Type Inference

Type Checking and Type Inference Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled

More information

Typed Racket: Racket with Static Types

Typed Racket: Racket with Static Types Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type

More information

An Introduction to Type Inference

An Introduction to Type Inference Sebastian Zimmeck An Introduction to Type Inference Professor Alfred V. Aho - COMS E6998-2 Advanced Topics in Programming Languages and Compilers November 29, 2011 Presentation Overview 1. Introduction

More information

The Typed λ Calculus and Type Inferencing in ML

The Typed λ Calculus and Type Inferencing in ML Notes on Types S. Arun-Kumar Department of Computer Science and Engineering Indian Institute of Technology New Delhi, 110016 email: sak@cse.iitd.ernet.in April 14, 2002 2 Chapter 1 The Typed λ Calculus

More information

Polymorphism and Type Inference

Polymorphism and Type Inference Polymorphism and Type Inference Volker Stolz stolz@ifi.uio.no Department of Informatics University of Oslo Initially by Gerardo Schneider. Based on John C. Mitchell s slides (Stanford U.) Compile-time

More information

λ calculus is inconsistent

λ calculus is inconsistent Content Rough timeline COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Gerwin Klein, June Andronick, Toby Murray λ Intro & motivation, getting started [1] Foundations & Principles

More information

Type Classes in Haskell

Type Classes in Haskell Type Classes in Haskell CORDELIA V. HALL, KEVIN HAMMOND, SIMON L. PEYTON JONES, and PHILIP L. WADLER Glasgow University This article defines a set of type inference rules for resolving overloading introduced

More information

Overview. Elements of Programming Languages. Another example. Consider the humble identity function

Overview. Elements of Programming Languages. Another example. Consider the humble identity function Overview Elements of Programming Languages Lecture 8: Polymorphism and type inference James Cheney University of Edinburgh October 21, 2016 This week and next week, we will cover di erent forms of abstraction

More information

Simply-Typed Lambda Calculus

Simply-Typed Lambda Calculus #1 Simply-Typed Lambda Calculus #2 Back to School What is operational semantics? When would you use contextual (small-step) semantics? What is denotational semantics? What is axiomatic semantics? What

More information

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Haskell 98 in short! CPSC 449 Principles of Programming Languages Haskell 98 in short! n Syntax and type inferencing similar to ML! n Strongly typed! n Allows for pattern matching in definitions! n Uses lazy evaluation" F definition of infinite lists possible! n Has

More information

CSci 450: Org. of Programming Languages Overloading and Type Classes

CSci 450: Org. of Programming Languages Overloading and Type Classes CSci 450: Org. of Programming Languages Overloading and Type Classes H. Conrad Cunningham 27 October 2017 (after class) Contents 9 Overloading and Type Classes 1 9.1 Chapter Introduction.........................

More information

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter 2.1-2.7 p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer

More information

The Typed Racket Guide

The Typed Racket Guide The Typed Racket Guide Version 5.3.6 Sam Tobin-Hochstadt and Vincent St-Amour August 9, 2013 Typed Racket is a family of languages, each of which enforce

More information

Lecture 9: Typed Lambda Calculus

Lecture 9: Typed Lambda Calculus Advanced Topics in Programming Languages Spring Semester, 2012 Lecture 9: Typed Lambda Calculus May 8, 2012 Lecturer: Mooly Sagiv Scribe: Guy Golan Gueta and Shachar Itzhaky 1 Defining a Type System for

More information

Type Systems. Parametric Polymorphism. 1. Recall Let-Polymorphism. 1. Recall Let-Polymorphism. Lecture 9 Dec. 15th, 2004 Sebastian Maneth

Type Systems. Parametric Polymorphism. 1. Recall Let-Polymorphism. 1. Recall Let-Polymorphism. Lecture 9 Dec. 15th, 2004 Sebastian Maneth Today Parametric Polymorphism Type Systems Lecture 9 Dec. 15th, 2004 Sebastian Maneth 1. Recall Let-Polymorphism 4. System F-sub 5. Properties of F-sub http://lampwww.epfl.ch/teaching/typesystems/2004

More information

A system of constructor classes: overloading and implicit higher-order polymorphism

A system of constructor classes: overloading and implicit higher-order polymorphism A system of constructor classes: overloading and implicit higher-order polymorphism Mark P. Jones Yale University, Department of Computer Science, P.O. Box 2158 Yale Station, New Haven, CT 06520-2158.

More information

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Functions

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Functions 1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Functions 2 Outline Defining Functions List Comprehensions Recursion 3 Conditional Expressions As in most programming languages, functions

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

Faith, Evolution, and Programming Languages. Philip Wadler University of Edinburgh

Faith, Evolution, and Programming Languages. Philip Wadler University of Edinburgh Faith, Evolution, and Programming Languages Philip Wadler University of Edinburgh Evolution Multiculturalism Part I Church: The origins of faith Gerhard Gentzen (1909 1945) Gerhard Gentzen (1935) Natural

More information

Beluga: A Framework for Programming and Reasoning with Deductive Systems (System Description)

Beluga: A Framework for Programming and Reasoning with Deductive Systems (System Description) Beluga: A Framework for Programming and Reasoning with Deductive Systems (System Description) Brigitte Pientka and Joshua Dunfield McGill University, Montréal, Canada {bpientka,joshua}@cs.mcgill.ca Abstract.

More information

Subsumption. Principle of safe substitution

Subsumption. Principle of safe substitution Recap on Subtyping Subsumption Some types are better than others, in the sense that a value of one can always safely be used where a value of the other is expected. Which can be formalized as by introducing:

More information

Lecture #23: Conversion and Type Inference

Lecture #23: Conversion and Type Inference Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:

More information

1 Introduction. 3 Syntax

1 Introduction. 3 Syntax CS 6110 S18 Lecture 19 Typed λ-calculus 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic semantics,

More information

Simplifying and Improving Qualified Types

Simplifying and Improving Qualified Types Simplifying and Improving Qualified Types Mark P. Jones Yale University, Department of Computer Science P.O. Box 208285, New Haven, CT 06520-8285. jones-mark@cs.yale.edu Research Report YALEU/DCS/RR-1040,

More information

Course year Typeclasses and their instances

Course year Typeclasses and their instances Course year 2016-2017 Typeclasses and their instances Doaitse Swierstra and Atze Dijkstra with extra s Utrecht University September 29, 2016 1. The basics 2 Overloading versus parametric polymorphism 1

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 14 Tuesday, March 24, 2015 1 Parametric polymorphism Polymorph means many forms. Polymorphism is the ability of

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp-16/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 24! Type inference in ML / Haskell 1 Type Checking vs

More information

Polymorphism and Type Inference

Polymorphism and Type Inference Polymorphism and Type Inference Volker Stolz stolz@ifi.uio.no INF 3110-2008 Department of Informatics University of Oslo Initially by Gerardo Schneider. Based on John C. Mitchell s slides (Stanford U.)

More information

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = Hello; Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";

More information

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc. CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

More information

n n Try tutorial on front page to get started! n spring13/ n Stack Overflow!

n   n Try tutorial on front page to get started! n   spring13/ n Stack Overflow! Announcements n Rainbow grades: HW1-6, Quiz1-5, Exam1 n Still grading: HW7, Quiz6, Exam2 Intro to Haskell n HW8 due today n HW9, Haskell, out tonight, due Nov. 16 th n Individual assignment n Start early!

More information

Chapter 11 :: Functional Languages

Chapter 11 :: Functional Languages Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Copyright 2016 Elsevier 1 Chapter11_Functional_Languages_4e - Tue November 21, 2017 Historical Origins The imperative

More information

(Refer Slide Time: 01:01)

(Refer Slide Time: 01:01) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 32 Monomorphism Welcome to lecture 32. So today I will

More information

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus Types Type checking What is a type? The notion varies from language to language Consensus A set of values A set of operations on those values Classes are one instantiation of the modern notion of type

More information

More Lambda Calculus and Intro to Type Systems

More Lambda Calculus and Intro to Type Systems More Lambda Calculus and Intro to Type Systems Plan Heavy Class Participation Thus, wake up! Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems Overview Static, Dyamic

More information

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic

More information

cs242 Kathleen Fisher Reading: Concepts in Programming Languages, Chapter 6 Thanks to John Mitchell for some of these slides.

cs242 Kathleen Fisher Reading: Concepts in Programming Languages, Chapter 6 Thanks to John Mitchell for some of these slides. cs242 Kathleen Fisher Reading: Concepts in Programming Languages, Chapter 6 Thanks to John Mitchell for some of these slides. We are looking for homework graders. If you are interested, send mail to cs242cs.stanford.edu

More information

Qualified Types for MLF

Qualified Types for MLF Qualified Types for MLF Daan Leijen Andres Löh Institute of Information and Computing Sciences, Utrecht University PO Box 80089, 3508 TB Utrecht, The Netherlands {daan,andres}@csuunl Abstract MLF is a

More information

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6] 1 Lecture Overview Types 1. Type systems 2. How to think about types 3. The classification of types 4. Type equivalence structural equivalence name equivalence 5. Type compatibility 6. Type inference [Scott,

More information

Type Systems COMP 311 Rice University Houston, Texas

Type Systems COMP 311 Rice University Houston, Texas Rice University Houston, Texas 1 Type Systems for Programming Language were invented by mathematicians before electronic computers were invented. What is a type? A meaningful subset of the set of the domain

More information

Extracting the Range of cps from Affine Typing

Extracting the Range of cps from Affine Typing Extracting the Range of cps from Affine Typing Extended Abstract Josh Berdine, Peter W. O Hearn Queen Mary, University of London {berdine, ohearn}@dcs.qmul.ac.uk Hayo Thielecke The University of Birmingham

More information

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e

More information

Type Inference for ML

Type Inference for ML Type Inference for ML Tony Garnock-Jones February 29, 2012 1 Typing without quite so much typing Writing programs in System F is certainly possible, and the type system gives us nice

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

Lecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference

Lecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference Lecture #13: Type Inference and Unification Typing In the Language ML Examples from the language ML: fun map f [] = [] map f (a :: y) = (f a) :: (map f y) fun reduce f init [] = init reduce f init (a ::

More information

Typed Lambda Calculus for Syntacticians

Typed Lambda Calculus for Syntacticians Department of Linguistics Ohio State University January 12, 2012 The Two Sides of Typed Lambda Calculus A typed lambda calculus (TLC) can be viewed in two complementary ways: model-theoretically, as a

More information

CSE 3302 Programming Languages Lecture 8: Functional Programming

CSE 3302 Programming Languages Lecture 8: Functional Programming CSE 3302 Programming Languages Lecture 8: Functional Programming (based on the slides by Tim Sheard) Leonidas Fegaras University of Texas at Arlington CSE 3302 L8 Spring 2011 1 Functional Programming Languages

More information

COMP 4161 NICTA Advanced Course. Advanced Topics in Software Verification. Toby Murray, June Andronick, Gerwin Klein

COMP 4161 NICTA Advanced Course. Advanced Topics in Software Verification. Toby Murray, June Andronick, Gerwin Klein COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Toby Murray, June Andronick, Gerwin Klein λ 1 Last time... λ calculus syntax free variables, substitution β reduction α and η conversion

More information

Programming Languages

Programming Languages CSE 230: Winter 2008 Principles of Programming Languages Ocaml/HW #3 Q-A Session Push deadline = Mar 10 Session Mon 3pm? Lecture 15: Type Systems Ranjit Jhala UC San Diego Why Typed Languages? Development

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

Coq with Classes. Matthieu Sozeau. Journées PPS 2011 September 5th 2011 Trouville, France. Project Team πr 2 INRIA Paris

Coq with Classes. Matthieu Sozeau. Journées PPS 2011 September 5th 2011 Trouville, France. Project Team πr 2 INRIA Paris Coq with Classes Matthieu Sozeau Project Team πr 2 INRIA Paris Journées PPS 2011 September 5th 2011 Trouville, France This talk A quick overview of Coq Elaboration Type Classes Matthieu Sozeau - Coq with

More information

Goal. CS152: Programming Languages. Lecture 15 Parametric Polymorphism. What the Library Likes. What The Client Likes. Start simpler.

Goal. CS152: Programming Languages. Lecture 15 Parametric Polymorphism. What the Library Likes. What The Client Likes. Start simpler. Goal Understand what this interface means and why it matters: CS152: Programming Languages Lecture 15 Parametric Polymorphism Dan Grossman Spring 2011 type a mylist; val mt_list : a mylist val cons : a

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

(Refer Slide Time: 4:00)

(Refer Slide Time: 4:00) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional

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

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

Types and Programming Languages. Lecture 5. Extensions of simple types

Types and Programming Languages. Lecture 5. Extensions of simple types Types and Programming Languages Lecture 5. Extensions of simple types Xiaojuan Cai cxj@sjtu.edu.cn BASICS Lab, Shanghai Jiao Tong University Fall, 2016 Coming soon Simply typed λ-calculus has enough structure

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

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012 CS-XXX: Graduate Programming Languages Lecture 9 Simply Typed Lambda Calculus Dan Grossman 2012 Types Major new topic worthy of several lectures: Type systems Continue to use (CBV) Lambda Caluclus as our

More information

How does ML deal with +?

How does ML deal with +? How does ML deal with +? Moscow ML version 2.00 (June 2000) - op +; > val it = fn : int * int -> int - 1 + 1; > val it = 2 : int - 1.0 + 1.0; > val it = 2.0 : real - false + false;! Overloaded + cannot

More information

Advances in Programming Languages

Advances in Programming Languages T O Y H Advances in Programming Languages APL8: Multiparameter Type Classes, Constructor Classes Ian Stark School of Informatics The University of Edinburgh Thursday 4 February Semester 2 Week 4 E H U

More information

Haskell Types, Classes, and Functions, Currying, and Polymorphism

Haskell Types, Classes, and Functions, Currying, and Polymorphism 1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Types, Classes, and Functions, Currying, and Polymorphism 2 Types A type is a collection of related values. For example, Bool contains the

More information

Introduction to the Lambda Calculus

Introduction to the Lambda Calculus Introduction to the Lambda Calculus Overview: What is Computability? Church s Thesis The Lambda Calculus Scope and lexical address The Church-Rosser Property Recursion References: Daniel P. Friedman et

More information

Shared Subtypes. Subtyping Recursive Parameterized Algebraic Data Types

Shared Subtypes. Subtyping Recursive Parameterized Algebraic Data Types Shared Subtypes Subtyping Recursive Parameterized Algebraic Data Types Ki Yung Ahn kya@cs.pdx.edu Tim Sheard sheard@cs.pdx.edu Department of Computer Science Maseeh College of Engineering & Computer Science

More information

Symmetry in Type Theory

Symmetry in Type Theory Google May 29th, 2012 What is Symmetry? Definition Symmetry: Two or more things that initially look distinct, may actually be instances of a more general underlying principle. Why do we care? Simplicity.

More information

Uniqueness Typing Redefined

Uniqueness Typing Redefined Uniqueness Typing Redefined Edsko de Vries 1, Rinus Plasmeijer 2, and David Abrahamson 1 1 Trinity College Dublin, Ireland, {devriese,david}@cs.tcd.ie 2 Radboud Universiteit Nijmegen, Netherlands, rinus@cs.ru.nl

More information

Improving Scala's Safe Type-Level Abstraction

Improving Scala's Safe Type-Level Abstraction Seminar: Program Analysis and Transformation University of Applied Sciences Rapperswil Improving Scala's Safe Type-Level Abstraction Stefan Oberholzer, soberhol@hsr.ch Dez 2010 Abstract Scala cannot nd

More information

Girard s System F. Chapter System F. = λ ( f :τ 2 τ 3 ) λ (g:τ 1 τ 2 ) λ (x:τ 1 ) f (g(x)) System F

Girard s System F. Chapter System F. = λ ( f :τ 2 τ 3 ) λ (g:τ 1 τ 2 ) λ (x:τ 1 ) f (g(x)) System F 174 20.1 System F 20.1 System F Chapter 20 Girard s System F The languages we have considered so far are all monomorphic in that every expression has a unique type, given the types of its free variables,

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

Introduction to Programming, Aug-Dec 2006

Introduction to Programming, Aug-Dec 2006 Introduction to Programming, Aug-Dec 2006 Lecture 3, Friday 11 Aug 2006 Lists... We can implicitly decompose a list into its head and tail by providing a pattern with two variables to denote the two components

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

Functional Logic Programming Language Curry

Functional Logic Programming Language Curry Functional Logic Programming Language Curry Xiang Yin Department of Computer Science McMaster University November 9, 2010 Outline Functional Logic Programming Language 1 Functional Logic Programming Language

More information

Introduction. chapter Functions

Introduction. chapter Functions chapter 1 Introduction In this chapter we set the stage for the rest of the book. We start by reviewing the notion of a function, then introduce the concept of functional programming, summarise the main

More information

Polymorphism and System-F (OV)

Polymorphism and System-F (OV) Polymorphism and System-F (OV) Theorie der Programmierung SoSe 2014 FAU the occurrence of something in several different forms Polymorphism? Polymorphic systems Type systems that allow a single piece of

More information