Skip this Video
Download Presentation

Loading in 2 Seconds...

play fullscreen
1 / 23

Pizza - PowerPoint PPT Presentation

  • Uploaded on

Pizza. Java on the move?. Java super-set. Already people are adding features to Java. Pizza, Martin Odersky, Univ. of Karlsruhe Phillip Wadler, Univ of Glasgow is one that is academically interesting. Pizza. Adds to Java Parametric polymorphism

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Pizza' - nedra

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript


Java on the move?

java super set
Java super-set
  • Already people are adding features to Java.
  • Pizza,
    • Martin Odersky, Univ. of Karlsruhe
    • Phillip Wadler, Univ of Glasgow

is one that is academically interesting.

  • Adds to Java
    • Parametric polymorphism
      • superficially similar to C++ templates, but based on Hindley/Milner typing system of ML and Haskell
    • First-class functions
      • similar to the blocks of Smalltalk. Functions and procedures may be passed as parameters, stored in variables, and returned from methods.
    • Case classes (algebraic types) and pattern matching.
pizza references
Pizza references
  • Pizza is a superset of Java
  • Programs that are written in Pizza are translated into Java, thus nothing new is required of the Java Language
  • A tool, ExpressoGrinder translates Pizza into Java.
parametric polymorphism
Parametric Polymorphism
  • Parametric polymorphism means types can be parameters.
  • Parametric Polymorphism in Pizza

class Pair {

elem x; elem y;

Pair(elem x, elem y) { this.x = x;

this.y = y; }


using parametric polymorphism
Using Parametric Polymorphism

class Pair {

elem x; elem y;

Pair(elem x, elem y) { this.x = x;

this.y = y; }


Pair p = new


Pair z = new Pair(22,33);

  • A macro approach

Pair z = new Pair(22,33);

causes the translator to generate

class Pair_int {

int x, int y;

Pair_int(int x, int y) {this.x = x;

this.y = y }


Pair_int z = new Pair_int(22,33);

  • An inheritance approach

Pair z = new Pair(22,33);

causes the translator to generate

class Pair {

Object x, Object y;

Pair(Object x, Object y) {this.x = x;

this.y = y }


Pair z = new Pair(

(Object)new Integer(22),

(Object)new Integer(33));

interesting issues
Interesting issues
  • The interesting issues are with inheritance
  • In Java single inheritance by extension, multiple inheritance by interface.
  • Pizza allows a type variable to take on any class that is a subclass of a given class, or any class that implements an interface.
  • This is called “bounded polymorphism”
bounded polymorphism
Bounded polymorphism

interface Ord {

boolean less(elem o); }


class Pair> {

elem x; elem y;

Pair(elem x, elem y) {. . .}

elem min() {

if (x.less(y))return x;

else return y; }


problems with bounded polymorphism
Problems with bounded polymorphism
  • Pizza had problems with arrays and subtyping, and would have to do some extra run-time checking to pull it off.
  • Java 1.2 Reflection classes could have made this easier
  • Design of Pizza for now excludes polymorphic arrays.
higher order functions
Higher order functions
  • Treating functions as data can be convenient. Higher order functions or first class functions refer to the ability to treat functions as objects.
  • for example f().integral(2,5) is sending the function f the message “what is your integral from 2 to 5?
higher order functions oop
Higher order functions & oop
  • OO style partially supports higher order functions.
  • Functions are methods, methods are part of objects, objects are data. So functions may be treated as data. Pizza just makes it more appealing as to the syntax.
  • Functions have
    • formal parameters
    • free variables (belong to enclosing scope)
    • local variables
  • When passing functions as data, formal parameters and local variables are not a problem. But free what about free variables?
implementation of free variables
Implementation of free variables
  • At the time a function is made data the free variables should have values.
  • They could be passed
    • as references,
    • as values (immutable)

providing design alternatives. Pizza uses references.

no more higher order functions
No more higher order functions?
  • Reflection added the ability to treat a method of a class as an object, but at the time of Pizza this was not the case.
  • Inner classes in Java 1.1 diminishes the need for higher order functions in Java. Inner classes hide a class in the scope of another class supporting free variables.
  • Serialization also allows one to treat a method as data.
algebraic types in pizza
Algebraic Types in Pizza
  • Algebraic types are a language capability usually unfamiliar to imperative programmers.
  • Algebraic types may be viewed as variant records with a recursive definition.
algebraic types in pizza1
Algebraic Types in Pizza

class List {

case Nil;

case Cons(char head, List tail);

List append(List ys) {

switch(this) {

case Nil: return ys;

case Cons(Char x, List xs):

return Cons(x,xs.append(ys));




algebraic types in pizza2
Algebraic Types in Pizza

List as = Cons(‘c’,Nil);

List zs =



class List {

final int Nil_tag = 0;

final int Cons_tag = 1;

int tag;

List append(list ys) {

switch(this.tag) {

case Nil_tag: return ys;

case Cons_tag:

char x = ((Cons)this).head;

List ys = ((Cons)this).tail;

return new Cons(x,xs.append(ys));



class Nill extends List {

Nil() {this.tag = Nil_tag;}


class Cons extends List {

char head; List tail;

Cons(char head, List tail) {

this.tag = Cons_tag;

this.head = head, this.tail = tail;}


watch for parametric polymorphism templates
Watch for parametric polymorphism
  • Wadler at Bell labs has left academics. He is now working on GJ which omits algebraic types and higher order functions from Pizza, but translates to the VM.
  • This work is being done in collaboration with Sun Microsystems - which suggests its inclusion soon. I will say “I told you so”