Introducing Scala-like function types into Java-TX
|
|
- Brent Horn
- 5 years ago
- Views:
Transcription
1 Introducing Scala-like function types into Java-TX ManLang 2017 Martin Plümicke Andreas Stadelmeier
2 Overview 1 Type of lambda expressions in Java-8 2 Introducing real function types 3 Java TX The type inference algorithm 4 Conclusion and Outlook Seite 2
3 Lambda Expressions in Java 8 has no explicite type. (x) -> x; Lambda expressions get functional interfaces as compatible target types from the environment. Type of lambda expressions in Java-8 Seite 3
4 Functional Interface Interfaces with a single abstract method. E.g. interface Comparator<T> { int compare(t x, T y); } interface FileFilter { boolean accept(file x); } interface DirectoryStream.Filter<T> { boolean accept(t x); interface Runnable { void run(); } interface ActionListener { void actionperformed(...); } interface Callable<T> { T call(); } Major benefit of target typing: Possibility of implementing callback functions in existing libraries by lambda expressions. Until Java 7 that callback functions has often been implemented by anonymous inner classes. Type of lambda expressions in Java-8 Seite 4
5 Simulating function types In the package: java.util.function there are public interface Function<T,R> { R apply(t t); } public interface BiFunction<T,U,R> { R apply(t t, U u); } Type of lambda expressions in Java-8 Seite 5
6 Properties of function types 1 Subtyping 2 Less reasonable subtyping in Java 8 3 Direct application of lambda expressions Type of lambda expressions in Java-8 Seite 6
7 Subtyping (T 1,..., T N) T 0 (T 1,..., T N ) T 0, iff T i T i Type of lambda expressions in Java-8 Seite 7
8 Subtyping (T 1,..., T N) T 0 (T 1,..., T N ) T 0, iff T i T i Function<T 1, T 0 > Function<T 1, T 0>, for T i T i Type of lambda expressions in Java-8 Seite 7
9 Subtyping (T 1,..., T N) T 0 (T 1,..., T N ) T 0, iff T i T i Function<T 1, T 0 > Function<T 1, T 0>, for T i T i Example: For Integer Number Object holds: Number Number Integer Object Type of lambda expressions in Java-8 Seite 7
10 Subtyping (T 1,..., T N) T 0 (T 1,..., T N ) T 0, iff T i T i Function<T 1, T 0 > Function<T 1, T 0>, for T i T i Example: For Integer Number Object holds: but Number Number Integer Object Function<Number, Number> f_numnum =... Function<Integer, Object> f_intobj = f_numnum is wrong!, as Function<Number, Number> Function<Integer, Object> Type of lambda expressions in Java-8 Seite 7
11 Subtyping with wildcards (T 1,..., T N) T 0 (T 1,..., T N ) T 0, iff T i T i Function<T 1, T 0 > Function<T 1, T 0>, for T i T i Type of lambda expressions in Java-8 Seite 8
12 Subtyping with wildcards (T 1,..., T N) T 0 (T 1,..., T N ) T 0, iff T i T i but Function<T 1, T 0 > Function<T 1, T 0>, for T i T i Function<T 1, T 0> Function<? super T 1,? extends T 0 >, for T i T i Type of lambda expressions in Java-8 Seite 8
13 Large example for function types //A -> (B -> (((A, B) -> C) -> C))) g = x -> y -> f -> f.apply(x,y); Type of lambda expressions in Java-8 Seite 9
14 Large example for function types //A -> (B -> (((A, B) -> C) -> C))) Func.<? super A,? extends Func.<? super B,? extends Func.<? super BiFunc.<? super A,? super B,? ext. C>>,? extends C>>> g = x -> y -> f -> f.apply(x,y); Type of lambda expressions in Java-8 Seite 10
15 Large example for function types //A -> (B -> (((A, B) -> C) -> C))) Func.<? super A,? extends Func.<? super B,? extends Func.<? super BiFunc.<? super A,? super B,? ext. C>>,? extends C>>> g = x -> y -> f -> f.apply(x,y); Ugly syntax! Type of lambda expressions in Java-8 Seite 10
16 Less reasonable subtyping in Java 8 I class Sub extends Super { void m() { Function<Sub, Sub> f = x -> x; //common subtyping Function<? super Sub,? extends Super> g1; g1 = f; Super sup = g1.apply(new Sub()); } } Type of lambda expressions in Java-8 Seite 11
17 Less reasonable subtyping in Java 8 I class Sub extends Super { void m() { Function<Sub, Sub> f = x -> x; } } //exchanging the wildcard bounds Function<? extends Super,? super Sub> g2; g2 = f; //g2.apply(new Sub()); //incorrect g2.apply(null); //sup = g2.apply(null); //incorrect Object o = g2.apply(null); Type of lambda expressions in Java-8 Seite 12
18 Direct application of lambda expressions In the λ-calculus β-conversion (direct application of a lambda expression to its arguments) is possible: (λ x.e)arg = E[x/arg]. In Java 8 this lambda term would have the following form: (x -> h(x)).apply(arg); Such expressions are not permitted, as the lambda expression has no type. Type of lambda expressions in Java-8 Seite 13
19 Direct application of lambda expressions In the λ-calculus β-conversion (direct application of a lambda expression to its arguments) is possible: (λ x.e)arg = E[x/arg]. In Java 8 this lambda term would have the following form: (x -> h(x)).apply(arg); Such expressions are not permitted, as the lambda expression has no type. ((Function<T,R>)x -> h(x)).apply(arg); is ok!, as there is cast expression. Type of lambda expressions in Java-8 Seite 13
20 Currying f : T 1 (T 2 (... (T N T 0 )...)) x1 -> x2 ->...-> xn -> h(x1,...,xn)).apply(a1).apply(a2)...apply(an) Type of lambda expressions in Java-8 Seite 14
21 Currying f : T 1 T 2... T N T 0 x1 -> x2 ->...-> xn -> h(x1,...,xn)).apply(a1).apply(a2)...apply(an) Type of lambda expressions in Java-8 Seite 15
22 Currying f : T 1 T 2... T N T 0 ((Function<T1, Function<T2,... Function<TN, T0>>> ) x1 -> x2 ->...-> xn -> h(x1,...,xn)).apply(a1).apply(a2)...apply(an) Type of lambda expressions in Java-8 Seite 16
23 Summary: Solving drawbacks: Loss of function types Introducing Bi/Function Interfaces Subtyping problem Using wildcards Impossibility of direct application of lambda expressions Using type-casts All problems are solvable, but not pretty!!! Type of lambda expressions in Java-8 Seite 17
24 Summary: Solving drawbacks: Loss of function types Introducing Bi/Function Interfaces Subtyping problem Using wildcards Impossibility of direct application of lambda expressions Using type-casts All problems are solvable, but not pretty!!! Introducing real function types Type of lambda expressions in Java-8 Seite 17
25 View to Scala Scala supports variance annotations of type parameters of generic classes. In contrast to Java, variance annotations may be added when a class abstraction is defined, whereas in Java, variance annotations are given by clients when a class abstraction is used. [Scala Tutorial] Introducing real function types Seite 18
26 View to Scala Scala supports variance annotations of type parameters of generic classes. In contrast to Java, variance annotations may be added when a class abstraction is defined, whereas in Java, variance annotations are given by clients when a class abstraction is used. [Scala Tutorial] trait Function_n[-T1,..., -Tn, +R] { def apply(x1: T1,..., xn: Tn): R override def tostring = "<function>" } Introducing real function types Seite 18
27 Introduction of FunN* interface FunN*<-T1,..., -TN,+R> { R apply(t1 arg1,..., TN argn); } where FunN <T 1,..., T N,T 0 > FunN <T 1,..., T N,T 0> iff T i T i For FunN no wildcards are allowed. Introducing real function types Seite 19
28 Introduction of FunN* interface FunN*<-T1,..., -TN,+R> { R apply(t1 arg1,..., TN argn); } where FunN <T 1,..., T N,T 0 > FunN <T 1,..., T N,T 0> iff T i T i For FunN no wildcards are allowed. Lambda expressions are explicitly typed by FunN* types Introducing real function types Seite 19
29 Solved Problems Lambda expressions have types FunN types allows subtyping without wildcards Direct application of lambda expressions is possible without type-casts. Introducing real function types Seite 20
30 Preserving target typing Remember: Lambda-expressions implements callback functions. In Java 8 lambda-expressions could be compatible with a target type. Now any expression could be compatible with a target type. Example from JavaFX Button btn = new Button(); btn.settext("say Hello World "); btn.setonaction( event -> System.out.println("Hello World!")} ); Introducing real function types Seite 21
31 Preserving target typing Remember: Lambda-expressions implements callback functions. In Java 8 lambda-expressions could be compatible with a target type. Now any expression could be compatible with a target type. Example from JavaFX Fun1*<ActionEvent, String> helloworld = event -> System.out.println("Hello World!");} Button btn = new Button(); btn.settext("say Hello World "); btn.setonaction(helloworld); Introducing real function types Seite 22
32 Java-TX Core of Java 8 Real function types as presented Global type inference Java TX Seite 23
33 Java-TX Core of Java 8 Real function types as presented Global type inference Local type inference (e.g. Scala): val i = 1 It is not necessary to declare the type of i. but val fact = (x) => if (x <= 1) 1 else x * fact(x-1); //fact do not compile //the type of fact must be declared Global type inference infers also types of recursive functions. Java TX Seite 23
34 The type inference algorithm [Plümicke 14] TI: TypeAssumptions Class { (Constraints, TClass) } TI( Ass, Class( τ, extends( τ ), fdecls ) ) = let (Class( τ, extends( τ ), fdecls t ), ConS) = TYPE( Ass, Class( τ, extends( τ ), fdecls ) ) { (cs 1, σ 1 ),..., (cs n, σ n ) } = SOLVE( ConS ) in { (cs i, σ i ( Class( τ, extends( τ ), fdecls t ) )) 1 i n } Java TX Seite 24
35 The type inference algorithm [Plümicke 14] TI: TypeAssumptions Class { (Constraints, TClass) } TI( Ass, Class( τ, extends( τ ), fdecls ) ) = let (Class( τ, extends( τ ), fdecls t ), ConS) = TYPE( Ass, Class( τ, extends( τ ), fdecls ) ) { (cs 1, σ 1 ),..., (cs n, σ n ) } = SOLVE( ConS ) in { (cs i, σ i ( Class( τ, extends( τ ), fdecls t ) )) 1 i n } TYPE: Inserts type annotations, widely type variables as placeholders to any subexpression in the input class. Determines the set of type constraints (inequations of types). Java TX Seite 24
36 The type inference algorithm [Plümicke 14] TI: TypeAssumptions Class { (Constraints, TClass) } TI( Ass, Class( τ, extends( τ ), fdecls ) ) = let (Class( τ, extends( τ ), fdecls t ), ConS) = TYPE( Ass, Class( τ, extends( τ ), fdecls ) ) { (cs 1, σ 1 ),..., (cs n, σ n ) } = SOLVE( ConS ) in { (cs i, σ i ( Class( τ, extends( τ ), fdecls t ) )) 1 i n } TYPE: Inserts type annotations, widely type variables as placeholders to any subexpression in the input class. Determines the set of type constraints (inequations of types). SOLVE: Solves the constraints set by type unification [Plümicke 07] Java TX Seite 24
37 class MathStruc<A> { A model; innerop = o -> ms -> new MathStruc<A>(o.apply(this.model, ms.model)); } MathStruc(A m) { model=m; } Java TX Seite 25
38 The TYPE function inserts the following types. innerop:α = (o:β -> (ms:γ -> (new MathStruc<A>(o.apply(this.model:A, ms.model:δ):ɛ) ):MathStruc<A>):Fun1*<γ,η> ):Fun1*<β,ζ>; and determines the following set of constraints: { Fun1 <β,ζ> α, Fun1 <γ,η> ζ, MathStruc<A> η, γ MathStruc<δ>, ɛ A, β. = Fun2 <ι, κ,ɛ>, A ι, δ κ }. Java TX Seite 26
39 Reslut of SOLVE: (, [α Fun1 <Fun2 <A, δ,a>, Fun1 <MathStruc<δ>,MathStruc<A>>>, ζ Fun1 <MathStruc<δ>,MathStruc<A>>, η MathStruc<A>, γ MathStruc<δ>, ɛ A, β Fun2 <A, δ,a>]) Java TX Seite 27
40 Reslut of SOLVE: (, [α Fun1 <Fun2 <A, δ,a>, Fun1 <MathStruc<δ>,MathStruc<A>>>, ζ Fun1 <MathStruc<δ>,MathStruc<A>>, η MathStruc<A>, γ MathStruc<δ>, ɛ A, β Fun2 <A, δ,a>]) class MathStruc<A,Delta> { A model; Fun1*<Fun2*<A,Delta,A>, Fun1*<MathStruc<Delta>,MathStruc<A>> innerop = (Fun2*<A,Delta,A> o -> (MathStruc<A, Delta> ms) -> new MathStruc<A,Delta>(o.apply(this.model, ms.model)); } Java TX Seite 27
41 Demo Java TX Seite 28
42 Brian Goetz s (Oracle) arguments against real function types It would add complexity to the type system and further mix structural and nominal types (Java is almost entirely nominally typed). It would lead to a divergence of library styles some libraries would continue to use callback interfaces, while others would use structural function types. The syntax could be unwieldy, especially when checked exceptions were included. It is unlikely that there would be a runtime representation for each distinct function type, meaning developers would be further exposed to and limited by erasure. For example, it would not be possible (perhaps surprisingly) to overload methods m(t->u) and m(x->y). Java TX Seite 29
43 Brian Goetz s (Oracle) arguments against real function types It would add complexity to the type system and further mix structural and nominal types (Java is almost entirely nominally typed). It would lead to a divergence of library styles some libraries would continue to use callback interfaces, while others would use structural function types. The syntax could be unwieldy, especially when checked exceptions were included. It is unlikely that there would be a runtime representation for each distinct function type, meaning developers would be further exposed to and limited by erasure. For example, it would not be possible (perhaps surprisingly) to overload methods m(t->u) and m(x->y). Java TX Seite 30
44 Brian Goetz s (Oracle) arguments against real function types It would add complexity to the type system and further mix structural and nominal types (Java is almost entirely nominally typed). It would lead to a divergence of library styles some libraries would continue to use callback interfaces, while others would use structural function types. The syntax could be unwieldy, especially when checked exceptions were included. It is unlikely that there would be a runtime representation for each distinct function type, meaning developers would be further exposed to and limited by erasure. For example, it would not be possible (perhaps surprisingly) to overload methods m(t->u) and m(x->y). Java TX Seite 31
45 Brian Goetz s (Oracle) arguments against real function types It would add complexity to the type system and further mix structural and nominal types (Java is almost entirely nominally typed). It would lead to a divergence of library styles some libraries would continue to use callback interfaces, while others would use structural function types. The syntax could be unwieldy, especially when checked exceptions were included. It is unlikely that there would be a runtime representation for each distinct function type, meaning developers would be further exposed to and limited by erasure. For example, it would not be possible (perhaps surprisingly) to overload methods m(t->u) and m(x->y). Java TX Seite 32
46 Conclusion and Outlook Conclusion Benefits and drawbacks of functional interfaces as target types of lambda expressions in Java 8. Simulating of function types by functional interfaces Function respectively BiFunction. Introduction of Scala-like functional interfaces into Java. Preserving traget typing to implement existing callback interfaces. Type inference algorithm with Scala-like functional interfaces. Conclusion and Outlook Seite 33
47 Conclusion and Outlook Conclusion Benefits and drawbacks of functional interfaces as target types of lambda expressions in Java 8. Simulating of function types by functional interfaces Function respectively BiFunction. Introduction of Scala-like functional interfaces into Java. Preserving traget typing to implement existing callback interfaces. Type inference algorithm with Scala-like functional interfaces. Outlook Complete implementation Bytecode without type-erasures Conclusion and Outlook Seite 33
Type inference in Java 8
Type inference in Java 8 Martin Plümicke Baden-Wuerttemberg Cooperative State University Stuttgart/Horb 10. Januar 2013 Overview Introduction The function TYPE The sub-function TYPEExpr The sub-function
More informationAusblick auf Java 8. Martin Plümicke. 25. Mai Baden-Wuerttemberg Cooperative State University Stuttgart/Horb
Ausblick auf Java 8 Martin Plümicke Baden-Wuerttemberg Cooperative State University Stuttgart/Horb 25. Mai 2012 Overview Introduction Introduction Closures Java s motivation λ expressions Functional interfaces
More informationLecture #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 informationConversion 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 informationLecture #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 informationCSCI-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 informationINF 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 informationJava SE 8: Lambda Expressions And The Stream API
Java SE 8: Lambda Expressions And The Stream API Simon Ritter Head of Java Technology Evangelism Java Product Management Java Day Tokyo 2015 April 8, 2015 Safe Harbor Statement The following is intended
More informationCS558 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 informationResolving of Intersection Types in Java
Resolving of Intersection Types in Java Martin Plümicke University of Cooperative Education Stuttgart Department of Information Technology Florianstraße 15, D 72160 Horb m.pluemicke@ba-horb.de Abstract.
More informationCS558 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 informationProgramming Languages Assignment #7
Programming Languages Assignment #7 December 2, 2007 1 Introduction This assignment has 20 points total. In this assignment, you will write a type-checker for the PolyMinML language (a language that is
More informationG 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 informationINF 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 informationType 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 informationExercise 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 informationHarvard 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 informationLAMBDA EXPRESSIONS AND STREAMS API
Java 8 LAMBDA EXPRESSIONS AND STREAMS API An Introduction Methods As Data 2 @FunctionalInterface public interface Runnable { public abstract void run(); public interface ActionListener extends EventListener
More informationThe 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 informationFontys Hogeschool voor Techniek en Logistiek. March 13, 2018
Java 8 s and Java 8 Fontys Hogeschool voor Techniek en Logistiek March 13, 2018 and? /FHTenL s and Java 8 March 13, 2018 1/34 talk The other anonymous and? Java 8 and? /FHTenL s and Java 8 March 13, 2018
More informationLambda expressions in Java: a compiler writer's perspective. Maurizio Cimadamore Type-system engineer, Oracle Corporation
Lambda expressions in Java: a compiler writer's perspective Maurizio Cimadamore Type-system engineer, Oracle Corporation The following is intended to outline our general product direction. It is intended
More informationNew Features in Java 8
New Features in Java 8 Lambda expressions Functional interfaces Streaming support for Collections Lambda expressions Are a block of java code with parameters Can be assigned to variables Can be executed
More informationProgramming 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 informationCS558 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 informationGoal. 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 informationLambda 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 informationObject-oriented programming in...
Programming Languages Week 12 Object-oriented programming in... College of Information Science and Engineering Ritsumeikan University plan this week intro to Java advantages and disadvantages language
More informationClosures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming
Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Summary 1. Predictive Parsing 2. Large Step Operational Semantics (Natural) 3. Small Step Operational Semantics
More informationLambdas in Java 8. Start programming in a more functional style
Lambdas in Java 8 Start programming in a more functional style Background Who am I? Tobias Coetzee I m a Technical Lead at BBD I present the Java Expert Level Certifications at BBD (EJB, JPA, etc.) I m
More informationCS 4110 Programming Languages & Logics. Lecture 27 Recursive Types
CS 4110 Programming Languages & Logics Lecture 27 Recursive Types 4 November 2016 Announcements 2 My office hours are at the normal time today but canceled on Monday Guest lecture by Seung Hee Han on Monday
More informationLecture 16: Static Semantics Overview 1
Lecture 16: Static Semantics Overview 1 Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces trees Detects & eliminates ill-formed parse trees Static semantic analysis
More informationCS 4110 Programming Languages & Logics. Lecture 28 Recursive Types
CS 4110 Programming Languages & Logics Lecture 28 Recursive Types 7 November 2014 Announcements 2 Foster office hours 11-12pm Guest lecture by Fran on Monday Recursive Types 3 Many languages support recursive
More informationHOL DEFINING HIGHER ORDER LOGIC LAST TIME ON HOL CONTENT. Slide 3. Slide 1. Slide 4. Slide 2 WHAT IS HIGHER ORDER LOGIC? 2 LAST TIME ON HOL 1
LAST TIME ON HOL Proof rules for propositional and predicate logic Safe and unsafe rules NICTA Advanced Course Forward Proof Slide 1 Theorem Proving Principles, Techniques, Applications Slide 3 The Epsilon
More informationOverview of Java 8 Functional Interfaces
Overview of Java 8 Functional Interfaces Douglas C. Schmidt d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/~schmidt Professor of Computer Science Institute for Software Integrated Systems Vanderbilt University
More informationIntermediate Code Generation Part II
Intermediate Code Generation Part II Chapter 6: Type checking, Control Flow Slides adapted from : Robert van Engelen, Florida State University Static versus Dynamic Checking Static checking: the compiler
More informationCSE 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 informationStatic Checking and Type Systems
1 Static Checking and Type Systems Chapter 6 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2009 2 The Structure of our Compiler Revisited Character stream Lexical
More informationlearning objectives learn about variables, their types and their values learn about different number representations
programming basics learning objectives algorithms your software system software hardware learn about variables, their types and their values learn about different number representations learn boolean algebra
More informationHigher-Order Intensional Type Analysis. Stephanie Weirich Cornell University
Higher-Order Intensional Type Analysis Stephanie Weirich Cornell University Reflection A style of programming that supports the run-time discovery of program information. What does this code do? How is
More informationTypes 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 informationCS-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 informationStatic 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 informationCSE-321 Programming Languages 2010 Final
Name: Hemos ID: CSE-321 Programming Languages 2010 Final Prob 1 Prob 2 Prob 3 Prob 4 Prob 5 Prob 6 Total Score Max 18 28 16 12 36 40 150 There are six problems on 16 pages, including two work sheets, in
More informationIf a program is well-typed, then a type can be inferred. For example, consider the program
CS 6110 S18 Lecture 24 Type Inference and Unification 1 Type Inference Type inference refers to the process of determining the appropriate types for expressions based on how they are used. For example,
More informationType 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 informationCS 11 java track: lecture 1
CS 11 java track: lecture 1 Administrivia need a CS cluster account http://www.cs.caltech.edu/ cgi-bin/sysadmin/account_request.cgi need to know UNIX www.its.caltech.edu/its/facilities/labsclusters/ unix/unixtutorial.shtml
More informationBinghamton University. CS-140 Fall Functional Java
Functional Java 1 First Class Data We have learned how to manipulate data with programs We can pass data to methods via arguments We can return data from methods via return types We can encapsulate data
More informationCSCI-GA Scripting Languages
CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation
More informationArray. Prepared By - Rifat Shahriyar
Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types
More informationProgramming Languages Lecture 14: Sum, Product, Recursive Types
CSE 230: Winter 200 Principles of Programming Languages Lecture 4: Sum, Product, Recursive Types The end is nigh HW 3 No HW 4 (= Final) Project (Meeting + Talk) Ranjit Jhala UC San Diego Recap Goal: Relate
More informationJava: introduction to object-oriented features
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer
More informationAdvances in Programming Languages
Advances in Programming Languages Lecture 4: Higher Polymorphism Ian Stark School of Informatics The University of Edinburgh Friday 30 September 2016 Semester 1 Week 2 https://blog.inf.ed.ac.uk/apl16 Topic:
More informationUnifying Nominal and Structural Ad-Hoc Polymorphism
Unifying Nominal and Structural Ad-Hoc Polymorphism Stephanie Weirich University of Pennsylvania Joint work with Geoff Washburn Ad-hoc polymorphism Define operations that can be used for many types of
More informationThe Hack programming language:
The Hack programming language: Types for PHP Andrew Kennedy Facebook Facebook s PHP Codebase 350,000 files >10,000,000 LoC (www.facebook.com & internally) 1000s of commits per day, 2 releases per day Anecdotally,
More informationCS 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 informationProgramming 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 information1 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 informationStatic Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1
Static Semantics Lecture 15 (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1 Current Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing
More informationLAMBDA EXPRESSIONS. Summer 2018
LAMBDA EXPRESSIONS Summer 2018 LAMBDA EXPRESSIONS USES Introduced in Java SE 8, lambda expressions are a way to create single-method classes in your code in a much less cumbersome manner than anonymous
More informationAxiomatic Rules. Lecture 18: Axiomatic Semantics & Type Safety. Correctness using Axioms & Rules. Axiomatic Rules. Steps in Proof
Lecture 18: Axiomatic Semantics & Type Safety CSCI 131 Fall, 2011 Kim Bruce Axiomatic Rules Assignment axiom: - {P [expression / id]} id := expression {P} - Ex: {a+47 > 0} x := a+47 {x > 0} - {x > 1} x
More informationCollections Algorithms
Collections Algorithms 1 / 11 The Collections Framework A collection is an object that represents a group of objects. The collections framework allows different kinds of collections to be dealt with in
More informationTYPE 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 informationFree your Lambdas Java SE 8
Free your Lambdas Java SE 8 Agenda Tutorial session: we will start at the very beginning! and explore how to build functional interfaces to design new APIs This is about lambdas and functional interfaces
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationGenerics: Past, Present and Future
Generics: Past, Present and Future @richardwarburto insightfullogic.com @raouluk cambridgecoding.com binarysearch(list
More informationCS 6110 S14 Lecture 1 Introduction 24 January 2014
CS 6110 S14 Lecture 1 Introduction 24 January 2014 1 Introduction What is a program? Is it just something that tells the computer what to do? Yes, but there is much more to it than that. The basic expressions
More informationCopyright 2012, Oracle and/or its affiliates. All rights reserved.
1 Lambda Expressions in Java Simon Ritter Java Technology Evangelist Twitter: @speakjava With thanks to Brian Goetz 2 The following is intended to outline our general product direction. It is intended
More informationObjects, 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 informationCOMP6700/2140 Generic Methods
COMP6700/2140 Generic Methods Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU March 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Generic Methods March 2017
More informationCompilation 2012 Static Type Checking
Compilation 2012 Jan Midtgaard Michael I. Schwartzbach Aarhus University The Type Checker The type checker has several tasks: determine the types of all expressions check that values and variables are
More informationA New Formalization of Subtyping to Match Subclasses to Subtypes
A New Formalization of Subtyping to Match Subclasses to Subtypes Hyunik Na and Sukyoung Ryu Programming Language Research Group KAIST June 6, 2014 Hyunik Na and Sukyoung Ryu A New Formalization of Subtyping
More informationHarvard 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 informationFeatherweight Java. Lecture 12 CS 565 3/18/08
Featherweight Java Lecture 12 CS 565 3/18/08 Objects vs Functions Will start exploring an object model that treats objects and classes as primitives Avoids some of the complexities faced when encoding
More informationValues (a.k.a. data) representation. Advanced Compiler Construction Michel Schinz
Values (a.k.a. data) representation Advanced Compiler Construction Michel Schinz 2016 03 10 The problem Values representation A compiler must have a way of representing the values of the source language
More informationValues (a.k.a. data) representation. The problem. Values representation. The problem. Advanced Compiler Construction Michel Schinz
Values (a.k.a. data) representation The problem Advanced Compiler Construction Michel Schinz 2016 03 10 1 2 Values representation The problem A compiler must have a way of representing the values of the
More informationSubtyping 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 informationDRAWING ENVIRONMENT DIAGRAMS
DRAWING ENVIRONMENT DIAGRAMS COMPUTER SCIENCE 61A September 10, 2012 0.1 Background A frame is a location where variable bindings are stored A binding is a connection between a name and a value. The name
More informationCS152: 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<Insert Picture Here> Project Lambda: To Multicore and Beyond
Project Lambda: To Multicore and Beyond Brian Goetz Java Language Architect, Oracle Corporation The following is intended to outline our general product direction. It is intended
More informationl e t print_name r = p r i n t _ e n d l i n e ( Name : ^ r. name)
Chapter 8 Row polymorphism Consider the following code: type name_home = {name : s t r i n g ; home : s t r i n g } type name_mobile = {name : s t r i n g ; mobile : s t r i n g } l e t jane = {name =
More informationAtelier 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 informationTypes-2. Polymorphism
Types-2 Polymorphism Type reconstruction (type inference) for a simple PL Typing functions Coercion, conversion, reconstruction Rich area of programming language research as people try to provide safety
More informationOverview. 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 informationCSC 172 Data Structures and Algorithms. Lecture 3 Spring 2018 TuTh 3:25 pm 4:40 pm
CSC 172 Data Structures and Algorithms Lecture 3 Spring 2018 TuTh 3:25 pm 4:40 pm Agenda Administrative aspects Java Generics Chapter 1 ADMINISTRATIVE ASPECTS Workshops Workshops Workshops begin on this
More informationLecture 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 informationCompilers 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 informationSection 2.2 Your First Program in Java: Printing a Line of Text
Chapter 2 Introduction to Java Applications Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two
More informationCS205: 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 informationTypes, Expressions, and States
8/27: solved Types, Expressions, and States CS 536: Science of Programming, Fall 2018 A. Why? Expressions represent values in programming languages, relative to a state. Types describe common properties
More informationContinuations and Continuation-Passing Style
Continuations and Continuation-Passing Style Lecture 4 CS 390 1/16/08 Goal Weʼre interested in understanding how to represent the state of a co-routine Insight into what a thread really means How fundamental
More informationCOSE212: Programming Languages. Lecture 3 Functional Programming in OCaml
COSE212: Programming Languages Lecture 3 Functional Programming in OCaml Hakjoo Oh 2017 Fall Hakjoo Oh COSE212 2017 Fall, Lecture 3 September 18, 2017 1 / 44 Why learn ML? Learning ML is a good way of
More informationLecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University
Lecture 2 COMP1406/1006 (the Java course) Fall 2013 M. Jason Hinek Carleton University today s agenda a quick look back (last Thursday) assignment 0 is posted and is due this Friday at 2pm Java compiling
More informationCSCI B522 Lecture 11 Naming and Scope 8 Oct, 2009
CSCI B522 Lecture 11 Naming and Scope 8 Oct, 2009 Lecture notes for CS 6110 (Spring 09) taught by Andrew Myers at Cornell; edited by Amal Ahmed, Fall 09. 1 Static vs. dynamic scoping The scope of a variable
More informationC# Adds Useful Features
C# Adds Useful Features Events and delegates are included to handle asynchronous actions (like keyboard or mouse actions). Properties allow user-defined read and write actions for fields. You can add get
More informationQuestions? Static Semantics. Static Semantics. Static Semantics. Next week on Wednesday (5 th of October) no
Questions? First exercise is online: http://www.win.tue.nl/~mvdbrand/courses/glt/1112/ Deadline 17 th of October Next week on Wednesday (5 th of October) no lectures!!! Primitive types Primitive value
More informationGenerics method and class definitions which involve type parameters.
Contents Topic 07 - Generic Programming I. Introduction Example 1 User defined Generic Method: printtwice(t x) Example 2 User defined Generic Class: Pair Example 3 using java.util.arraylist II. Type
More information17 From Delegation to Inheritance
Object-Oriented Design Lecture 17 CS 3500 Spring 2011 (Pucella) Friday, Mar 18, 2011 17 From Delegation to Inheritance Last time, we saw how to reuse code from the implementation of Point in CPoint via
More informationLambda Notes for CS 2102
Lambda Notes for CS 2102 Remember filter and map from CS1101/1102: ;; filter: (X- >Boolean) ListOfX - > ListOfX the function argument (X- > Boolean) is a predicate. Filter applies the predicate to each
More informationCS4215 Programming Language Implementation. Martin Henz
CS4215 Programming Language Implementation Martin Henz Thursday 26 January, 2012 2 Chapter 4 The Language simpl In this chapter, we are exting the language epl in order to provide a more powerful programming
More informationCSE 505, Fall 2008, Final Examination 11 December Please do not turn the page until everyone is ready.
CSE 505, Fall 2008, Final Examination 11 December 2008 Please do not turn the page until everyone is ready. Rules: The exam is closed-book, closed-note, except for one side of one 8.5x11in piece of paper.
More information