Lecture 16: Parameterized Types and Polymorphism

Slides for APL Lecture 16: Parameterized Types and PolymorphismThis lecture presented examples of parameterized types in different programming languages: families of data types with a common structure, built by applying type constructors to on or more type parameters; as in Java or C# generics, or the algebraic datatypes of Haskell or OCaml. To work with parameterized types we use polymorphic functions — code that can work with more than one type, either in a uniform way (parametric polymorphism) or with type-specific variations (ad-hoc polymorphim). The Hindley-Milner type system, illustrated in this lecture as applied to the simply-typed lambda-calculus, expands types into type schemes that summarize multiple possible types of a polymorphic function. Hindley-Milner is distinctive in guaranteeing that any code has a principal type scheme that captures every possible type, and the efficient Algorithm W for type inference which can find (“infer”) that most general type scheme.

Link: Slides for Lecture 16


Java has subtyping: a value of one type may be used at any more general type. For example, StringObject, and every Java String is an Object. This isn’t always straightforward — consider the following code.

String[] a = { "Hello", "world" }; 
Object[] b = a;                    
b[0] = Boolean.FALSE;              
String s = a[0];                   
      1. Build a Java program around this.
      2. Compile it.
      3. Run it.
      4. What happens? Can you explain why?
      5. How might you change the Java language to prevent this?


Eloquent JavaScript: Chapter 5, Higher-Order Functions  Higher-Order Functions
Eloquent JavaScript, Chapter 5
Discussion of first-class functions in JavaScript as an example of abstraction that can make programs more straightforward to understand.
Links: Book chapter; The book
 Mozilla Developer Network: Closures in JavaScript JavaScript Guide: Closures
Mozilla Developer Network
Detailed presentation of closures in JavaScript: what they are and how you can use them. Includes many examples.
Link: JavaScript Guide
 Announcing Lambda: AWS re:Invent, Thursday 13 November 2014 Amazon Web Services: Lambda
An Event-Driven Computing Service for Dynamic Applications
Amazon announce closures-as-a-service, at 200 nanodollars per request and 17 femtodollars per byte-second. Ironically, it’s not purely functional as lambdas can only be run for their side-effects.
Links: Announcement in AWS re:Invent keynote; Product overview; Sign up now!
 GJ: A Generic Java Language Extension GJ: A Generic Java Language Extension
Phil Wadler’s page recording the development of Java generics, and their eventual inclusion into the language.
Links: GJ web page; Generics now: Java tutorial
 Andrew Kennedy on Generics for .NET  Generics for .NET
Andrew Kennedy’s page recording the development of .NET generics, and some of the work involved going from a theoretically clean and useful concept all the way to practical deployment in the .NET tools and runtime.
Links: Generics for .NET; Microsoft documentation on generics

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s