Arne Brüsch Philipp Wille. Pattern Matching Syntax

Size: px
Start display at page:

Download "Arne Brüsch Philipp Wille. Pattern Matching Syntax"

Transcription

1 Scala Enthusiasts BS Arne Brüsch Philipp Wille Pattern Matching Syntax

2 Scala Modular programming language Some used to call it objectfunctional 2

3 Scala Modular programming language Some used to call it objectfunctional Main designer and architect is Prof. Martin Odersky Scala is an academic language Works on the JVM like Java 3

4 Scala Modular programming language Some used to call it objectfunctional Main designer and architect is Prof. Martin Odersky Scala is an academic language Works on the JVM like Java Influenced by (among others): Object-oriented: Java, Smalltalk 4

5 Scala Modular programming language Some used to call it objectfunctional Main designer and architect is Prof. Martin Odersky Scala is an academic language Works on the JVM like Java Influenced by (among others): Object-oriented: Java, Smalltalk Functional: Haskell, Lisp, Scheme 5

6 Scala Modular programming language Some used to call it objectfunctional Main designer and architect is Prof. Martin Odersky Scala is an academic language Works on the JVM like Java Influenced by (among others): Object-oriented: Java, Smalltalk Functional: Haskell, Lisp, Scheme Concurrent: Erlang 6

7 Scala Modular programming language Some used to call it objectfunctional Main designer and architect is Prof. Martin Odersky Scala is an academic language Works on the JVM like Java Influenced by (among others): Object-oriented: Java, Smalltalk Functional: Haskell, Lisp, Scheme Concurrent: Erlang Commercially marketed by Odersky s Typesafe Inc. 7

8 What do we talk about? 1. Algebraic Data Types & Pattern Matching 2. Implementing Algebraic Data Types 3. Pattern Matching Syntax 4. More Scala Features 8

9 (Generalized) Algebraic Data Types (ADTs) Most functional programming languages work with ADTs ADTs are types formed by a combination of other types The most common example is the singly linked list: Nil List[A] Cons[A](head: A, tail: List[A]) 9

10 (Generalized) Algebraic Data Types (ADTs) Most functional programming languages work with ADTs ADTs are types formed by a combination of other types The most common example is the singly linked list: Nil List[A] Cons[A](head: A, tail: List[A]) Cons(1, Cons(2, Cons(3, Nil))) 10

11 Pattern Matching Check a given ADT for an exact pattern Cons(1, Cons(2, Cons(3, Nil))) 11

12 Pattern Matching Check a given ADT for an exact pattern Similar to Java s Switch/Case statement Cons(1, Cons(2, Cons(3, Nil))) match { case Cons(1, tail) => println( one ) case Cons(2, tail) => println( two ) } 12

13 Pattern Matching Most functional languages use a special notation for lists: 13

14 Pattern Matching Most functional languages use a special notation for lists: Expresses the right-associativity of singly linked lists 1 :: 2 :: 3 :: Nil match { case 1 :: tail => println( one ) case 2 :: tail => println( two ) } 14

15 List Notation ML 15

16 List Notation (cons 1 (cons 2 (cons 3 (cons 4 (cons 5 nil))))) ML 16

17 List Notation (cons 1 (cons 2 (cons 3 (cons 4 (cons 5 nil))))) ML cons (1, cons (2, cons (3, cons (4, cons (5, nil))))) 17

18 List Notation (cons 1 (cons 2 (cons 3 (cons 4 (cons 5 nil))))) ML cons (1, cons (2, cons (3, cons (4, cons (5, nil))))) Cons 1 (Cons 2 (Cons 3 (Cons 4 (Cons 5 Nil)))) 18

19 List Notation Cons(1, Cons(2, Cons(3, Cons(4, Cons(5, Nil))))) (cons 1 (cons 2 (cons 3 (cons 4 (cons 5 nil))))) ML cons (1, cons (2, cons (3, cons (4, cons (5, nil))))) Cons 1 (Cons 2 (Cons 3 (Cons 4 (Cons 5 Nil)))) 19

20 List Notation ML 20

21 List Notation ( ) ML 21

22 List Notation ( ) ML 1 :: 2 :: 3 :: 4 :: 5 :: nil 22

23 List Notation ( ) ML 1 :: 2 :: 3 :: 4 :: 5 :: nil 1 : 2 : 3 : 4 : 5 : Nil 23

24 List Notation 1 :: 2 :: 3 :: 4 :: 5 :: Nil ( ) ML 1 :: 2 :: 3 :: 4 :: 5 :: nil 1 : 2 : 3 : 4 : 5 : Nil 24

25 List Notation ML 25

26 List Notation (list ) ML 26

27 List Notation (list ) ML [1; 2; 3; 4; 5] 27

28 List Notation (list ) ML [1; 2; 3; 4; 5] [1, 2, 3, 4, 5] 28

29 List Notation List(1, 2, 3, 4, 5) (list ) ML [1; 2; 3; 4; 5] [1, 2, 3, 4, 5] 29

30 Reimplementing List Cons and Nil are Data Constructors for List 30

31 Reimplementing List Cons and Nil are Data Constructors for List Basic class structure: sealed trait List[+A] case object Nil extends List[Nothing] case class Cons[+A](head: A, tail: List[A]) extends List[A] 31

32 Reimplementing List Cons and Nil are Data Constructors for List Basic class structure: sealed trait List[+A] case object Nil extends List[Nothing] case class Cons[+A](head: A, tail: List[A]) extends List[A] This gives us the following notation: val list = Cons(1, Cons(2, Cons(3, Cons(4, Cons(5, Nil))))) 32

33 Reimplementing List sealed trait List[+A] case object Nil extends List[Nothing] case class Cons[+A](head: A, tail: List[A]) extends List[A] Pattern matching the list: list match { case Cons(h, t) =>... } 33

34 Alternate List Notation We still need two additional notations: 34

35 Alternate List Notation We still need two additional notations: val list = List(1, 2, 3, 4, 5) val list = 1 :: 2 :: 3 :: 4 :: 5 :: Nil 35

36 Alternate List Notation We still need two additional notations: val list = List(1, 2, 3, 4, 5) val list = 1 :: 2 :: 3 :: 4 :: 5 :: Nil The first notation hides the implementation details from the user The user does not need to know about Cons or Nil 36

37 Alternate List Notation object List { def apply[a](as: A*): List[A] = if(as.isempty) Nil else Cons(as.head, as.tail: _*) } 37

38 Alternate List Notation object List { def apply[a](as: A*): List[A] = if(as.isempty) Nil else Cons(as.head, as.tail: _*) } The List companion objects enables the following notations: val list = List.apply(1, 2, 3, 4, 5) 38

39 Alternate List Notation object List { def apply[a](as: A*): List[A] = if(as.isempty) Nil else Cons(as.head, as.tail: _*) } The List companion objects enables the following notations: val list = List.apply(1, 2, 3, 4, 5) val list = List(1, 2, 3, 4, 5) 39

40 Better DSL for Lists We have two ways to define Lists now: val list = Cons(1, Cons(2, Cons(3, Cons(4, Cons(5, Nil))))) val list = List(1, 2, 3, 4, 5) 40

41 Better DSL for Lists We have two ways to define Lists now: val list = Cons(1, Cons(2, Cons(3, Cons(4, Cons(5, Nil))))) val list = List(1, 2, 3, 4, 5) But how can we implement the last one? val list = 1 :: 2 :: 3 :: 4 :: 5 :: Nil 41

42 Better DSL for Lists We have two ways to define Lists now: val list = Cons(1, Cons(2, Cons(3, Cons(4, Cons(5, Nil))))) val list = List(1, 2, 3, 4, 5) But how can we implement the last one? val list = 1 :: 2 :: 3 :: 4 :: 5 :: Nil Overloaded operator 42

43 Better DSL for Lists We have two ways to define Lists now: val list = Cons(1, Cons(2, Cons(3, Cons(4, Cons(5, Nil))))) val list = List(1, 2, 3, 4, 5) But how can we implement the last one? val list = 1 :: 2 :: 3 :: 4 :: 5 :: Nil Overloaded operator Right-associative 43

44 Nicer DSL for Lists Let us first look at a similar DSL: val list = Nil.after(5).after(4).after(3).after(2).after(1) 44

45 Nicer DSL for Lists Let us first look at a similar DSL: val list = Nil.after(5).after(4).after(3).after(2).after(1) In Scala, methods with just one parameter need no brackets val list = Nil after 5 after 4 after 3 after 2 after 1 45

46 Nicer DSL for Lists Let us first look at a similar DSL: val list = Nil.after(5).after(4).after(3).after(2).after(1) In Scala, methods with just one parameter need no brackets val list = Nil after 5 after 4 after 3 after 2 after 1 But after is still left-associative 46

47 Nicer DSL for Lists In Scala, methods with just one parameter need no brackets val list = Nil after 5 after 4 after 3 after 2 after 1 47

48 Nicer DSL for Lists In Scala, methods with just one parameter need no brackets val list = Nil after 5 after 4 after 3 after 2 after 1 It can be implemented as follows: sealed trait List[+A] { def after[b >: A](head: B): List[B] = Cons(head, this) } 48

49 Nicer DSL for Lists In Scala, methods with just one parameter need no brackets val list = Nil after 5 after 4 after 3 after 2 after 1 It can be implemented as follows: sealed trait List[+A] { def after[b >: A](head: B): List[B] = Cons(head, this) } But how to define right-associative functions? 49

50 Nicer DSL for Lists Scala methods ending with a : are always right-associative 50

51 Nicer DSL for Lists Scala methods ending with a : are always right-associative sealed trait List[+A] { def after[b >: A](head: B): List[B] = Cons(head, this) def ::[B >: A](head: B): List[B] = this.after(head) } 51

52 Nicer DSL for Lists Scala methods ending with a : are always right-associative sealed trait List[+A] { def after[b >: A](head: B): List[B] = Cons(head, this) def ::[B >: A](head: B): List[B] = this.after(head) } Which gives us our last notation val list = 1 :: 2 :: 3 :: 4 :: 5 :: Nil 52

53 Pattern Matching for Lists For now, we can only pattern match lists like this: list match { case Cons(head, tail) =>... } 53

54 Pattern Matching for Lists For now, we can only pattern match lists like this: list match { case Cons(head, tail) =>... } But how can we enable this notation? val list = 1 :: 2 :: 3 :: 4 :: 5 :: Nil list match { case head :: tail =>... } 54

55 Pattern Matching for Lists For now, we can only pattern match lists like this: list match { case Cons(head, tail) =>... } But how can we enable this notation? val list = 1 :: 2 :: 3 :: 4 :: 5 :: Nil list match { case head :: tail =>... } Let s have a closer look at how pattern matching in Scala works 55

56 Example 1: Sum of a List For a start we implement the sum of a list using Pattern Matching: def sum(list: List[Int]): Int = list match { } case Cons(head, tail) => head + sum(tail) case Nil => 0 sum(1 :: 2 :: 3 :: 4 :: 5 :: Nil) 56

57 Example 1: Sum of a List For a start we implement the sum of a list using Pattern Matching: def sum(list: List[Int]): Int = list match { } case Cons(head, tail) => head + sum(tail) case Nil => sum(2 :: 3 :: 4 :: 5 :: Nil) 57

58 Example 1: Sum of a List For a start we implement the sum of a list using Pattern Matching: def sum(list: List[Int]): Int = list match { } case Cons(head, tail) => head + sum(tail) case Nil => sum(3 :: 4 :: 5 :: Nil) 58

59 Example 1: Sum of a List For a start we implement the sum of a list using Pattern Matching: def sum(list: List[Int]): Int = list match { } case Cons(head, tail) => head + sum(tail) case Nil => sum(4 :: 5 :: Nil) 59

60 Example 1: Sum of a List For a start we implement the sum of a list using Pattern Matching: def sum(list: List[Int]): Int = list match { } case Cons(head, tail) => head + sum(tail) case Nil => sum(5 :: Nil) 60

61 Example 1: Sum of a List For a start we implement the sum of a list using Pattern Matching: def sum(list: List[Int]): Int = list match { } case Cons(head, tail) => head + sum(tail) case Nil => sum(nil) 61

62 Example 1: Sum of a List For a start we implement the sum of a list using Pattern Matching: def sum(list: List[Int]): Int = list match { } case Cons(head, tail) => head + sum(tail) case Nil =>

63 Example 1: Sum of a List For a start we implement the sum of a list using Pattern Matching: def sum(list: List[Int]): Int = list match { } case Cons(head, tail) => head + sum(tail) case Nil =>

64 Example 2: Length of a List Another useful operation is the length of a given list: def length[a](l: List[A]): Int = l match { } case Nil => 0 case cons: Cons => 1 + length(cons.tail) length(1 :: 2 :: 3 :: 4 :: 5 :: Nil) 64

65 Example 2: Length of a List Another useful operation is the length of a given list: def length[a](l: List[A]): Int = l match { } case Nil => 0 case cons: Cons => 1 + length(cons.tail) 1 + length(2 :: 3 :: 4 :: 5 :: Nil) 65

66 Example 2: Length of a List Another useful operation is the length of a given list: def length[a](l: List[A]): Int = l match { } case Nil => 0 case cons: Cons => 1 + length(cons.tail) length(3 :: 4 :: 5 :: Nil) 66

67 Example 2: Length of a List Another useful operation is the length of a given list: def length[a](l: List[A]): Int = l match { } case Nil => 0 case cons: Cons => 1 + length(cons.tail) length(4 :: 5 :: Nil) 67

68 Example 2: Length of a List Another useful operation is the length of a given list: def length[a](l: List[A]): Int = l match { } case Nil => 0 case cons: Cons => 1 + length(cons.tail) length(5 :: Nil) 68

69 Example 2: Length of a List Another useful operation is the length of a given list: def length[a](l: List[A]): Int = l match { } case Nil => 0 case cons: Cons => 1 + length(cons.tail) length(nil) 69

70 Example 2: Length of a List Another useful operation is the length of a given list: def length[a](l: List[A]): Int = l match { } case Nil => 0 case cons: Cons => 1 + length(cons.tail)

71 Example 2: Length of a List Another useful operation is the length of a given list: def length[a](l: List[A]): Int = l match { } case Nil => 0 case cons: Cons => 1 + length(cons.tail) 5 71

72 Example 3: Take n first Elements Pattern Matching also allows us to select Elements from a list def take[a](n: Int, ls: List[A]): List[A] = ls match { } case Cons(hd, tl) if n > 0 => hd :: take(n-1, tl) case _ => Nil take(2, 1 :: 2 :: 3 :: 4 :: 5 :: Nil) 72

73 Example 3: Take n first Elements Pattern Matching also allows us to select Elements from a list def take[a](n: Int, ls: List[A]): List[A] = ls match { } case Cons(hd, tl) if n > 0 => hd :: take(n-1, tl) case _ => Nil 1 :: take(1, 2 :: 3 :: 4 :: 5 :: Nil) 73

74 Example 3: Take n first Elements Pattern Matching also allows us to select Elements from a list def take[a](n: Int, ls: List[A]): List[A] = ls match { } case Cons(hd, tl) if n > 0 => hd :: take(n-1, tl) case _ => Nil 1 :: 2 :: take(0, 3 :: 4 :: 5 :: Nil) 74

75 Example 3: Take n first Elements Pattern Matching also allows us to select Elements from a list def take[a](n: Int, ls: List[A]): List[A] = ls match { } case Cons(hd, tl) if n > 0 => hd :: take(n-1, tl) case _ => Nil 1 :: 2 :: Nil 75

76 Pattern Matching Syntactically Pattern Matching is a very self-contained part of the Scala programming language. This is where Pattern Matching lives: Expr ::= PostfixExpr `match' `{' CaseClauses `}' CaseClauses ::= CaseClause {CaseClause} CaseClause ::= `case' Pattern [Guard] `=>' Block A more abstract syntax e match { case p1 => b1 case pn => bn } 76

77 Guard Syntax Remember take? def take[a](n: Int, ls: List[A]): List[A] = ls match { } case Cons(hd, tl) if n > 0 => hd :: take(n - 1, tl) case _ => Nil Guarded Patterns are applied iff The Pattern matches and The Guard yields true Guard ::= `if' BExpr Expr ::= PostfixExpr `match' `{' CaseClauses `}' CaseClauses ::= CaseClause {CaseClause} CaseClause ::= `case' Pattern [Guard] `=>' Block 77

78 Pattern Syntax Pattern ::= Pattern1 { Pattern1 } Pattern1 ::= varid : TypePat _ : TypePat Pattern2 Pattern2 ::= varid Pattern3] Pattern3 Pattern3 ::= SimplePattern SimplePattern {id [nl] SimplePattern} SimplePattern ::= _ varid Literal StableId StableId ( [Patterns] ) StableId ( [Patterns, ] ] _ * ) ( [Patterns] ) XmlPattern 78

79 Typed Pattern Pattern1 ::= varid : TypePat _ : TypePat Pattern2 def length[a](l: List[A]): Int = l match { } case Nil => 0 case cons: Cons => 1 + length(cons.tail) Pattern ::= Pattern1 { Pattern1 } Pattern1 ::= varid : TypePat _ : TypePat Pattern2 Pattern2 ::= varid Pattern3] Pattern3 Pattern3 ::= SimplePattern SimplePattern {id [nl] SimplePattern} SimplePattern ::= _ varid Literal StableId StableId ( [Patterns] ) StableId ( [Patterns, ] ] _ * ) ( [Patterns] ) XmlPattern 79

80 Pattern Binders Pattern2 ::= varid Pattern3] Pattern3 def length[a](list: List[A]): Int = list match { } case Nil => 0 case Cons(head, tail) => 1 + length(c.tail) Pattern ::= Pattern1 { Pattern1 } Pattern1 ::= varid : TypePat _ : TypePat Pattern2 Pattern2 ::= varid Pattern3] Pattern3 Pattern3 ::= SimplePattern SimplePattern {id [nl] SimplePattern} SimplePattern ::= _ varid Literal StableId StableId ( [Patterns] ) StableId ( [Patterns, ] ] _ * ) ( [Patterns] ) XmlPattern 80

81 Extractor Pattern SimplePattern ::= StableId ( [Patterns] ) def take[a](n: Int, ls: List[A]): List[A] = ls match { } case Cons(head, tail) if n > 0 => { } head :: take(n - 1, tail) case _ => Nil Pattern ::= Pattern1 { Pattern1 } Pattern1 ::= varid : TypePat _ : TypePat Pattern2 Pattern2 ::= varid Pattern3] Pattern3 Pattern3 ::= SimplePattern SimplePattern {id [nl] SimplePattern} SimplePattern ::= _ varid Literal StableId StableId ( [Patterns] ) StableId ( [Patterns, ] ] _ * ) ( [Patterns] ) XmlPattern 81

82 Custom Extractors Remember? We wanted to use the following extractor syntax: val list = 1 :: 2 :: 3 :: 4 :: 5 :: Nil list match { case head :: tail =>... } 82

83 Custom Extractors Remember? We wanted to use the following extractor syntax: val list = 1 :: 2 :: 3 :: 4 :: 5 :: Nil list match { case head :: tail =>... } We can do this by defining a custom extractor! 83

84 Pattern Matching with unapply Remember? We wanted to use the following extractor syntax: list match { case head :: tail =>... } We need to define an unapply method object :: { def unapply[a](cons: Cons[A]): Option[(A, List[A])] = Some((cons.head, cons.tail)) } 84

85 A Scalable Language Scala grows with the demands of its users E.g. by defining your own DSLs 85

86 A Scalable Language Scala grows with the demands of its users E.g. by defining your own DSLs Scala supports a huge number of advanced programming constructs, like: 86

87 A Scalable Language Scala grows with the demands of its users E.g. by defining your own DSLs Scala supports a huge number of advanced programming constructs, like: Higher-order Functions 87

88 A Scalable Language Scala grows with the demands of its users E.g. by defining your own DSLs Scala supports a huge number of advanced programming constructs, like: Higher-order Functions Call-by-name Parameters 88

89 A Scalable Language Scala grows with the demands of its users E.g. by defining your own DSLs Scala supports a huge number of advanced programming constructs, like: Higher-order Functions Call-by-name Parameters Lazy Evaluation 89

90 A Scalable Language Scala grows with the demands of its users E.g. by defining your own DSLs Scala supports a huge number of advanced programming constructs, like: Higher-order Functions Call-by-name Parameters Lazy Evaluation Implicit Conversions 90

91 A Scalable Language Scala grows with the demands of its users E.g. by defining your own DSLs Scala supports a huge number of advanced programming constructs, like: Higher-order Functions Call-by-name Parameters Lazy Evaluation Implicit Conversions Actors for Parallelization 91

92 A Scalable Language Scala grows with the demands of its users E.g. by defining your own DSLs Scala supports a huge number of advanced programming constructs, like: Higher-order Functions Call-by-name Parameters Lazy Evaluation Implicit Conversions Actors for Parallelization Structural Subtyping (aka Ducktyping) 92

93 A Scalable Language Scala grows with the demands of its users E.g. by defining your own DSLs Scala supports a huge number of advanced programming constructs, like: Higher-order Functions Structural Subtyping (aka Ducktyping) Call-by-name Parameters Tailrecursion Lazy Evaluation Implicit Conversions Actors for Parallelization 93

94 A Scalable Language Scala grows with the demands of its users E.g. by defining your own DSLs Scala supports a huge number of advanced programming constructs, like: Higher-order Functions Structural Subtyping (aka Ducktyping) Call-by-name Parameters Lazy Evaluation Tailrecursion Infix-Notation Implicit Conversions Actors for Parallelization 94

95 A Scalable Language Scala grows with the demands of its users E.g. by defining your own DSLs Scala supports a huge number of advanced programming constructs, like: Higher-order Functions Structural Subtyping (aka Ducktyping) Call-by-name Parameters Lazy Evaluation Implicit Conversions Tailrecursion Infix-Notation Build-in Dependency Injection Actors for Parallelization 95

96 Scala Enthusiasts Braunschweig Since June 16 th 2014: scala-bs.de 96

97 Scala Enthusiasts Braunschweig Since June 16 th 2014: scala-bs.de We are programming enthusiasts We do not only code Scala! Ruby, Node.JS, Groovy, JavaScript, 97

98 Scala Enthusiasts Braunschweig Since June 16 th 2014: scala-bs.de We are programming enthusiasts We do not only code Scala! Ruby, Node.JS, Groovy, JavaScript, We provide a forum for speaking and learning about programming We chose Scala as a common ground 98

99 Scala Enthusiasts Braunschweig Since June 16 th 2014: scala-bs.de We are programming enthusiasts We do not only code Scala! Ruby, Node.JS, Groovy, JavaScript, We provide a forum for speaking and learning about programming We chose Scala as a common ground We meet every 2 nd month, every 2 nd Tuesday and talk about Scala, its libraries, and programming concepts in general Normally we have two 30 minutes talks and open discussions afterwards 99

CompSci 220. Programming Methodology 12: Functional Data Structures

CompSci 220. Programming Methodology 12: Functional Data Structures CompSci 220 Programming Methodology 12: Functional Data Structures A Polymorphic Higher- Order Function def findfirst[a](as: Array[A], p: A => Boolean): Int = { def loop(n: Int): Int = if (n >= as.length)

More information

Classical Themes of Computer Science

Classical Themes of Computer Science Functional Programming (Part 1/2) Bernhard K. Aichernig Institute for Software Technology Graz University of Technology Austria Winter Term 2017/18 Version: November 22, 2017 1/49 Agenda I Functional Programming?

More information

G Programming Languages - Fall 2012

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

More information

Scala : an LLVM-targeted Scala compiler

Scala : an LLVM-targeted Scala compiler Scala : an LLVM-targeted Scala compiler Da Liu, UNI: dl2997 Contents 1 Background 1 2 Introduction 1 3 Project Design 1 4 Language Prototype Features 2 4.1 Language Features........................................

More information

Scala, Your Next Programming Language

Scala, Your Next Programming Language Scala, Your Next Programming Language (or if it is good enough for Twitter, it is good enough for me) WORLDCOMP 2011 By Dr. Mark C. Lewis Trinity University Disclaimer I am writing a Scala textbook that

More information

The SCAlable LAnguage

The SCAlable LAnguage The SCAlable LAnguage The Scala Language: Object Oriented Functional Programming Gabor Szokoli Overview Introduction Everything is an Object Inheritance and mixins For comprehensions Generic Types: Covariance,

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 6a Andrew Tolmach Portland State University 1994-2016 Functional Programming An alternative paradigm to imperative programming First-class functions Emphasis

More information

An Overview of Scala. Philipp Haller, EPFL. (Lots of things taken from Martin Odersky's Scala talks)

An Overview of Scala. Philipp Haller, EPFL. (Lots of things taken from Martin Odersky's Scala talks) An Overview of Scala Philipp Haller, EPFL (Lots of things taken from Martin Odersky's Scala talks) The Scala Programming Language Unifies functional and object-oriented programming concepts Enables embedding

More information

Philipp Wille. Beyond Scala s Standard Library

Philipp Wille. Beyond Scala s Standard Library Scala Enthusiasts BS Philipp Wille Beyond Scala s Standard Library OO or Functional Programming? Martin Odersky: Systems should be composed from modules. Modules should be simple parts that can be combined

More information

Programming in Scala Second Edition

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

More information

Scala - Some essential concepts -

Scala - Some essential concepts - Scala - Some essential concepts - Marcel Lüthi Graphics and Vision Research Group Department of Mathematics and Computer Science University of Basel Programming an important activity Data preprocessing

More information

CPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia

CPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia CPL 2016, week 10 Clojure functional core Oleg Batrashev Institute of Computer Science, Tartu, Estonia April 11, 2016 Overview Today Clojure language core Next weeks Immutable data structures Clojure simple

More information

Exercise 1: Graph coloring (10 points)

Exercise 1: Graph coloring (10 points) Exercise 1: Graph coloring (10 points) Graph coloring is the problem of assigning colors to vertices in a non-directed graph, so that no two adjacent nodes have the same color. In other words, if two vertices

More information

Scala Style Guide Spring 2018

Scala Style Guide Spring 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Scala Style Guide Spring 2018 Contents 1 Introduction 1 2 Naming 1 3 Formatting 2 4 Class Declarations 3 5 Functional Paradigms 4 6 Comments

More information

Collections and Combinatorial Search

Collections and Combinatorial Search Streams Collections and Combinatorial Search We ve seen a number of immutable collections that provide powerful operations, in particular for combinatorial search. For instance, to find the second prime

More information

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

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

More information

High-level Parallel Programming: Scala on the JVM

High-level Parallel Programming: Scala on the JVM High-level Parallel Programming: Scala on the JVM Contents of Lecture 4 The Scala programming language Parallel programming using actors Jonas Skeppstedt (jonasskeppstedt.net) Lecture 4 2017 1 / 40 Purpose

More information

Who am I? Harlan Iverson. Programming enthusiast. Seeker of truth. Imperfect. I'll be wrong about some things. Please correct me if you can.

Who am I? Harlan Iverson. Programming enthusiast. Seeker of truth. Imperfect. I'll be wrong about some things. Please correct me if you can. Who am I? Harlan Iverson. Programming enthusiast. Seeker of truth. Imperfect. I'll be wrong about some things. Please correct me if you can. P.S... I hate boring presentations. Please, engage and stay

More information

Bibliography. Analyse et Conception Formelle. Lesson 5. Crash Course on Scala. Scala in a nutshell. Outline

Bibliography. Analyse et Conception Formelle. Lesson 5. Crash Course on Scala. Scala in a nutshell. Outline Bibliography Analyse et Conception Formelle Lesson 5 Crash Course on Scala Simply Scala. Onlinetutorial: http://www.simply.com/fr http://www.simply.com/ Programming in Scala, M. Odersky, L. Spoon, B. Venners.

More information

Lazy Evaluation in Scala

Lazy Evaluation in Scala Lazy Evaluation Lazy Evaluation The proposed implementation suffers from a serious potential performance problem: If tail is called several times, the corresponding stream will be recomputed each time.

More information

Practically Functional. Daniel Spiewak

Practically Functional. Daniel Spiewak Practically Functional Daniel Spiewak whoami Author of Scala for Java Refugees and other articles on Scala and FP Former editor Javalobby / EclipseZone Engaged in academic research involving Scala DSLs

More information

an overview Alceste Scalas Programming languages reading group

an overview Alceste Scalas Programming languages reading group an overview Alceste Scalas Programming languages reading group 31 October 2017 Scala: what s the hype about? Object oriented and functional programming language Runs on the JVM... interoperability with

More information

INTRODUCTION. SHORT INTRODUCTION TO SCALA INGEGNERIA DEL SOFTWARE Università degli Studi di Padova

INTRODUCTION. SHORT INTRODUCTION TO SCALA INGEGNERIA DEL SOFTWARE Università degli Studi di Padova SHORT INTRODUCTION TO SCALA INGEGNERIA DEL SOFTWARE Università degli Studi di Padova Dipartimento di Matematica Corso di Laurea in Informatica, A.A. 2014 2015 rcardin@math.unipd.it INTRODUCTION Object/functional

More information

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.) Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.) David Haraburda January 30, 2013 1 Introduction Scala is a multi-paradigm language that runs on the JVM (is totally

More information

Chapter 15. Functional Programming Languages

Chapter 15. Functional Programming Languages Chapter 15 Functional Programming Languages Copyright 2009 Addison-Wesley. All rights reserved. 1-2 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages

More information

CSE 130, Fall 2006: Final Examination

CSE 130, Fall 2006: Final Examination CSE 130, Fall 2006: Final Examination Name: ID: Instructions, etc. 1. Write your answers in the space provided. 2. Wherever it says explain, write no more than three lines as explanation. The rest will

More information

CS205: Scalable Software Systems

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

More information

CPS 506 Comparative Programming Languages. Programming Language Paradigm

CPS 506 Comparative Programming Languages. Programming Language Paradigm CPS 506 Comparative Programming Languages Functional Programming Language Paradigm Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming

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

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

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

More information

First Programming Language in CS Education The Arguments for Scala

First Programming Language in CS Education The Arguments for Scala First Programming Language in CS Education The Arguments for Scala WORLDCOMP 2011 By Dr. Mark C. Lewis Trinity University Disclaimer I am writing a Scala textbook that is under contract with CRC Press.

More information

Optimizing Higher-Order Functions in Scala

Optimizing Higher-Order Functions in Scala Optimizing Higher-Order Functions in Scala Iulian Dragos EPFL Outline A quick tour of Scala Generalities Extension through libraries Closure translation in Scala Cost Optimizations in the Scala compiler

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

Scala in Martin Odersky

Scala in Martin Odersky Scala in 2016 - Martin Odersky 2015 was on the quiet side Maturing tools: 2.11.x, IDEs, sbt Steady growth indeed.com jobs google trends In 2016, things will move again Scala 2.12 release Rethinking the

More information

Scalable Performance for Scala Message-Passing Concurrency

Scalable Performance for Scala Message-Passing Concurrency Scalable Performance for Scala Message-Passing Concurrency Andrew Bate Department of Computer Science University of Oxford cso.io Motivation Multi-core commodity hardware Non-uniform shared memory Expose

More information

n n Official Scala website n Scala API n

n   n Official Scala website n Scala API n n Quiz 8 Announcements n Rainbow grades: HW1-8, Quiz1-6, Exam1-2 n Still grading: HW9, Quiz 7 Scala n HW10 due today n HW11 out today, due Friday Fall 18 CSCI 4430, A Milanova 1 Today s Lecture Outline

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

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

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

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

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

More information

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 6 Robert Grimm, New York University 1 Review Last week Function Languages Lambda Calculus SCHEME review 2 Outline Promises, promises, promises Types,

More information

Life in a Post-Functional World

Life in a Post-Functional World Life in a Post-Functional World Definitions Functional Programming Definitions Functional Programming Programming with functions! Definitions Functional Programming Programming with functions! Functions

More information

Lecture 8: Summary of Haskell course + Type Level Programming

Lecture 8: Summary of Haskell course + Type Level Programming Lecture 8: Summary of Haskell course + Type Level Programming Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense October 31, 2017 Principles from Haskell

More information

Featherweight Scala. Week 14

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

More information

Introduction to Functional Programming and Haskell. Aden Seaman

Introduction to Functional Programming and Haskell. Aden Seaman Introduction to Functional Programming and Haskell Aden Seaman Functional Programming Functional Programming First Class Functions Expressions (No Assignment) (Ideally) No Side Effects Different Approach

More information

Using Scala for building DSL s

Using Scala for building DSL s Using Scala for building DSL s Abhijit Sharma Innovation Lab, BMC Software 1 What is a DSL? Domain Specific Language Appropriate abstraction level for domain - uses precise concepts and semantics of domain

More information

Example Scheme Function: equal

Example Scheme Function: equal ICOM 4036 Programming Languages Functional Programming Languages Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language: LISP Introduction to

More information

Functional Programming Principles in Scala. Martin Odersky

Functional Programming Principles in Scala. Martin Odersky Functional Programming Principles in Scala Martin Odersky Programming Paradigms Paradigm: In science, a paradigm describes distinct concepts or thought patterns in some scientific discipline. Main programming

More information

Linked lists and the List class

Linked lists and the List class Linked lists and the List class Cheong 1 Linked lists So far, the only container object we used was the array. An array is a single object that contains references to other objects, possibly many of them.

More information

Implementation of JVM-based languages support in IntelliJ IDEA

Implementation of JVM-based languages support in IntelliJ IDEA Implementation of JVM-based languages support in IntelliJ IDEA Ilya Sergey Dept. of Software Engineering Saint-Petersburg State University JetBrains Inc. ilya.sergey@jetbrains.com Abstract. This paper

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

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

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context Types 1 / 15 Outline Introduction Concepts and terminology The case for static typing Implementing a static type system Basic typing relations Adding context 2 / 15 Types and type errors Type: a set of

More information

CS205: Scalable Software Systems

CS205: Scalable Software Systems CS205: Scalable Software Systems Lecture 3 September 5, 2016 Lecture 3 CS205: Scalable Software Systems September 5, 2016 1 / 19 Table of contents 1 Quick Recap 2 Type of recursive solutions 3 Translating

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

Lecture 09: Introduction to Scala

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

More information

Thoughts on Assignment 4 Haskell: Flow of Control

Thoughts on Assignment 4 Haskell: Flow of Control Thoughts on Assignment 4 Haskell: Flow of Control CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 27, 2017 Glenn G. Chappell Department of Computer

More information

Haskell: From Basic to Advanced. Part 2 Type Classes, Laziness, IO, Modules

Haskell: From Basic to Advanced. Part 2 Type Classes, Laziness, IO, Modules Haskell: From Basic to Advanced Part 2 Type Classes, Laziness, IO, Modules Qualified types In the types schemes we have seen, the type variables were universally quantified, e.g. ++ :: [a] -> [a] -> [a]

More information

Company Predecessor Domain Concepts

Company Predecessor Domain Concepts 1. Performance 2. Security 3. Productivity New PL in Industry PL Company Predecessor Domain Concepts Go C Systems Channels Type Inference ML modules GC Dart Javascript Web Types Rust C++ System Browser

More information

Overview. Elements of Programming Languages. Records. Named variants. Last time: Simple data structures: pairing (product types), choice (sum types)

Overview. Elements of Programming Languages. Records. Named variants. Last time: Simple data structures: pairing (product types), choice (sum types) Overview Elements of Programming Languages Lecture 7: Records, variants, and subtyping James Cheney University of Edinburgh October 12, 2017 Last time: Simple data structures: pairing (product types),

More information

Scala. Fernando Medeiros Tomás Paim

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

More information

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1 A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner

More information

Monadologie. professional help for type anxiety. Christopher League 12 July 2010

Monadologie. professional help for type anxiety. Christopher League 12 July 2010 Monadologie professional help for type anxiety Christopher League 12 July 2010 Monadologie github.com/league/scala-type-anxiety @chrisleague league@contrapunctus.net 1996 Principles of Programming Languages

More information

University of Tartu Faculty of Mathematics and Computer Science Institute of Computer Science

University of Tartu Faculty of Mathematics and Computer Science Institute of Computer Science University of Tartu Faculty of Mathematics and Computer Science Institute of Computer Science Martin Vels Concurrent programming languages: Scala Research paper for Distributed Systems Seminar Advisor:

More information

Introduction to Functional Programming in Haskell 1 / 56

Introduction to Functional Programming in Haskell 1 / 56 Introduction to Functional Programming in Haskell 1 / 56 Outline Why learn functional programming? The essence of functional programming What is a function? Equational reasoning First-order vs. higher-order

More information

Scala Java Sparkle Monday, April 16, 2012

Scala Java Sparkle Monday, April 16, 2012 Scala Java Sparkle Scala Scala Java Scala "Which Programming Language would you use *now* on top of JVM, except Java?". The answer was surprisingly fast and very clear: - Scala. http://www.adam-bien.com/roller/abien/entry/java_net_javaone_which_programming

More information

The Seductions of Scala

The Seductions of Scala The online version contains more material. You can also find this talk and the code used for many of the examples at github.com/deanwampler/presentations/tree/master/ SeductionsOfScala. Copyright 2010-2015,

More information

Control Structures. Christopher Simpkins CS 3693, Fall Chris Simpkins (Georgia Tech) CS 3693 Scala / 1

Control Structures. Christopher Simpkins CS 3693, Fall Chris Simpkins (Georgia Tech) CS 3693 Scala / 1 Control Structures Christopher Simpkins csimpkin@spsu.edu CS 3693, Fall 2011 Chris Simpkins (Georgia Tech) CS 3693 Scala 2011-08-31 1 / 1 Control Structures Scala has only four built-in control structures:

More information

Declarative concurrency. March 3, 2014

Declarative concurrency. March 3, 2014 March 3, 2014 (DP) what is declarativeness lists, trees iterative comutation recursive computation (DC) DP and DC in Haskell and other languages 2 / 32 Some quotes What is declarativeness? ness is important

More information

Programming Systems in Artificial Intelligence Functional Programming

Programming Systems in Artificial Intelligence Functional Programming Click to add Text Programming Systems in Artificial Intelligence Functional Programming Siegfried Nijssen 8/03/16 Discover thediscover world at the Leiden world University at Leiden University Overview

More information

A Whirlwind Tour of Scala. Kevin Kilroy October 2014

A Whirlwind Tour of Scala. Kevin Kilroy October 2014 A Whirlwind Tour of Scala Kevin Kilroy October 2014 A Brief History of Scala... Created in 2001 by javac author 1995 created Pizza with 1998 created GJ with 1999 Joined EPFL Created Funnel 2001 Scala 2003

More information

Side-effect checking for Scala. Lukas Rytz, Martin Odersky, Adriaan Moors Scala Days 2011

Side-effect checking for Scala. Lukas Rytz, Martin Odersky, Adriaan Moors Scala Days 2011 Side-effect checking for Scala Lukas Rytz, Martin Odersky, Adriaan Moors Scala Days 2011 Why effect checking? We have at least one post a week where the correct answer is wholly or in part, effect system.

More information

Code Listings. Inheritance APPENDIX A. Subtype Inheritance in Java

Code Listings. Inheritance APPENDIX A. Subtype Inheritance in Java APPENDIX A For the full source, see https://github.com/tobyweston/learn-scala-java-devs. The following is a selection of examples from the text, expanded to provide fuller context for your reference. Inheritance

More information

From the λ-calculus to Functional Programming Drew McDermott Posted

From the λ-calculus to Functional Programming Drew McDermott Posted From the λ-calculus to Functional Programming Drew McDermott drew.mcdermott@yale.edu 2015-09-28 Posted 2015-10-24 The λ-calculus was intended from its inception as a model of computation. It was used by

More information

Programming Clojure, Third Edition

Programming Clojure, Third Edition Extracted from: Programming Clojure, Third Edition This PDF file contains pages extracted from Programming Clojure, Third Edition, published by the Pragmatic Bookshelf. For more information or to purchase

More information

CSCI-GA Final Exam

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

More information

Verifying pattern matching with guards in Scala

Verifying pattern matching with guards in Scala EPFL SAV 07 June 21, 2007 version 1.1 Outline Introduction Scala reasoning about pattern matching status in Scala motivation project overview general idea formalization of concepts axioms patterns miscellaneous

More information

Using Scala in CS241

Using Scala in CS241 Using Scala in CS241 Winter 2018 Contents 1 Purpose 1 2 Scala 1 3 Basic Syntax 2 4 Tuples, Arrays, Lists and Vectors in Scala 3 5 Binary output in Scala 5 6 Maps 5 7 Option types 5 8 Objects and Classes

More information

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml

COSE212: 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 information

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing What Is Computer Science? The Scientific Study of Computation CMPSCI 630: Programming Languages Introduction Spring 2009 (with thanks to Robert Harper) Expressing or Describing Automating Understanding

More information

Data Types The ML Type System

Data Types The ML Type System 7 Data Types 7.2.4 The ML Type System The following is an ML version of the tail-recursive Fibonacci function introduced Fibonacci function in ML in Section 6.6.1: EXAMPLE 7.96 1. fun fib (n) = 2. let

More information

4. Functional Programming Language-Oriented Programming

4. Functional Programming Language-Oriented Programming 4. Functional Programming Language-Oriented Programming Prof. Dr. Bernhard Humm Faculty of Computer Science Hochschule Darmstadt University of Applied Sciences 1 Retrospect: LOP the big picture What is

More information

Elements of Programming Languages Assignment 1: Introduction to Scala September 27, 2017

Elements of Programming Languages Assignment 1: Introduction to Scala September 27, 2017 Elements of Programming Languages Assignment 1: Introduction to Scala September 27, 2017 This laboratory session is intended to introduce you to the basic features of Scala, focusing primarily on the pure,

More information

Functional Programming. Another representative from the Declarative paradigm

Functional Programming. Another representative from the Declarative paradigm Functional Programming Another representative from the Declarative paradigm 1 Variables in Imperative Languages A variable in an imperative programming language can be regarded as an abstraction of the

More information

Combining Concurrency Abstractions

Combining Concurrency Abstractions Combining Concurrency Abstractions Philipp Haller Typesafe, Switzerland Correctly and Efficiently Combining Concurrency Abstractions Philipp Haller Typesafe, Switzerland The Problem Tendency to combine

More information

Scala Where It Came From Where It is Going

Scala Where It Came From Where It is Going Scala Where It Came From Where It is Going Scala Days San Francisco Martin Odersky Scala Where It Came From Scala Days San Francisco Martin Odersky Scala is going nowhere Scala is a gateway drug to Haskell

More information

Copyright 2018 Tendril, Inc. All rights reserved.

Copyright 2018 Tendril, Inc. All rights reserved. Type Parameter Power-Up! Variance, Bounds, and Inference INTRO Motivations 3 INTRO Motivations Home Energy Report Generation System Free Monad Workflow stages extending common base class Workflow actions

More information

A π-calculus Internal Domain-Specic Language for Scala

A π-calculus Internal Domain-Specic Language for Scala A π-calculus Internal Domain-Specic Language for Scala Pedro Matiello pmatiello@gmail.com Ana C. V. de Melo acvm@ime.usp.br π-calculus Syntax Prexes α ::= ȳ x Output y(x) Input τ Silent π-calculus Syntax

More information

Topic VIII. The state of the art Scala < > Scala By Example by M. Odersky. Programming Methods Laboratory, EPFL, 2008.

Topic VIII. The state of the art Scala <  > Scala By Example by M. Odersky. Programming Methods Laboratory, EPFL, 2008. References: Topic VIII The state of the art Scala < www.scala-lang.org > Scala By Example by M. Odersky. Programming Methods Laboratory, EPFL, 2008. An overview of the Scala programming language by M.

More information

Programming Languages Fall 2013

Programming Languages Fall 2013 Programming Languages Fall 2013 Lecture 2: types Prof. Liang Huang huang@qc.cs.cuny.edu Recap of Lecture 1 functional programming vs. imperative programming basic Haskell syntax function definition lazy

More information

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar Design Patterns MSc in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

More information

Dependently Typed Functional Programming with Idris

Dependently Typed Functional Programming with Idris Dependently Typed Functional Programming with Idris Lecture 2: Embedded Domain Specific Languages Edwin Brady University of St Andrews ecb10@st-andrews.ac.uk @edwinbrady Introduction In this lecture: Some

More information

Advanced Type System Features Tom Schrijvers. Leuven Haskell User Group

Advanced Type System Features Tom Schrijvers. Leuven Haskell User Group Advanced Type System Features Tom Schrijvers Leuven Haskell User Group Data Recursion Genericity Schemes Expression Problem Monads GADTs DSLs Type Type Families Classes Lists and Effect Free Other Handlers

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

Functional Programming

Functional Programming Functional Programming Final Exam Friday, December 18 2015 First Name: Last Name: Your points are precious, don t let them go to waste! Your Name Work that can t be attributed to you is lost: write your

More information

Experiences with Scala Across the College-Level Curriculum

Experiences with Scala Across the College-Level Curriculum Loyola University Chicago Loyola ecommons Emerging Technologies Laboratory Publications Computer Science: Faculty Publications and Other Works 4-21-2017 Experiences with Scala Across the College-Level

More information

Type checking by theorem proving in IDRIS

Type checking by theorem proving in IDRIS Type checking by theorem proving in IDRIS p. 1 Type checking by theorem proving in IDRIS Scottish Theorem Proving, 10th February 2012 ecb10@st-andrews.ac.uk University of St Andrews Edwin Brady Type checking

More information

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement Outline Expression Evaluation and Control Flow In Text: Chapter 6 Notation Operator evaluation order Operand evaluation order Overloaded operators Type conversions Short-circuit evaluation of conditions

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