SlideShare a Scribd company logo
Scala
What’s New, What’s Next

   Scala eXchange opening address
           June 15th, 2011

           Martin Odersky
         Typesafe and EPFL
Trajectory
10 years ago
   –  The plan: Unify functional and object-oriented programming in a
      practical language.
8 years ago
   –  First Scala release (experimental, students as subjects)
5 years ago
   –  Open source system forms around Scala
3 years ago
   –  Industrial adoption starts, spreads rapidly through internet companies
      and financial sector.
1 year ago
   –  First Scala Days conference demonstrates strength of community,
      demand for industrial support.
#1 Concern: Concurrency and Parallelism

  Two motivations:

  •    Make use of multicore/GPU processing power (scale-up)
  •    Distribute computations over many nodes (scala-out)

  Two approaches:

  •    Explicit: Programmer defines and manages processes
  •    Implicit: Control of parallelism given to system

      Implicit is simpler,
      But explicit is often needed when nodes and connections can
       fail.



                                                                     3
Scala’s Toolbox



                  4
Different Tools for Different Purposes

Implicit:

                          Parallel Collections
     Collections
                          Distributed Collections

     Parallel DSLs

Explicit:

     Actors
     Software transactional memory                  Akka
     Futures



                                                           5
Scala Collections:
  Building Interesting Things in Space
•  De-emphasize destructive         scala> val ys = List(1, 2, 3)
                                    ys: List[Int] = List(1, 2, 3)
   updates
                                    scala> val xs: Seq[Int] = ys
•  Focus on transformers that       xs: Seq[Int] = List(1, 2, 3)
   map collections to collections   scala> xs map (_ + 1)
                                    res0: Seq[Int] = List(2, 3, 4)
•  Have a complete range of
                                    scala> ys map (_ + 1)
   persistent collections           res1: List[Int] = List(2, 3, 4)




                                                                      6
Some General Scala Collections




            Constructed automatically using decodify.

                                                        7
An Example
•    Task: Phone keys have mnemonics assigned to them.

           val	
  mnemonics	
  =	
  Map(	
  
           	
  	
  	
  	
  	
  	
  '2'	
  -­‐>	
  "ABC",	
  '3'	
  -­‐>	
  "DEF",	
  '4'	
  -­‐>	
  "GHI",	
  '5'	
  -­‐>	
  "JKL",	
  	
  
           	
  	
  	
  	
  	
  	
  '6'	
  -­‐>	
  "MNO",	
  '7'	
  -­‐>	
  "PQRS",	
  '8'	
  -­‐>	
  "TUV",	
  '9'	
  -­‐>	
  "WXYZ")	
  

•    Assume you are given a dictionary dict as a list of words. Design a class
     Coder with a method translate such that

           new	
  Coder(dict).translate(phoneNumber)	
  	
  

     produces all phrases of words in dict that can serve as mnemonics for the
     phone number.

•    Example: The phone number “7225276257” should have the mnemonic
           Scala	
  rocks	
  
     as one element of the list of solution phrases.


                                                                                                                                              2-8
Program Example: Phone Mnemonics

•  This example was taken from:
    Lutz Prechelt: An Empirical Comparison of Seven Programming
       Languages. IEEE Computer 33(10): 23-29 (2000)

•  Tested with Tcl, Python, Perl, Rexx, Java, C++, C

•  Code size medians:
    –  100 loc for scripting languages
    –  200-300 loc for the others




                                                                  2-9
Outline of Class Coder	
  

class	
  Coder(words:	
  List[String])	
  {	
  

	
  	
  private	
  val	
  mnemonics	
  =	
  Map(	
  
	
  	
  	
  	
  	
  	
  '2'	
  -­‐>	
  "ABC",	
  '3'	
  -­‐>	
  "DEF",	
  '4'	
  -­‐>	
  "GHI",	
  '5'	
  -­‐>	
  "JKL",	
  	
  
	
  	
  	
  	
  	
  	
  '6'	
  -­‐>	
  "MNO",	
  '7'	
  -­‐>	
  "PQRS",	
  '8'	
  -­‐>	
  "TUV",	
  '9'	
  -­‐>	
  "WXYZ")	
  

	
  	
  /**	
  Invert	
  the	
  mnemonics	
  map	
  to	
  give	
  a	
  map	
  from	
  chars	
  'A'	
  ...	
  'Z'	
  to	
  '2'	
  ...	
  '9'	
  */	
  
	
  	
  private	
  val	
  charCode:	
  Map[Char,	
  Char]	
  =	
  ??	
  

	
  	
  /**	
  Maps	
  a	
  word	
  to	
  the	
  digit	
  string	
  it	
  can	
  represent,	
  e.g.	
  “Java”	
  -­‐>	
  “5282”	
  */	
  
	
  	
  private	
  def	
  wordCode(word:	
  String):	
  String	
  =	
  ??	
  

	
  	
  /**	
  A	
  map	
  from	
  digit	
  strings	
  to	
  the	
  words	
  that	
  represent	
  them,	
  	
  
	
  	
  	
  	
  *	
  e,g.	
  “5282”	
  -­‐>	
  Set(“Java”,	
  “Kata”,	
  “Lava”,	
  ...)	
  */	
  
	
  	
  private	
  val	
  wordsForNum:	
  Map[String,	
  Set[String]]	
  =	
  ??	
  

	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  ??	
  

	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}




                                                                                                                                                        10
Class Coder	
  (1)	
  
class	
  Coder(words:	
  List[String])	
  {	
  

	
  	
  private	
  val	
  mnemonics	
  =	
  Map(	
  
	
  	
  	
  	
  	
  	
  '2'	
  -­‐>	
  "ABC",	
  '3'	
  -­‐>	
  "DEF",	
  '4'	
  -­‐>	
  "GHI",	
  '5'	
  -­‐>	
  "JKL",	
  	
  
	
  	
  	
  	
  	
  	
  '6'	
  -­‐>	
  "MNO",	
  '7'	
  -­‐>	
  "PQRS",	
  '8'	
  -­‐>	
  "TUV",	
  '9'	
  -­‐>	
  "WXYZ")	
  

	
  	
  /**	
  Invert	
  the	
  mnemonics	
  map	
  to	
  give	
  a	
  map	
  from	
  chars	
  'A'	
  ...	
  'Z'	
  to	
  '2'	
  ...	
  '9'	
  */	
  
	
  	
  private	
  val	
  charCode:	
  Map[Char,	
  Char]	
  =	
  	
  	
  


	
  	
  /**	
  Maps	
  a	
  word	
  to	
  the	
  digit	
  string	
  it	
  can	
  represent	
  */	
  
	
  	
  private	
  def	
  wordCode(word:	
  String):	
  String	
  =	
  ??	
  

	
  	
  /**	
  A	
  map	
  from	
  digit	
  strings	
  to	
  the	
  words	
  that	
  represent	
  them	
  */	
  
	
  	
  private	
  val	
  wordsForNum:	
  Map[String,	
  List[String]]	
  =	
  ??	
  

	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  ??	
  

	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}




                                                                                                                                                        11
Class Coder	
  (1)	
  
class	
  Coder(words:	
  List[String])	
  {	
  

	
  	
  private	
  val	
  mnemonics	
  =	
  Map(	
  
	
  	
  	
  	
  	
  	
  '2'	
  -­‐>	
  "ABC",	
  '3'	
  -­‐>	
  "DEF",	
  '4'	
  -­‐>	
  "GHI",	
  '5'	
  -­‐>	
  "JKL",	
  	
  
	
  	
  	
  	
  	
  	
  '6'	
  -­‐>	
  "MNO",	
  '7'	
  -­‐>	
  "PQRS",	
  '8'	
  -­‐>	
  "TUV",	
  '9'	
  -­‐>	
  "WXYZ")	
  

	
  	
  /**	
  Invert	
  the	
  mnemonics	
  map	
  to	
  give	
  a	
  map	
  from	
  chars	
  'A'	
  ...	
  'Z'	
  to	
  '2'	
  ...	
  '9'	
  */	
  
	
  	
  private	
  val	
  charCode:	
  Map[Char,	
  Char]	
  =	
  	
  	
  
        for	
  ((digit,	
  str)	
  <-­‐	
  mnemonics;	
  ltr	
  <-­‐	
  str)	
  yield	
  (ltr	
  -­‐>	
  digit)	
  

	
  	
  /**	
  Maps	
  a	
  word	
  to	
  the	
  digit	
  string	
  it	
  can	
  represent	
  */	
  
	
  	
  private	
  def	
  wordCode(word:	
  String):	
  String	
  =	
  ??	
  

	
  	
  /**	
  A	
  map	
  from	
  digit	
  strings	
  to	
  the	
  words	
  that	
  represent	
  them	
  */	
  
	
  	
  private	
  val	
  wordsForNum:	
  Map[String,	
  List[String]]	
  =	
  ??	
  

	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  ??	
  

	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}




                                                                                                                                                        12
Class Coder	
  (2)	
  
class	
  Coder(words:	
  List[String])	
  {	
  

	
  	
  private	
  val	
  mnemonics	
  =	
  Map(	
  
	
  	
  	
  	
  	
  	
  '2'	
  -­‐>	
  "ABC",	
  '3'	
  -­‐>	
  "DEF",	
  '4'	
  -­‐>	
  "GHI",	
  '5'	
  -­‐>	
  "JKL",	
  	
  
	
  	
  	
  	
  	
  	
  '6'	
  -­‐>	
  "MNO",	
  '7'	
  -­‐>	
  "PQRS",	
  '8'	
  -­‐>	
  "TUV",	
  '9'	
  -­‐>	
  "WXYZ")	
  

	
  	
  /**	
  Invert	
  the	
  mnemonics	
  map	
  to	
  give	
  a	
  map	
  from	
  chars	
  'A'	
  ...	
  'Z'	
  to	
  '2'	
  ...	
  '9'	
  */	
  
	
  	
  private	
  val	
  charCode:	
  Map[Char,	
  Char]	
  =	
  	
  	
  
         for	
  ((digit,	
  str)	
  <-­‐	
  m;	
  letter	
  <-­‐	
  str)	
  yield	
  (letter	
  -­‐>	
  digit)	
  

	
  	
  /**	
  Maps	
  a	
  word	
  to	
  the	
  digit	
  string	
  it	
  can	
  represent,	
  e.g.	
  “Java”	
  -­‐>	
  “5282”	
  */	
  
	
  	
  private	
  def	
  wordCode(word:	
  String):	
  String	
  =	
  



	
  	
  /**	
  A	
  map	
  from	
  digit	
  strings	
  to	
  the	
  words	
  that	
  represent	
  them	
  */	
  
	
  	
  private	
  val	
  wordsForNum:	
  Map[String,	
  Set[String]]	
  =	
  ??	
  

	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  ??	
  

	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}




                                                                                                                                                        13
Class Coder	
  (2)	
  
class	
  Coder(words:	
  List[String])	
  {	
  

	
  	
  private	
  val	
  mnemonics	
  =	
  Map(	
  
	
  	
  	
  	
  	
  	
  '2'	
  -­‐>	
  "ABC",	
  '3'	
  -­‐>	
  "DEF",	
  '4'	
  -­‐>	
  "GHI",	
  '5'	
  -­‐>	
  "JKL",	
  	
  
	
  	
  	
  	
  	
  	
  '6'	
  -­‐>	
  "MNO",	
  '7'	
  -­‐>	
  "PQRS",	
  '8'	
  -­‐>	
  "TUV",	
  '9'	
  -­‐>	
  "WXYZ")	
  

	
  	
  /**	
  Invert	
  the	
  mnemonics	
  map	
  to	
  give	
  a	
  map	
  from	
  chars	
  'A'	
  ...	
  'Z'	
  to	
  '2'	
  ...	
  '9'	
  */	
  
	
  	
  private	
  val	
  charCode:	
  Map[Char,	
  Char]	
  =	
  	
  	
  
         for	
  ((digit,	
  str)	
  <-­‐	
  m;	
  letter	
  <-­‐	
  str)	
  yield	
  (letter	
  -­‐>	
  digit)	
  

	
  	
  /**	
  Maps	
  a	
  word	
  to	
  the	
  digit	
  string	
  it	
  can	
  represent,	
  e.g.	
  “Java”	
  -­‐>	
  “5282”	
  */	
  
	
  	
  private	
  def	
  wordCode(word:	
  String):	
  String	
  =	
  
	
  	
  	
  word.toUpperCase	
  map	
  charCode	
  

	
  	
  /**	
  A	
  map	
  from	
  digit	
  strings	
  to	
  the	
  words	
  that	
  represent	
  them	
  */	
  
	
  	
  private	
  val	
  wordsForNum:	
  Map[String,	
  Set[String]]	
  =	
  ??	
  

	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  ??	
  

	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}




                                                                                                                                                        14
Class Coder	
  (3)	
  
class	
  Coder(words:	
  List[String])	
  {	
  

	
  	
  private	
  val	
  mnemonics	
  =	
  Map(	
  
	
  	
  	
  	
  	
  	
  '2'	
  -­‐>	
  "ABC",	
  '3'	
  -­‐>	
  "DEF",	
  '4'	
  -­‐>	
  "GHI",	
  '5'	
  -­‐>	
  "JKL",	
  	
  
	
  	
  	
  	
  	
  	
  '6'	
  -­‐>	
  "MNO",	
  '7'	
  -­‐>	
  "PQRS",	
  '8'	
  -­‐>	
  "TUV",	
  '9'	
  -­‐>	
  "WXYZ")	
  

	
  	
  /**	
  Invert	
  the	
  mnemonics	
  map	
  to	
  give	
  a	
  map	
  from	
  chars	
  'A'	
  ...	
  'Z'	
  to	
  '2'	
  ...	
  '9'	
  */	
  
	
  	
  private	
  val	
  charCode:	
  Map[Char,	
  Char]	
  =	
  	
  	
  
          for	
  ((digit,	
  str)	
  <-­‐	
  m;	
  letter	
  <-­‐	
  str)	
  yield	
  (letter	
  -­‐>	
  digit)	
  

	
  	
  /**	
  Maps	
  a	
  word	
  to	
  the	
  digit	
  string	
  it	
  can	
  represent	
  */	
  
	
  	
  private	
  def	
  wordCode(word:	
  String):	
  String	
  =	
  
	
  	
  	
  	
  word.toUpperCase	
  map	
  charCode	
  

	
  	
  /**	
  A	
  map	
  from	
  digit	
  strings	
  to	
  the	
  words	
  that	
  represent	
  them,	
  	
  
	
  	
  	
  	
  *	
  e,g.	
  “5282”	
  -­‐>	
  Set(“Java”,	
  “Kata”,	
  “Lava”,	
  ...)	
  */	
  
	
  	
  private	
  val	
  wordsForNum:	
  Map[String,	
  List[String]]	
  =	
  	
  




	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  ??	
  

	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}

                                                                                                                                                        15
Class Coder	
  (3)	
  
class	
  Coder(words:	
  List[String])	
  {	
  

	
  	
  private	
  val	
  mnemonics	
  =	
  Map(	
  
	
  	
  	
  	
  	
  	
  '2'	
  -­‐>	
  "ABC",	
  '3'	
  -­‐>	
  "DEF",	
  '4'	
  -­‐>	
  "GHI",	
  '5'	
  -­‐>	
  "JKL",	
  	
  
	
  	
  	
  	
  	
  	
  '6'	
  -­‐>	
  "MNO",	
  '7'	
  -­‐>	
  "PQRS",	
  '8'	
  -­‐>	
  "TUV",	
  '9'	
  -­‐>	
  "WXYZ")	
  

	
  	
  /**	
  Invert	
  the	
  mnemonics	
  map	
  to	
  give	
  a	
  map	
  from	
  chars	
  'A'	
  ...	
  'Z'	
  to	
  '2'	
  ...	
  '9'	
  */	
  
	
  	
  private	
  val	
  charCode:	
  Map[Char,	
  Char]	
  =	
  	
  	
  
          for	
  ((digit,	
  str)	
  <-­‐	
  m;	
  letter	
  <-­‐	
  str)	
  yield	
  (letter	
  -­‐>	
  digit)	
  

	
  	
  /**	
  Maps	
  a	
  word	
  to	
  the	
  digit	
  string	
  it	
  can	
  represent	
  */	
  
	
  	
  private	
  def	
  wordCode(word:	
  String):	
  String	
  =	
  
	
  	
  	
  	
  word.toUpperCase	
  map	
  charCode	
  

	
  	
  /**	
  A	
  map	
  from	
  digit	
  strings	
  to	
  the	
  words	
  that	
  represent	
  them,	
  	
  
	
  	
  	
  	
  *	
  e,g.	
  “5282”	
  -­‐>	
  Set(“Java”,	
  “Kata”,	
  “Lava”,	
  ...)	
  */	
  
	
  	
  private	
  val	
  wordsForNum:	
  Map[String,	
  List[String]]	
  =	
  	
  

     	
  	
  (words	
  groupBy	
  wordCode)	
  withDefaultValue	
  List()	
  

	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  ??	
  

	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}

                                                                                                                                                        16
Class Coder	
  (4)	
  
class	
  Coder(words:	
  List[String])	
  {	
  ...	
  

	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  	
  




	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}




                                                                                                                                    17
Class Coder	
  (4)	
  
class	
  Coder(words:	
  List[String])	
  {	
  ...	
  

	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  	
  
        	
  if	
  (number.isEmpty)	
  
	
  	
  	
  	
  	
  	
  Set(List())	
  




	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}




                                                                                                                                    18
Class Coder	
  (4)	
  
class	
  Coder(words:	
  List[String])	
  {	
  ...	
  

	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  	
  
        	
  if	
  (number.isEmpty)	
  
	
  	
  	
  	
  	
  	
  Set(List())	
  
	
  	
  	
  	
  else	
  {	
  
        	
  	
  	
  	
  for	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  splitPoint	
  <-­‐	
  1	
  to	
  number.length	
  




	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}




                                                                                                                                    19
Class Coder	
  (4)	
  
class	
  Coder(words:	
  List[String])	
  {	
  ...	
  

	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  	
  
        	
  if	
  (number.isEmpty)	
  
	
  	
  	
  	
  	
  	
  Set(List())	
  
	
  	
  	
  	
  else	
  {	
  
	
  	
  	
  	
  	
  	
  for	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  splitPoint	
  <-­‐	
  1	
  to	
  number.length	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  word	
  <-­‐	
  wordsForNum(number	
  take	
  splitPoint)	
  




	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}




                                                                                                                                    20
Class Coder	
  (4)	
  
class	
  Coder(words:	
  List[String])	
  {	
  ...	
  

	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  	
  
        	
  if	
  (number.isEmpty)	
  
	
  	
  	
  	
  	
  	
  Set(List())	
  
	
  	
  	
  	
  else	
  {	
  
        	
  	
  	
  	
  for	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  splitPoint	
  <-­‐	
  1	
  to	
  number.length	
  
        	
                   	
  word	
  <-­‐	
  wordsForNum(number	
  take	
  splitPoint)	
  
	
  	
  	
  	
  	
  	
  	
  	
  rest	
  <-­‐	
  encode(number	
  drop	
  splitPoint)	
  
	
  	
  	
  	
  	
  	
  }	
  yield	
  word	
  ::	
  rest	
  
	
  	
  	
  	
  }.toSet	
  
	
  	
  /**	
  Maps	
  a	
  number	
  to	
  a	
  list	
  of	
  all	
  word	
  phrases	
  that	
  can	
  represent	
  it	
  */	
  
	
  	
  def	
  translate(number:	
  String):	
  Set[String]	
  =	
  encode(number)	
  map	
  (_	
  mkString	
  "	
  ")	
  
}




                                                                                                                                    21
In Summary
•  In the original experiment:
   –  Scripting language programs were shorter and often even faster than
      Java/C/C++ because their developers tended to use standard
      collections.

•  In Scala’s solution:
   –  Obtained a further 5x reduction in size because of the systematic use of
      functional collections.

•  Scala’s collection’s are also easily upgradable to parallel.


Think collection transformers, not CRUD!



                                                                                 22
A Solution in Java
By Josh Bloch, author of Java collections	
  




                                                23
Going Parallel

•  In Scala 2.9, collections support parallel operations.
•  Two new methods:
   c.par	
      returns parallel version of collection c	
  	
  
   c.seq       	
  returns sequential version of collection c	
  

•  The right tool for addressing the PPP (popular parallel
   programming) challenge.
•  I expect this to be the cornerstone for making use of
   multicores for the rest of us.


                                                                    24
a parallel collection
                                                 Parallel Coder	
  
 class	
  Coder(words:	
  ParVector[String])	
  {	
  

 	
  	
  private	
  val	
  mnemonics	
  =	
  Map(	
  
 	
  	
  	
  	
  	
  	
  '2'	
  -­‐>	
  "ABC",	
  '3'	
  -­‐>	
  "DEF",	
  '4'	
  -­‐>	
  "GHI",	
  '5'	
  -­‐>	
  "JKL",	
  	
  
 	
  	
  	
  	
  	
  	
  '6'	
  -­‐>	
  "MNO",	
  '7'	
  -­‐>	
  "PQRS",	
  '8'	
  -­‐>	
  "TUV",	
  '9'	
  -­‐>	
  "WXYZ")	
  

 	
  	
  /**	
  Invert	
  the	
  mnemonics	
  map	
  to	
  give	
  a	
  map	
  from	
  chars	
  'A'	
  ...	
  'Z'	
  to	
  '2'	
  ...	
  '9'	
  */	
  
 	
  	
  private	
  val	
  charCode:	
  Map[Char,	
  Char]	
  =	
  	
  	
  
           for	
  ((digit,	
  str)	
  <-­‐	
  m;	
  letter	
  <-­‐	
  str)	
  yield	
  (letter	
  -­‐>	
  digit)	
  

 	
  	
  /**	
  Maps	
  a	
  word	
  to	
  the	
  digit	
  string	
  it	
  can	
  represent	
  */	
  
 	
  	
  private	
  def	
  wordCode(word:	
  String):	
  String	
  =	
  word.toUpperCase	
  map	
  charCode	
  

 	
  	
  /**	
  A	
  map	
  from	
  digit	
  strings	
  to	
  the	
  words	
  that	
  represent	
  them	
  */	
  
 	
  	
  private	
  val	
  wordsForNum:	
  Map[String,	
  List[String]]	
  =	
  words	
  groupBy	
  wordCode	
  

 	
  	
  /**	
  Return	
  all	
  ways	
  to	
  encode	
  a	
  number	
  as	
  a	
  list	
  of	
  words	
  */	
  
 	
  	
  def	
  encode(number:	
  String):	
  Set[List[String]]	
  =	
  	
  
             	
  if	
  (number.isEmpty)	
  Set(List())	
  
 	
  	
  	
  	
  else	
  {	
  
                                                                                                          mapping sequential
 	
  	
  	
  	
  	
  	
  for	
  {	
                                                                       collection to parallel
 	
  	
  	
  	
  	
  	
  	
  	
  splitPoint	
  <-­‐	
  (1	
  to	
  number.length).par	
  
 	
  	
  	
  	
  	
  	
  	
  	
  word	
  <-­‐	
  wordsForNum(number	
  take	
  splitPoint)	
  
 	
  	
  	
  	
  	
  	
  	
  	
  rest	
  <-­‐	
  encode(number	
  drop	
  splitPoint)	
  
 	
  	
  	
  	
  	
  	
  }	
  yield	
  word	
  ::	
  rest	
  
                 }.toSet


                                                                                                                                                         25
Parallel Collections
•  Split work by number of Processors
•  Each Thread has a work queue that is split
   exponentially. Largest on end of queue
•  Granularity balance against scheduling overhead
•  On completion threads “work steals” from end of other
   thread queues




                                                           26
General Collection Hierarchy


                GenTraversable

                  GenIterable
Traversable
                    GenSeq
 Iterable                        ParIterable

   Seq                             ParSeq




                                            27
Going Distributed
•  Can we get the power of parallel collections to work on
   10’000s of computers?
•  Hot technologies: MapReduce (Google’s and Hadoop)
•  But not everything is easy to fit into that mold
•  Sometimes 100’s of map-reduce steps are needed.
•  Distributed collections retain most operations, provide a
   powerful frontend for MapReduce computations.
•  Scala’s uniform collection model is designed to also
   accommodate parallel and distributed.



                                                               28
The Future
Scala’s persistent collections are
•  easy to use:   few steps to do the job
•  concise:       one word replaces a whole loop
•  safe:          type checker is really good at catching errors
•  fast:          collection ops are tuned, can be parallelized
•  scalable:      one vocabulary to work on all kinds of
                    collections: sequential, parallel, or distributed.

I see them play a rapidly increasing role in software development.



                                                                         29
Akka: Event-driven Middleware in Scala
•  Unified programming model for:
    –  scaling up to many cores
    –  scaling out to many nodes
    –  fault-tolerance
•  Actors:
    –  lightweight (run millions on a single node)
    –  send and receive messages async
    –  location transparent
•  Transparent and adaptive:
    –  load-balancing and routing
    –  replication and fail-over
    –  elasticity: grow/shrink dynamically
•  Decouples app logic from low-level
   mechanisms


                                                     30
Akka vs scala.actors

Akka:
  + Best performance
  + Scalable to clusters and clouds
  + Best safety through encapsulation


Scala Actors:
  + Simple to get started
  + Good integration with threads
  + Blocking as well as non-blocking receives
  − Erlang-inherited mailbox model can lead to inefficient code


Over the next releases we plan to merge the two libraries.
                                                                  31
Other New Developments
•  Scala-based reflection
•  Type Dynamic
•  Effects in an optional pluggable type system (?)

•  Libraries:
    –  I/O, including event-based
    –  STM
    –  Reactive programming, GUI


•  Most effort will go in tools
    –    Eclipse IDE
    –    REPL
    –    SBT (simple build tool)
    –    Type debugger

                                                      32
Going further

But how do we keep a bunch of Fermi’s happy?
   –  How to find and deal with 10000+ threads in an
      application?
  –  Parallel collections and actors are necessary but not
     sufficient for this.
Our bet for the mid term future: parallel embedded DSLs.
   –  Find parallelism in domains: physics simulation, machine
      learning, statistics, ...
Joint work with Kunle Olukuton, Pat Hanrahan @ Stanford.
EPFL side funded by ERC.


                                                                 33
Scientific              Virtual                  Personal                     Data
 Applications
                  Engineering              Worlds                   Robotics                 informatics


  Domain
                                    Physics                             Probabilistic             Machine
  Specific       Rendering                           Scripting                                    Learning
 Languages                           (Liszt)                             (RandomT)                (OptiML)

                                        Domain Embedding Language (Scala)
                       Polymorphic Embedding              Staging            Static Domain Specific Opt.
     DSL
Infrastructure
                                     Parallel Runtime (Delite, Sequoia, GRAMPS)
                  Dynamic Domain Spec. Opt.        Task & Data Parallelism        Locality Aware Scheduling



                                               Hardware Architecture
Heterogeneous
                   OOO Cores          SIMD Cores           Threaded Cores               Specialized Cores
  Hardware
                     Programmable         Scalable        Isolation &        On-chip        Pervasive
                      Hierarchies        Coherence         Atomicity         Networks       Monitoring
                                                                                                              34
Example: Liszt - A DSL for Physics
                 Simulation

                                                            Combustion

                                    Turbulence



                                                      Fuel injection
                                         Transition                      Thermal
•  Mesh-based
•  Numeric Simulation
•  Huge domains                     Turbulence


   –  millions of cells
•  Example: Unstructured Reynolds-averaged Navier
   Stokes (RANS) solver




                                                                                   35
Liszt as Virtualized Scala
val // calculating scalar convection (Liszt)

val Flux = new Field[Cell,Float]                              AST
val Phi = new Field[Cell,Float]
val cell_volume = new Field[Cell,Float]
val deltat = .001
...
untilconverged {
  for(f <- interior_faces) {
    val flux = calc_flux(f)
    Flux(inside(f)) -= flux
    Flux(outside(f)) += flux
  }
  for(f <- inlet_faces) {                                       Optimisers Generators
    Flux(outside(f)) += calc_boundary_flux(f)
  }                                                                       …
  for(c <- cells(mesh)) {
    Phi(c) += deltat * Flux(c) /cell_volume                            Schedulers
    (c)
  }                                                                        …
  for(f <- faces(mesh))
    Flux(f) = 0.f                                                       Hardware
}

                                                DSL Library         GPU, Multi-Core, etc

                                                                                           36
Other Developments
DelayedInit
Dynamic          Scala 2.9 also introduces two new “magic” traits:
Tools
                     DelayedInit      and
Reflection
                     Dynamic!
STM
@specialized
                 A lot work has been done on the tools side:
Slick
                    Scala IDE for Eclipse 2.0,
scala.reflect
                    SBT 0.10,
scala.react
                    enhanced REPL,
Scala.NET
                    Migration Manager Diagnostics (MiMaLib)
Scala.IO (?)
Effects (?)
Javascript (?)



                                                                     37
Planned Work
DelayedInit
Dynamic
                 Over the next releases, we plan to introduce:
Tools
                    •  Scala STM, a standard STM API,
Reflection
                    •  Enhanced support for @specialized,
STM
                    •  Slick, A common framework for connecting with
@specialized
                       databases and distributed collections.
Slick
                    •  Scala.reflect, a Scala-centric reflection library.
scala.reflect
                    •  Scala.react, a reactive programming framework.
scala.react
                    •  An updated Scala.NET
Scala.NET
                 We are also exploring:
Scala.IO (?)
                    •  Adding Scala.IO to the standard distibution
Effects (?)
                    •  An effect system for Scala
Javascript (?)
                    •  A Scala to Javascript translator

                                                                            38
DelayedInit and App
DelayedInit
Dynamic          Trait Application is convenient, but has hidden problems:
Tools
                   object First extends Application {	
Reflection           println("hi there!)	
STM                }

@specialized
Slick            Body is executed as part of the object initializer.
scala.reflect    main method inherited from Application is empty.

scala.react      Body is neither optimized nor threading-friendly.
Scala.NET
Scala.IO (?)     Solution: Replace Application with App.
Effects (?)
Javascript (?)



                                                                             39
DelayedInit and App
DelayedInit
Dynamic          Trait App solves these problems:
Tools
                   object First extends App {	
Reflection           println("hi there!)	
STM                }

@specialized
Slick            Body is now stored in a buffer, executed by main method.
scala.reflect    Here’s an outline of this trait.
scala.react
Scala.NET          trait App extends DelayedInit {	
Scala.IO (?)         def main(args: Array[String]) =	
                       for (code <- inits) code()	
Effects (?)        }
Javascript (?)



                                                                            40
Conclusion
Scala has the right “genes” to scale into parallel +
   distributed computing:
•  Strong, practical foundation: JVM
•  Functional programming reduces liabilities
•  Library-centric approach makes for building tailored
   solutions.
Makes it possible to write:
•  High-level, easy to use libraries (e.g., collections)
•  Safer concurrency concepts (e.g., actors)
•  Parallel DSLs (e.g., EPFL/Stanford project)


                                                           41
Thank You

scala-lang.org




                         typesafe.com

                                        42

More Related Content

What's hot

Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are Databases
Martin Odersky
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
Martin Odersky
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
Tim Underwood
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
Scala Italy
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
pramode_ce
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
Hiroshi Ono
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Rahul Jain
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Mohammad Hossein Rimaz
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
Jonas Bonér
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Saleem Ansari
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scala
akuklev
 
Functional Programming In Practice
Functional Programming In PracticeFunctional Programming In Practice
Functional Programming In Practice
Michiel Borkent
 
scala
scalascala
scala
Pranav E K
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
Derek Chen-Becker
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
Patrick Nicolas
 

What's hot (17)

Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are Databases
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scala
 
Functional Programming In Practice
Functional Programming In PracticeFunctional Programming In Practice
Functional Programming In Practice
 
scala
scalascala
scala
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
 

Similar to Scala eXchange opening

Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
Baishampayan Ghose
 
Class 31: Deanonymizing
Class 31: DeanonymizingClass 31: Deanonymizing
Class 31: Deanonymizing
David Evans
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
Michiel Borkent
 
Morel, a data-parallel programming language
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming language
Julian Hyde
 
From Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn IntroductionFrom Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn Introduction
elliando dias
 
Scoobi - Scala for Startups
Scoobi - Scala for StartupsScoobi - Scala for Startups
Scoobi - Scala for Startups
bmlever
 
The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)
jaxLondonConference
 
Seminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mmeSeminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mme
Vyacheslav Arbuzov
 
Introducing redis
Introducing redisIntroducing redis
Introducing redis
Nuno Caneco
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
Stuart Roebuck
 
Gpu programming with java
Gpu programming with javaGpu programming with java
Gpu programming with java
Gary Sieling
 
Unit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxUnit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
Anastasios Skarlatidis
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
osfameron
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
Guy Lebanon
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
Eric Pederson
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
Eelco Visser
 
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf
Advanced-Concepts-Team
 
5_IntermediateCodeGeneration.ppt
5_IntermediateCodeGeneration.ppt5_IntermediateCodeGeneration.ppt
5_IntermediateCodeGeneration.ppt
HARIHARANMRA20110030
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Anne Nicolas
 

Similar to Scala eXchange opening (20)

Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Class 31: Deanonymizing
Class 31: DeanonymizingClass 31: Deanonymizing
Class 31: Deanonymizing
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
 
Morel, a data-parallel programming language
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming language
 
From Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn IntroductionFrom Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn Introduction
 
Scoobi - Scala for Startups
Scoobi - Scala for StartupsScoobi - Scala for Startups
Scoobi - Scala for Startups
 
The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)
 
Seminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mmeSeminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mme
 
Introducing redis
Introducing redisIntroducing redis
Introducing redis
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Gpu programming with java
Gpu programming with javaGpu programming with java
Gpu programming with java
 
Unit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxUnit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptx
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
 
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf
 
5_IntermediateCodeGeneration.ppt
5_IntermediateCodeGeneration.ppt5_IntermediateCodeGeneration.ppt
5_IntermediateCodeGeneration.ppt
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
 

More from Martin Odersky

scalar.pdf
scalar.pdfscalar.pdf
scalar.pdf
Martin Odersky
 
Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and Effects
Martin Odersky
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
Martin Odersky
 
Simplicitly
SimplicitlySimplicitly
Simplicitly
Martin Odersky
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 
From DOT to Dotty
From DOT to DottyFrom DOT to Dotty
From DOT to Dotty
Martin Odersky
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in Dotty
Martin Odersky
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
Martin Odersky
 
Flatmap
FlatmapFlatmap

More from Martin Odersky (10)

scalar.pdf
scalar.pdfscalar.pdf
scalar.pdf
 
Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and Effects
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Simplicitly
SimplicitlySimplicitly
Simplicitly
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
From DOT to Dotty
From DOT to DottyFrom DOT to Dotty
From DOT to Dotty
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in Dotty
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
Flatmap
FlatmapFlatmap
Flatmap
 

Recently uploaded

JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 

Recently uploaded (20)

JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 

Scala eXchange opening

  • 1. Scala What’s New, What’s Next Scala eXchange opening address June 15th, 2011 Martin Odersky Typesafe and EPFL
  • 2. Trajectory 10 years ago –  The plan: Unify functional and object-oriented programming in a practical language. 8 years ago –  First Scala release (experimental, students as subjects) 5 years ago –  Open source system forms around Scala 3 years ago –  Industrial adoption starts, spreads rapidly through internet companies and financial sector. 1 year ago –  First Scala Days conference demonstrates strength of community, demand for industrial support.
  • 3. #1 Concern: Concurrency and Parallelism Two motivations: •  Make use of multicore/GPU processing power (scale-up) •  Distribute computations over many nodes (scala-out) Two approaches: •  Explicit: Programmer defines and manages processes •  Implicit: Control of parallelism given to system   Implicit is simpler,   But explicit is often needed when nodes and connections can fail. 3
  • 5. Different Tools for Different Purposes Implicit: Parallel Collections Collections Distributed Collections Parallel DSLs Explicit: Actors Software transactional memory Akka Futures 5
  • 6. Scala Collections: Building Interesting Things in Space •  De-emphasize destructive scala> val ys = List(1, 2, 3) ys: List[Int] = List(1, 2, 3) updates scala> val xs: Seq[Int] = ys •  Focus on transformers that xs: Seq[Int] = List(1, 2, 3) map collections to collections scala> xs map (_ + 1) res0: Seq[Int] = List(2, 3, 4) •  Have a complete range of scala> ys map (_ + 1) persistent collections res1: List[Int] = List(2, 3, 4) 6
  • 7. Some General Scala Collections Constructed automatically using decodify. 7
  • 8. An Example •  Task: Phone keys have mnemonics assigned to them. val  mnemonics  =  Map(              '2'  -­‐>  "ABC",  '3'  -­‐>  "DEF",  '4'  -­‐>  "GHI",  '5'  -­‐>  "JKL",                '6'  -­‐>  "MNO",  '7'  -­‐>  "PQRS",  '8'  -­‐>  "TUV",  '9'  -­‐>  "WXYZ")   •  Assume you are given a dictionary dict as a list of words. Design a class Coder with a method translate such that new  Coder(dict).translate(phoneNumber)     produces all phrases of words in dict that can serve as mnemonics for the phone number. •  Example: The phone number “7225276257” should have the mnemonic Scala  rocks   as one element of the list of solution phrases. 2-8
  • 9. Program Example: Phone Mnemonics •  This example was taken from: Lutz Prechelt: An Empirical Comparison of Seven Programming Languages. IEEE Computer 33(10): 23-29 (2000) •  Tested with Tcl, Python, Perl, Rexx, Java, C++, C •  Code size medians: –  100 loc for scripting languages –  200-300 loc for the others 2-9
  • 10. Outline of Class Coder   class  Coder(words:  List[String])  {      private  val  mnemonics  =  Map(              '2'  -­‐>  "ABC",  '3'  -­‐>  "DEF",  '4'  -­‐>  "GHI",  '5'  -­‐>  "JKL",                '6'  -­‐>  "MNO",  '7'  -­‐>  "PQRS",  '8'  -­‐>  "TUV",  '9'  -­‐>  "WXYZ")      /**  Invert  the  mnemonics  map  to  give  a  map  from  chars  'A'  ...  'Z'  to  '2'  ...  '9'  */      private  val  charCode:  Map[Char,  Char]  =  ??      /**  Maps  a  word  to  the  digit  string  it  can  represent,  e.g.  “Java”  -­‐>  “5282”  */      private  def  wordCode(word:  String):  String  =  ??      /**  A  map  from  digit  strings  to  the  words  that  represent  them,            *  e,g.  “5282”  -­‐>  Set(“Java”,  “Kata”,  “Lava”,  ...)  */      private  val  wordsForNum:  Map[String,  Set[String]]  =  ??      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =  ??      /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 10
  • 11. Class Coder  (1)   class  Coder(words:  List[String])  {      private  val  mnemonics  =  Map(              '2'  -­‐>  "ABC",  '3'  -­‐>  "DEF",  '4'  -­‐>  "GHI",  '5'  -­‐>  "JKL",                '6'  -­‐>  "MNO",  '7'  -­‐>  "PQRS",  '8'  -­‐>  "TUV",  '9'  -­‐>  "WXYZ")      /**  Invert  the  mnemonics  map  to  give  a  map  from  chars  'A'  ...  'Z'  to  '2'  ...  '9'  */      private  val  charCode:  Map[Char,  Char]  =          /**  Maps  a  word  to  the  digit  string  it  can  represent  */      private  def  wordCode(word:  String):  String  =  ??      /**  A  map  from  digit  strings  to  the  words  that  represent  them  */      private  val  wordsForNum:  Map[String,  List[String]]  =  ??      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =  ??      /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 11
  • 12. Class Coder  (1)   class  Coder(words:  List[String])  {      private  val  mnemonics  =  Map(              '2'  -­‐>  "ABC",  '3'  -­‐>  "DEF",  '4'  -­‐>  "GHI",  '5'  -­‐>  "JKL",                '6'  -­‐>  "MNO",  '7'  -­‐>  "PQRS",  '8'  -­‐>  "TUV",  '9'  -­‐>  "WXYZ")      /**  Invert  the  mnemonics  map  to  give  a  map  from  chars  'A'  ...  'Z'  to  '2'  ...  '9'  */      private  val  charCode:  Map[Char,  Char]  =       for  ((digit,  str)  <-­‐  mnemonics;  ltr  <-­‐  str)  yield  (ltr  -­‐>  digit)      /**  Maps  a  word  to  the  digit  string  it  can  represent  */      private  def  wordCode(word:  String):  String  =  ??      /**  A  map  from  digit  strings  to  the  words  that  represent  them  */      private  val  wordsForNum:  Map[String,  List[String]]  =  ??      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =  ??      /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 12
  • 13. Class Coder  (2)   class  Coder(words:  List[String])  {      private  val  mnemonics  =  Map(              '2'  -­‐>  "ABC",  '3'  -­‐>  "DEF",  '4'  -­‐>  "GHI",  '5'  -­‐>  "JKL",                '6'  -­‐>  "MNO",  '7'  -­‐>  "PQRS",  '8'  -­‐>  "TUV",  '9'  -­‐>  "WXYZ")      /**  Invert  the  mnemonics  map  to  give  a  map  from  chars  'A'  ...  'Z'  to  '2'  ...  '9'  */      private  val  charCode:  Map[Char,  Char]  =       for  ((digit,  str)  <-­‐  m;  letter  <-­‐  str)  yield  (letter  -­‐>  digit)      /**  Maps  a  word  to  the  digit  string  it  can  represent,  e.g.  “Java”  -­‐>  “5282”  */      private  def  wordCode(word:  String):  String  =      /**  A  map  from  digit  strings  to  the  words  that  represent  them  */      private  val  wordsForNum:  Map[String,  Set[String]]  =  ??      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =  ??      /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 13
  • 14. Class Coder  (2)   class  Coder(words:  List[String])  {      private  val  mnemonics  =  Map(              '2'  -­‐>  "ABC",  '3'  -­‐>  "DEF",  '4'  -­‐>  "GHI",  '5'  -­‐>  "JKL",                '6'  -­‐>  "MNO",  '7'  -­‐>  "PQRS",  '8'  -­‐>  "TUV",  '9'  -­‐>  "WXYZ")      /**  Invert  the  mnemonics  map  to  give  a  map  from  chars  'A'  ...  'Z'  to  '2'  ...  '9'  */      private  val  charCode:  Map[Char,  Char]  =       for  ((digit,  str)  <-­‐  m;  letter  <-­‐  str)  yield  (letter  -­‐>  digit)      /**  Maps  a  word  to  the  digit  string  it  can  represent,  e.g.  “Java”  -­‐>  “5282”  */      private  def  wordCode(word:  String):  String  =        word.toUpperCase  map  charCode      /**  A  map  from  digit  strings  to  the  words  that  represent  them  */      private  val  wordsForNum:  Map[String,  Set[String]]  =  ??      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =  ??      /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 14
  • 15. Class Coder  (3)   class  Coder(words:  List[String])  {      private  val  mnemonics  =  Map(              '2'  -­‐>  "ABC",  '3'  -­‐>  "DEF",  '4'  -­‐>  "GHI",  '5'  -­‐>  "JKL",                '6'  -­‐>  "MNO",  '7'  -­‐>  "PQRS",  '8'  -­‐>  "TUV",  '9'  -­‐>  "WXYZ")      /**  Invert  the  mnemonics  map  to  give  a  map  from  chars  'A'  ...  'Z'  to  '2'  ...  '9'  */      private  val  charCode:  Map[Char,  Char]  =       for  ((digit,  str)  <-­‐  m;  letter  <-­‐  str)  yield  (letter  -­‐>  digit)      /**  Maps  a  word  to  the  digit  string  it  can  represent  */      private  def  wordCode(word:  String):  String  =          word.toUpperCase  map  charCode      /**  A  map  from  digit  strings  to  the  words  that  represent  them,            *  e,g.  “5282”  -­‐>  Set(“Java”,  “Kata”,  “Lava”,  ...)  */      private  val  wordsForNum:  Map[String,  List[String]]  =        /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =  ??      /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 15
  • 16. Class Coder  (3)   class  Coder(words:  List[String])  {      private  val  mnemonics  =  Map(              '2'  -­‐>  "ABC",  '3'  -­‐>  "DEF",  '4'  -­‐>  "GHI",  '5'  -­‐>  "JKL",                '6'  -­‐>  "MNO",  '7'  -­‐>  "PQRS",  '8'  -­‐>  "TUV",  '9'  -­‐>  "WXYZ")      /**  Invert  the  mnemonics  map  to  give  a  map  from  chars  'A'  ...  'Z'  to  '2'  ...  '9'  */      private  val  charCode:  Map[Char,  Char]  =       for  ((digit,  str)  <-­‐  m;  letter  <-­‐  str)  yield  (letter  -­‐>  digit)      /**  Maps  a  word  to  the  digit  string  it  can  represent  */      private  def  wordCode(word:  String):  String  =          word.toUpperCase  map  charCode      /**  A  map  from  digit  strings  to  the  words  that  represent  them,            *  e,g.  “5282”  -­‐>  Set(“Java”,  “Kata”,  “Lava”,  ...)  */      private  val  wordsForNum:  Map[String,  List[String]]  =        (words  groupBy  wordCode)  withDefaultValue  List()      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =  ??      /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 16
  • 17. Class Coder  (4)   class  Coder(words:  List[String])  {  ...      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =        /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 17
  • 18. Class Coder  (4)   class  Coder(words:  List[String])  {  ...      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =      if  (number.isEmpty)              Set(List())      /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 18
  • 19. Class Coder  (4)   class  Coder(words:  List[String])  {  ...      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =      if  (number.isEmpty)              Set(List())          else  {          for  {                  splitPoint  <-­‐  1  to  number.length      /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 19
  • 20. Class Coder  (4)   class  Coder(words:  List[String])  {  ...      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =      if  (number.isEmpty)              Set(List())          else  {              for  {                  splitPoint  <-­‐  1  to  number.length                    word  <-­‐  wordsForNum(number  take  splitPoint)      /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 20
  • 21. Class Coder  (4)   class  Coder(words:  List[String])  {  ...      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =      if  (number.isEmpty)              Set(List())          else  {          for  {                  splitPoint  <-­‐  1  to  number.length      word  <-­‐  wordsForNum(number  take  splitPoint)                  rest  <-­‐  encode(number  drop  splitPoint)              }  yield  word  ::  rest          }.toSet      /**  Maps  a  number  to  a  list  of  all  word  phrases  that  can  represent  it  */      def  translate(number:  String):  Set[String]  =  encode(number)  map  (_  mkString  "  ")   } 21
  • 22. In Summary •  In the original experiment: –  Scripting language programs were shorter and often even faster than Java/C/C++ because their developers tended to use standard collections. •  In Scala’s solution: –  Obtained a further 5x reduction in size because of the systematic use of functional collections. •  Scala’s collection’s are also easily upgradable to parallel. Think collection transformers, not CRUD! 22
  • 23. A Solution in Java By Josh Bloch, author of Java collections   23
  • 24. Going Parallel •  In Scala 2.9, collections support parallel operations. •  Two new methods: c.par   returns parallel version of collection c     c.seq  returns sequential version of collection c   •  The right tool for addressing the PPP (popular parallel programming) challenge. •  I expect this to be the cornerstone for making use of multicores for the rest of us. 24
  • 25. a parallel collection Parallel Coder   class  Coder(words:  ParVector[String])  {      private  val  mnemonics  =  Map(              '2'  -­‐>  "ABC",  '3'  -­‐>  "DEF",  '4'  -­‐>  "GHI",  '5'  -­‐>  "JKL",                '6'  -­‐>  "MNO",  '7'  -­‐>  "PQRS",  '8'  -­‐>  "TUV",  '9'  -­‐>  "WXYZ")      /**  Invert  the  mnemonics  map  to  give  a  map  from  chars  'A'  ...  'Z'  to  '2'  ...  '9'  */      private  val  charCode:  Map[Char,  Char]  =       for  ((digit,  str)  <-­‐  m;  letter  <-­‐  str)  yield  (letter  -­‐>  digit)      /**  Maps  a  word  to  the  digit  string  it  can  represent  */      private  def  wordCode(word:  String):  String  =  word.toUpperCase  map  charCode      /**  A  map  from  digit  strings  to  the  words  that  represent  them  */      private  val  wordsForNum:  Map[String,  List[String]]  =  words  groupBy  wordCode      /**  Return  all  ways  to  encode  a  number  as  a  list  of  words  */      def  encode(number:  String):  Set[List[String]]  =      if  (number.isEmpty)  Set(List())          else  {   mapping sequential            for  {   collection to parallel                splitPoint  <-­‐  (1  to  number.length).par                  word  <-­‐  wordsForNum(number  take  splitPoint)                  rest  <-­‐  encode(number  drop  splitPoint)              }  yield  word  ::  rest   }.toSet 25
  • 26. Parallel Collections •  Split work by number of Processors •  Each Thread has a work queue that is split exponentially. Largest on end of queue •  Granularity balance against scheduling overhead •  On completion threads “work steals” from end of other thread queues 26
  • 27. General Collection Hierarchy GenTraversable GenIterable Traversable GenSeq Iterable ParIterable Seq ParSeq 27
  • 28. Going Distributed •  Can we get the power of parallel collections to work on 10’000s of computers? •  Hot technologies: MapReduce (Google’s and Hadoop) •  But not everything is easy to fit into that mold •  Sometimes 100’s of map-reduce steps are needed. •  Distributed collections retain most operations, provide a powerful frontend for MapReduce computations. •  Scala’s uniform collection model is designed to also accommodate parallel and distributed. 28
  • 29. The Future Scala’s persistent collections are •  easy to use: few steps to do the job •  concise: one word replaces a whole loop •  safe: type checker is really good at catching errors •  fast: collection ops are tuned, can be parallelized •  scalable: one vocabulary to work on all kinds of collections: sequential, parallel, or distributed. I see them play a rapidly increasing role in software development. 29
  • 30. Akka: Event-driven Middleware in Scala •  Unified programming model for: –  scaling up to many cores –  scaling out to many nodes –  fault-tolerance •  Actors: –  lightweight (run millions on a single node) –  send and receive messages async –  location transparent •  Transparent and adaptive: –  load-balancing and routing –  replication and fail-over –  elasticity: grow/shrink dynamically •  Decouples app logic from low-level mechanisms 30
  • 31. Akka vs scala.actors Akka: + Best performance + Scalable to clusters and clouds + Best safety through encapsulation Scala Actors: + Simple to get started + Good integration with threads + Blocking as well as non-blocking receives − Erlang-inherited mailbox model can lead to inefficient code Over the next releases we plan to merge the two libraries. 31
  • 32. Other New Developments •  Scala-based reflection •  Type Dynamic •  Effects in an optional pluggable type system (?) •  Libraries: –  I/O, including event-based –  STM –  Reactive programming, GUI •  Most effort will go in tools –  Eclipse IDE –  REPL –  SBT (simple build tool) –  Type debugger 32
  • 33. Going further But how do we keep a bunch of Fermi’s happy? –  How to find and deal with 10000+ threads in an application? –  Parallel collections and actors are necessary but not sufficient for this. Our bet for the mid term future: parallel embedded DSLs. –  Find parallelism in domains: physics simulation, machine learning, statistics, ... Joint work with Kunle Olukuton, Pat Hanrahan @ Stanford. EPFL side funded by ERC. 33
  • 34. Scientific Virtual Personal Data Applications Engineering Worlds Robotics informatics Domain Physics Probabilistic Machine Specific Rendering Scripting Learning Languages (Liszt) (RandomT) (OptiML) Domain Embedding Language (Scala) Polymorphic Embedding Staging Static Domain Specific Opt. DSL Infrastructure Parallel Runtime (Delite, Sequoia, GRAMPS) Dynamic Domain Spec. Opt. Task & Data Parallelism Locality Aware Scheduling Hardware Architecture Heterogeneous OOO Cores SIMD Cores Threaded Cores Specialized Cores Hardware Programmable Scalable Isolation & On-chip Pervasive Hierarchies Coherence Atomicity Networks Monitoring 34
  • 35. Example: Liszt - A DSL for Physics Simulation Combustion Turbulence Fuel injection Transition Thermal •  Mesh-based •  Numeric Simulation •  Huge domains Turbulence –  millions of cells •  Example: Unstructured Reynolds-averaged Navier Stokes (RANS) solver 35
  • 36. Liszt as Virtualized Scala val // calculating scalar convection (Liszt) val Flux = new Field[Cell,Float] AST val Phi = new Field[Cell,Float] val cell_volume = new Field[Cell,Float] val deltat = .001 ... untilconverged { for(f <- interior_faces) { val flux = calc_flux(f) Flux(inside(f)) -= flux Flux(outside(f)) += flux } for(f <- inlet_faces) { Optimisers Generators Flux(outside(f)) += calc_boundary_flux(f) } … for(c <- cells(mesh)) { Phi(c) += deltat * Flux(c) /cell_volume Schedulers (c) } … for(f <- faces(mesh)) Flux(f) = 0.f Hardware } DSL Library GPU, Multi-Core, etc 36
  • 37. Other Developments DelayedInit Dynamic Scala 2.9 also introduces two new “magic” traits: Tools DelayedInit and Reflection Dynamic! STM @specialized A lot work has been done on the tools side: Slick Scala IDE for Eclipse 2.0, scala.reflect SBT 0.10, scala.react enhanced REPL, Scala.NET Migration Manager Diagnostics (MiMaLib) Scala.IO (?) Effects (?) Javascript (?) 37
  • 38. Planned Work DelayedInit Dynamic Over the next releases, we plan to introduce: Tools •  Scala STM, a standard STM API, Reflection •  Enhanced support for @specialized, STM •  Slick, A common framework for connecting with @specialized databases and distributed collections. Slick •  Scala.reflect, a Scala-centric reflection library. scala.reflect •  Scala.react, a reactive programming framework. scala.react •  An updated Scala.NET Scala.NET We are also exploring: Scala.IO (?) •  Adding Scala.IO to the standard distibution Effects (?) •  An effect system for Scala Javascript (?) •  A Scala to Javascript translator 38
  • 39. DelayedInit and App DelayedInit Dynamic Trait Application is convenient, but has hidden problems: Tools object First extends Application { Reflection println("hi there!) STM } @specialized Slick Body is executed as part of the object initializer. scala.reflect main method inherited from Application is empty. scala.react Body is neither optimized nor threading-friendly. Scala.NET Scala.IO (?) Solution: Replace Application with App. Effects (?) Javascript (?) 39
  • 40. DelayedInit and App DelayedInit Dynamic Trait App solves these problems: Tools object First extends App { Reflection println("hi there!) STM } @specialized Slick Body is now stored in a buffer, executed by main method. scala.reflect Here’s an outline of this trait. scala.react Scala.NET trait App extends DelayedInit { Scala.IO (?) def main(args: Array[String]) = for (code <- inits) code() Effects (?) } Javascript (?) 40
  • 41. Conclusion Scala has the right “genes” to scale into parallel + distributed computing: •  Strong, practical foundation: JVM •  Functional programming reduces liabilities •  Library-centric approach makes for building tailored solutions. Makes it possible to write: •  High-level, easy to use libraries (e.g., collections) •  Safer concurrency concepts (e.g., actors) •  Parallel DSLs (e.g., EPFL/Stanford project) 41
  • 42. Thank You scala-lang.org typesafe.com 42