SlideShare a Scribd company logo
1 of 31
Download to read offline
SCALA FUNDAMENTALS
JARGON DICTIONARY
(ADT, TYPECLASSES, EXTENSION METHODS,
CAKE, ETC …. )
// Ruslan Shevchenko
Legend:
— you start to learn scala and found a dozen of new words.
ADT
GADT
typeclasses
existential types
Pattern-matching
Call by {name, value}
Legend:
— words, idioms, …
— let’s made cheatsheet
ADT = { Algebraic Data Types }
ADT = { Abstract Data Types } (not SCALA)
— in context:
Algol 60
Simula
CLU
Algol 68
Scala
LISP
Flavours
ML
ADT = { Algebraic Data Types }
ADT = { Abstract Data Types } (not SCALA)
Pattern Matching
Nominative types, Structured Types
Generic = (Parameter Polymorphism)
Existential types
Type aliases F-Bounded Polymorphism
Traits = (mixins, flavors)
typeclasses = (typeclasses, concepts )
implicit.
extension methods.
ADT = { Abstract Data Types } (not SCALA)
CLU (1970, MIT)
"An abstract data type defines a class of abstract objects which is completely
characterized by the operations available on those objects. This means that an
abstract data type can be defined by defining the characterizing operations for
that type."
// 1974, ACM Sigplan, Congress of very hight-level languages.
From today-s point of view: Interface
cluster stack[t] is create push pop isEmpty
%rep struct {
arr: array[t]
idx: Int
}
create = proc() returns(cvt) ….
push = proc(x:t) signal(overflow)
trait Stack[T]
{
def push(x:T): Unit
…….
}
Barbara Leskov
ADT = { Algebraic Data Type }
HOPE (1970, Edinburg)
From today-s point of view: ADT ;)
data list alpha = nil
++ alpha :: list alpha
(A, B) == Pair[A,B]
(A+B) == emulated by sealed trait
(a:A,b:B)== case classes.
A | B ~~ partially emulated by traits
(will be implemented in dotty)
A & B ~~ partially emulated by A with B
(will be implemented in dotty)
A => B == Function[A,B]
Rod Burstall
David MacQueen
Some initial set of types: A, B, C, ….
Operations on types: Pair [A*B]
records (set of name-value-pairs)
discriminated unions (one of A or B)
functions: A=>B
// often (incorrectly): discr. union == ADT
Equality by value
ADT = { Algebraic Data Type }
data X = A ++ B
data A = ‘A#integer#integer
data B = ‘B#string
(a:A,b:B)== case classes [or objects].
sealed trait X
case class A(x:Int,y:Int) extends X
case class B(s:String) extends X
discriminated unions (one of A or B)
// often (incorrectly): discr. union == ADT
A+B
A+0
B+0
BOOL
BOOL
isA
isB
Pattern Matching
HOPE (1970, Edinburg)
data list alpha = nil
++ alpha::list alpha
sealed trait List[+A]
class Nil extends List[Nothing]
class Cons[A](head:A, tail:List[A]) extends List[A]
Rod Burstall
David MacQueen
dec length: list(alpha) -> int
— length nil <= 0
— length (a::l) <= length(l) + 1
def length[A](l: List[A]): Int =
l match {
case Nil => 0
case Cons(head,tail) => 1+length(tail)
}
Pattern Matching
SCALA
data list alpha = nil
++ alpha::list alpha
sealed trait List[+A]
class Nil extends List[Nothing]
class Cons[A](head:A, tail:List[A]) extends List[A]
dec length: list(alpha) -> int
— length nil <= 0
— length (a::l) <= length(l) + 1
def length[A](l: List[A]): Int =
l match {
case Nil => 0
case Cons(head,tail) => 1+length(tail)
}
Pattern Matching
SCALA
data list alpha = nil
++ alpha::list alpha
sealed trait List[+A]
class Nil extends List[Nothing]
class Cons[A](head:A, tail:List[A]) extends List[A]
dec length: list(alpha) -> int
— length nil <= 0
— length (a::l) <= length(l) + 1
def length[A](l: List[A]): Int =
l match {
case Nil => 0
case head :: tail => 1+length(tail)
}
Pattern Matching
Why Pattern Matching is better than sequence of IF-s ?
- Binding. (i.e. information from structure is extracted into variables)
We have not only algebraic, but object-oriented types.
- Views. (bridge, which represent object as algebraic type). Wadler, 1984
- Pattern objects. (Pattern-object method call return algebraic type)
- ODersky, 2006
- Exhaustive checking (if we miss something then we will see this)
x match {
case A(x,y) => y1
….
}
We have not only algebraic, but object-oriented types.
Pattern-Object
object A {
def unapply(x: X): Option[(A,B)]
}
extractor
Regular expressions:
final val StackElement =
“""W+([^)]+)(([^:]*):([^)]*))W*""".r
line match {
case StackElement(class,file,lineno) => ….
….
}
sealed trait Option[+A]
case class Some[A](a:A) extends Option[A]
case object None extends Option[Nothing]
val fac: Int => Int = {
case 0 => 1
case n => n*fac(n-1)
}
Partial functions syntax:
object Succ
{
def unapply(n: Int):Option[Int] =
if (n==0) None
else Some(n-1)
}
{ case (x,y) => (y,x) }
val positiveOne: Int => Int = {
case Succ(n) => 1
}
positiveOne.isDefinedAt(0)
false
positiveOne.isDefinedAt(3)
true
Partial functions:
val positiveOne: Int => Int = {
case Succ(n) => 1
}
positiveOne.isDefinedAt(0)
false
positiveOne.isDefinedAt(3)
true
PartialFunction[A,B]
B
Boolean
A
apply
isDefinedAt
Types: A <: B
Nominative typing (type == name)
{ def x:Int ; def y: Int } val a = A(1,2)
val b = new B(1,2)
f(a) ==> 3
f(b) ==> 3
Structured typing (type == structure)
case class A(x: Int, y: Int)
class B(x: Int, y: Int)
A != B
- Effective implementation in JVM
- Simula, Clu, C++, Java, …..
~ (A <: B)
~ (B <: A)
def f(p: { def x:Int ; def y: Int }):Int =
p.x + p.y
- implementation in JVM require reflection (can be better)
- ML, OCaml, Go
- theoretically have less corner cases than nominative
Refined type
Generics [Parametric Polymorphism]
B {
def z: Int
}
F[T]
- Structured type, based on nominative.
- Scala: structured types are refinement of AnyRef
Existential types: F[_] F[X] for Some X
Bounded type parameters:
Type aliases
F[T <: Closeable]
F[T <: { def close(): Unit }]
trait Expression[A]
{
type Value = A
}
trait Expression
{
type Value <: X
}
Undefined type alias
Scolem type
//CLU where
Traits:
trait Interpeter {
type Value
}
trait BaseInterpreter[A] extends Additive with Multiplicative with Show
{
type Value = A
}
Flavours (Flavours, [LISP dialects]) 1980, MIT
Mixing
trait Show {
this: Interpreter =>
def show
}
trait Additive {
this: Interpreter =>
def plus(x:Value, y:Value): Value
}
// Howard Cannon, David Moor
(CLOS, OCaml, Groovy, Python ..)
Traits:
trait LoggedInterpreter[A] extends BaseInterpreter[A]
with Logged with LoggedAdditive
trait LoggedAdditive extends Additive {
this => Logged
def plus(x:Value, y: Value) : Value =
{
log(s”(${x}+${y}”)
super.plus(x,y)
}
}
trait Additive {
this: Interpreter =>
def plus(x:Value, y:Value): Value
}
// AOP (aspect oriented programming)
// Flavours
: around
: before-next
: after-next
Type classes.
class Eq a where
== :: a -> a -> Bool
/= :: a -> a -> Bool
class (Eq a) => Ord a
where
compare :: a->a->Int
instance Ord Int where
compare x y = (x-y)
//addition to Haskell, Wadler, 1988
Constructor classes (type classes with multiple type parameters).
//addition to Haskell, Jone, 1993
instance (Eq a) (Eq b) => Eq(Pair a b) where
== (Pair x y) (Pair z w) =
x == z and y == w
classes = rules; instances = adaptors to this rules
Type classes.
trait Eq[A] {
def === (x:A, y:A):Boolean
def !== (x:A, y:A):Boolean = !(x===y)
}
trait Ord[A] extends Eq[A]
{
def compare :: a->a->Int
override
def ===(x:A, y:A):Boolean =
(compare(x,y)==0)
}
implicit val intOrd: Ord[Int] = new Ord[Int]
{
def compare(x:Int, y:Int) = (x-y)
}
//in scala as design pattern (implicit) & one word
implicit def pairEq[A,B]: Eq[Pair[A,B]]
( implicit eqA:Eq[A], eqB:Eq[B]) =
{
def ===(x: Pair[A,B],y:Pair[A,B]):Boolean=
eqA(x._1,y._1) && eqB(x._1, y._1)

}
implicit (val, def, classes )
- define rules of your world
- can be usable via implicit parameters
- implicit search <=> logical deduction
- can be dangerous.
implicit def stringToInt(s:String):Int = s.toInt
def f(x:Int):Int = x+1
f(“45”)
implicit (val, def, classes )
- define rules of your world
- can be usable via implicit parameters
- implicit search <=> logical deduction
- can be dangerous.
implicit def toJson(x:Int): Json = JsonNumeric(10)
def printAsJson[A](x:A)(implicit convert:A=>Json): String =
convert(x).prettyPrint
Type classes.
//Libraries: universal rules (like ontologies in philosophy)
scalaz : https://github.com/scalaz/scalaz
spire/algebra: https://github.com/non/algebra
(now - part of cats)
//Potenial problem: premature abstraction
// Human is an upright, featherless, ripped with broad, flat nails
+
Z / 10^64 Z << BigInt
Z{ |x| < 10^32} <<ERROR
Extension methods.
//implicit-based technique (pimp my library pattern [obsolete name])
implicit class WithPow(x: Int) {
def pow(y: Int): Int = Math.pow(x,y).toInt
}
scala> 2 pow 3
scala> res1: Int = 8
• pow — Int have no pow method
• => compiler search for implicit with pow
Scala types.
//whats-left for advanced talks:
42.type
Dynamic
// Homework:
Path dependency issues.
What’s left out of scala type system (?)
Call by ……….
Value.
Reference:
Name
Need
// value is copied.
// reference is copied by value.
// reference in language must exists
// Algol 68 (today - call by closure)
// lazy one-time evaluation
Call by ……….
Name // Algol 68 (today - call by closure)
def doWhile(x: => Boolean)(f : =>Unit)
{ while(x) { f } }
doWhile(x < 10)(x = x + 1)
Call by ……….
Need
def dupN[A](n: Int, v : =>A): Seq[A] =
{ lazy val neededV = v
for( i <- 1 to N) yield v
}
Scala.
Scala / Dotty : like grand unification theory
for large subset of type theories.
Mathematical jargon hide quite simple patterns.
Questions ?
// ruslan@shevchenko.kiev.ua
Scala jargon cheatsheet

More Related Content

What's hot

Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: NotesRoberto Casadei
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheoryKnoldus Inc.
 
Scala collections api expressivity and brevity upgrade from java
Scala collections api  expressivity and brevity upgrade from javaScala collections api  expressivity and brevity upgrade from java
Scala collections api expressivity and brevity upgrade from javaIndicThreads
 
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...Sanjeev_Knoldus
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in ScalaShai Yallin
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scalafanf42
 
Property based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesProperty based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesDebasish Ghosh
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Derek Chen-Becker
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersSkills Matter
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With ScalaTomer Gabel
 
Practically Functional
Practically FunctionalPractically Functional
Practically Functionaldjspiewak
 
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 ScalaDerek Chen-Becker
 

What's hot (20)

Scala Intro
Scala IntroScala Intro
Scala Intro
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
Scala collections api expressivity and brevity upgrade from java
Scala collections api  expressivity and brevity upgrade from javaScala collections api  expressivity and brevity upgrade from java
Scala collections api expressivity and brevity upgrade from java
 
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
 
Scala for curious
Scala for curiousScala for curious
Scala for curious
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in Scala
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
Property based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesProperty based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rules
 
Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
 
Scala
ScalaScala
Scala
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
 
Joy of scala
Joy of scalaJoy of scala
Joy of scala
 
Practically Functional
Practically FunctionalPractically Functional
Practically Functional
 
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
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 

Similar to Scala jargon cheatsheet

Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed worldDebasish Ghosh
 
Type classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceType classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceAlexey Raga
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Languageleague
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and HaskellHermann Hueck
 
Comparing Haskell & Scala
Comparing Haskell & ScalaComparing Haskell & Scala
Comparing Haskell & ScalaMartin Ockajak
 
Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Philip Schwarz
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldWerner Hofstra
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevJavaDayUA
 
Monoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsMonoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsPhilip Schwarz
 
Scala or functional programming from a python developer's perspective
Scala or functional programming from a python developer's perspectiveScala or functional programming from a python developer's perspective
Scala or functional programming from a python developer's perspectivegabalese
 
Oh, All the things you'll traverse
Oh, All the things you'll traverseOh, All the things you'll traverse
Oh, All the things you'll traverseLuka Jacobowitz
 

Similar to Scala jargon cheatsheet (20)

Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
 
Type classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceType classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritance
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and Haskell
 
Scala
ScalaScala
Scala
 
Comparing Haskell & Scala
Comparing Haskell & ScalaComparing Haskell & Scala
Comparing Haskell & Scala
 
Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Sequence and Traverse - Part 3
Sequence and Traverse - Part 3
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereld
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy Dyagilev
 
Meet scala
Meet scalaMeet scala
Meet scala
 
Monoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsMonoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and Cats
 
Scala or functional programming from a python developer's perspective
Scala or functional programming from a python developer's perspectiveScala or functional programming from a python developer's perspective
Scala or functional programming from a python developer's perspective
 
Oh, All the things you'll traverse
Oh, All the things you'll traverseOh, All the things you'll traverse
Oh, All the things you'll traverse
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
ScalaBlitz
ScalaBlitzScalaBlitz
ScalaBlitz
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 

More from Ruslan Shevchenko

Embedding Generic Monadic Transformer into Scala. [Tfp2022]
Embedding Generic Monadic Transformer into Scala. [Tfp2022]Embedding Generic Monadic Transformer into Scala. [Tfp2022]
Embedding Generic Monadic Transformer into Scala. [Tfp2022]Ruslan Shevchenko
 
Papers We Love / Kyiv : PAXOS (and little about other consensuses )
Papers We Love / Kyiv :  PAXOS (and little about other consensuses )Papers We Love / Kyiv :  PAXOS (and little about other consensuses )
Papers We Love / Kyiv : PAXOS (and little about other consensuses )Ruslan Shevchenko
 
Scala / Technology evolution
Scala  / Technology evolutionScala  / Technology evolution
Scala / Technology evolutionRuslan Shevchenko
 
{co/contr} variance from LSP
{co/contr} variance  from LSP{co/contr} variance  from LSP
{co/contr} variance from LSPRuslan Shevchenko
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Ruslan Shevchenko
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisRuslan Shevchenko
 
Java & low latency applications
Java & low latency applicationsJava & low latency applications
Java & low latency applicationsRuslan Shevchenko
 
Jslab rssh: JS as language platform
Jslab rssh:  JS as language platformJslab rssh:  JS as language platform
Jslab rssh: JS as language platformRuslan Shevchenko
 
Behind OOD: domain modelling in post-OO world.
Behind OOD:  domain modelling in post-OO world.Behind OOD:  domain modelling in post-OO world.
Behind OOD: domain modelling in post-OO world.Ruslan Shevchenko
 
scala-gopher: async implementation of CSP for scala
scala-gopher:  async implementation of CSP  for  scalascala-gopher:  async implementation of CSP  for  scala
scala-gopher: async implementation of CSP for scalaRuslan Shevchenko
 
Programming Languages: some news for the last N years
Programming Languages: some news for the last N yearsProgramming Languages: some news for the last N years
Programming Languages: some news for the last N yearsRuslan Shevchenko
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation streamRuslan Shevchenko
 
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014Ruslan Shevchenko
 
Web architecture - overview of techniques.
Web architecture - overview of  techniques.Web architecture - overview of  techniques.
Web architecture - overview of techniques.Ruslan Shevchenko
 

More from Ruslan Shevchenko (20)

Embedding Generic Monadic Transformer into Scala. [Tfp2022]
Embedding Generic Monadic Transformer into Scala. [Tfp2022]Embedding Generic Monadic Transformer into Scala. [Tfp2022]
Embedding Generic Monadic Transformer into Scala. [Tfp2022]
 
Svitla talks 2021_03_25
Svitla talks 2021_03_25Svitla talks 2021_03_25
Svitla talks 2021_03_25
 
Akka / Lts behavior
Akka / Lts behaviorAkka / Lts behavior
Akka / Lts behavior
 
Papers We Love / Kyiv : PAXOS (and little about other consensuses )
Papers We Love / Kyiv :  PAXOS (and little about other consensuses )Papers We Love / Kyiv :  PAXOS (and little about other consensuses )
Papers We Love / Kyiv : PAXOS (and little about other consensuses )
 
Scala / Technology evolution
Scala  / Technology evolutionScala  / Technology evolution
Scala / Technology evolution
 
{co/contr} variance from LSP
{co/contr} variance  from LSP{co/contr} variance  from LSP
{co/contr} variance from LSP
 
N flavors of streaming
N flavors of streamingN flavors of streaming
N flavors of streaming
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with this
 
Java & low latency applications
Java & low latency applicationsJava & low latency applications
Java & low latency applications
 
Csp scala wixmeetup2016
Csp scala wixmeetup2016Csp scala wixmeetup2016
Csp scala wixmeetup2016
 
IDLs
IDLsIDLs
IDLs
 
R ext world/ useR! Kiev
R ext world/ useR!  KievR ext world/ useR!  Kiev
R ext world/ useR! Kiev
 
Jslab rssh: JS as language platform
Jslab rssh:  JS as language platformJslab rssh:  JS as language platform
Jslab rssh: JS as language platform
 
Behind OOD: domain modelling in post-OO world.
Behind OOD:  domain modelling in post-OO world.Behind OOD:  domain modelling in post-OO world.
Behind OOD: domain modelling in post-OO world.
 
scala-gopher: async implementation of CSP for scala
scala-gopher:  async implementation of CSP  for  scalascala-gopher:  async implementation of CSP  for  scala
scala-gopher: async implementation of CSP for scala
 
Programming Languages: some news for the last N years
Programming Languages: some news for the last N yearsProgramming Languages: some news for the last N years
Programming Languages: some news for the last N years
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
 
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014
 
Web architecture - overview of techniques.
Web architecture - overview of  techniques.Web architecture - overview of  techniques.
Web architecture - overview of techniques.
 

Recently uploaded

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 

Scala jargon cheatsheet

  • 1. SCALA FUNDAMENTALS JARGON DICTIONARY (ADT, TYPECLASSES, EXTENSION METHODS, CAKE, ETC …. ) // Ruslan Shevchenko
  • 2. Legend: — you start to learn scala and found a dozen of new words. ADT GADT typeclasses existential types Pattern-matching Call by {name, value}
  • 3. Legend: — words, idioms, … — let’s made cheatsheet ADT = { Algebraic Data Types } ADT = { Abstract Data Types } (not SCALA) — in context: Algol 60 Simula CLU Algol 68 Scala LISP Flavours ML
  • 4. ADT = { Algebraic Data Types } ADT = { Abstract Data Types } (not SCALA) Pattern Matching Nominative types, Structured Types Generic = (Parameter Polymorphism) Existential types Type aliases F-Bounded Polymorphism Traits = (mixins, flavors) typeclasses = (typeclasses, concepts ) implicit. extension methods.
  • 5. ADT = { Abstract Data Types } (not SCALA) CLU (1970, MIT) "An abstract data type defines a class of abstract objects which is completely characterized by the operations available on those objects. This means that an abstract data type can be defined by defining the characterizing operations for that type." // 1974, ACM Sigplan, Congress of very hight-level languages. From today-s point of view: Interface cluster stack[t] is create push pop isEmpty %rep struct { arr: array[t] idx: Int } create = proc() returns(cvt) …. push = proc(x:t) signal(overflow) trait Stack[T] { def push(x:T): Unit ……. } Barbara Leskov
  • 6. ADT = { Algebraic Data Type } HOPE (1970, Edinburg) From today-s point of view: ADT ;) data list alpha = nil ++ alpha :: list alpha (A, B) == Pair[A,B] (A+B) == emulated by sealed trait (a:A,b:B)== case classes. A | B ~~ partially emulated by traits (will be implemented in dotty) A & B ~~ partially emulated by A with B (will be implemented in dotty) A => B == Function[A,B] Rod Burstall David MacQueen Some initial set of types: A, B, C, …. Operations on types: Pair [A*B] records (set of name-value-pairs) discriminated unions (one of A or B) functions: A=>B // often (incorrectly): discr. union == ADT Equality by value
  • 7. ADT = { Algebraic Data Type } data X = A ++ B data A = ‘A#integer#integer data B = ‘B#string (a:A,b:B)== case classes [or objects]. sealed trait X case class A(x:Int,y:Int) extends X case class B(s:String) extends X discriminated unions (one of A or B) // often (incorrectly): discr. union == ADT A+B A+0 B+0 BOOL BOOL isA isB
  • 8. Pattern Matching HOPE (1970, Edinburg) data list alpha = nil ++ alpha::list alpha sealed trait List[+A] class Nil extends List[Nothing] class Cons[A](head:A, tail:List[A]) extends List[A] Rod Burstall David MacQueen dec length: list(alpha) -> int — length nil <= 0 — length (a::l) <= length(l) + 1 def length[A](l: List[A]): Int = l match { case Nil => 0 case Cons(head,tail) => 1+length(tail) }
  • 9. Pattern Matching SCALA data list alpha = nil ++ alpha::list alpha sealed trait List[+A] class Nil extends List[Nothing] class Cons[A](head:A, tail:List[A]) extends List[A] dec length: list(alpha) -> int — length nil <= 0 — length (a::l) <= length(l) + 1 def length[A](l: List[A]): Int = l match { case Nil => 0 case Cons(head,tail) => 1+length(tail) }
  • 10. Pattern Matching SCALA data list alpha = nil ++ alpha::list alpha sealed trait List[+A] class Nil extends List[Nothing] class Cons[A](head:A, tail:List[A]) extends List[A] dec length: list(alpha) -> int — length nil <= 0 — length (a::l) <= length(l) + 1 def length[A](l: List[A]): Int = l match { case Nil => 0 case head :: tail => 1+length(tail) }
  • 11. Pattern Matching Why Pattern Matching is better than sequence of IF-s ? - Binding. (i.e. information from structure is extracted into variables) We have not only algebraic, but object-oriented types. - Views. (bridge, which represent object as algebraic type). Wadler, 1984 - Pattern objects. (Pattern-object method call return algebraic type) - ODersky, 2006 - Exhaustive checking (if we miss something then we will see this)
  • 12. x match { case A(x,y) => y1 …. } We have not only algebraic, but object-oriented types. Pattern-Object object A { def unapply(x: X): Option[(A,B)] } extractor Regular expressions: final val StackElement = “""W+([^)]+)(([^:]*):([^)]*))W*""".r line match { case StackElement(class,file,lineno) => …. …. } sealed trait Option[+A] case class Some[A](a:A) extends Option[A] case object None extends Option[Nothing]
  • 13. val fac: Int => Int = { case 0 => 1 case n => n*fac(n-1) } Partial functions syntax: object Succ { def unapply(n: Int):Option[Int] = if (n==0) None else Some(n-1) } { case (x,y) => (y,x) } val positiveOne: Int => Int = { case Succ(n) => 1 } positiveOne.isDefinedAt(0) false positiveOne.isDefinedAt(3) true
  • 14. Partial functions: val positiveOne: Int => Int = { case Succ(n) => 1 } positiveOne.isDefinedAt(0) false positiveOne.isDefinedAt(3) true PartialFunction[A,B] B Boolean A apply isDefinedAt
  • 16. Nominative typing (type == name) { def x:Int ; def y: Int } val a = A(1,2) val b = new B(1,2) f(a) ==> 3 f(b) ==> 3 Structured typing (type == structure) case class A(x: Int, y: Int) class B(x: Int, y: Int) A != B - Effective implementation in JVM - Simula, Clu, C++, Java, ….. ~ (A <: B) ~ (B <: A) def f(p: { def x:Int ; def y: Int }):Int = p.x + p.y - implementation in JVM require reflection (can be better) - ML, OCaml, Go - theoretically have less corner cases than nominative
  • 17. Refined type Generics [Parametric Polymorphism] B { def z: Int } F[T] - Structured type, based on nominative. - Scala: structured types are refinement of AnyRef Existential types: F[_] F[X] for Some X Bounded type parameters: Type aliases F[T <: Closeable] F[T <: { def close(): Unit }] trait Expression[A] { type Value = A } trait Expression { type Value <: X } Undefined type alias Scolem type //CLU where
  • 18. Traits: trait Interpeter { type Value } trait BaseInterpreter[A] extends Additive with Multiplicative with Show { type Value = A } Flavours (Flavours, [LISP dialects]) 1980, MIT Mixing trait Show { this: Interpreter => def show } trait Additive { this: Interpreter => def plus(x:Value, y:Value): Value } // Howard Cannon, David Moor (CLOS, OCaml, Groovy, Python ..)
  • 19. Traits: trait LoggedInterpreter[A] extends BaseInterpreter[A] with Logged with LoggedAdditive trait LoggedAdditive extends Additive { this => Logged def plus(x:Value, y: Value) : Value = { log(s”(${x}+${y}”) super.plus(x,y) } } trait Additive { this: Interpreter => def plus(x:Value, y:Value): Value } // AOP (aspect oriented programming) // Flavours : around : before-next : after-next
  • 20. Type classes. class Eq a where == :: a -> a -> Bool /= :: a -> a -> Bool class (Eq a) => Ord a where compare :: a->a->Int instance Ord Int where compare x y = (x-y) //addition to Haskell, Wadler, 1988 Constructor classes (type classes with multiple type parameters). //addition to Haskell, Jone, 1993 instance (Eq a) (Eq b) => Eq(Pair a b) where == (Pair x y) (Pair z w) = x == z and y == w classes = rules; instances = adaptors to this rules
  • 21. Type classes. trait Eq[A] { def === (x:A, y:A):Boolean def !== (x:A, y:A):Boolean = !(x===y) } trait Ord[A] extends Eq[A] { def compare :: a->a->Int override def ===(x:A, y:A):Boolean = (compare(x,y)==0) } implicit val intOrd: Ord[Int] = new Ord[Int] { def compare(x:Int, y:Int) = (x-y) } //in scala as design pattern (implicit) & one word implicit def pairEq[A,B]: Eq[Pair[A,B]] ( implicit eqA:Eq[A], eqB:Eq[B]) = { def ===(x: Pair[A,B],y:Pair[A,B]):Boolean= eqA(x._1,y._1) && eqB(x._1, y._1) 
}
  • 22. implicit (val, def, classes ) - define rules of your world - can be usable via implicit parameters - implicit search <=> logical deduction - can be dangerous. implicit def stringToInt(s:String):Int = s.toInt def f(x:Int):Int = x+1 f(“45”)
  • 23. implicit (val, def, classes ) - define rules of your world - can be usable via implicit parameters - implicit search <=> logical deduction - can be dangerous. implicit def toJson(x:Int): Json = JsonNumeric(10) def printAsJson[A](x:A)(implicit convert:A=>Json): String = convert(x).prettyPrint
  • 24. Type classes. //Libraries: universal rules (like ontologies in philosophy) scalaz : https://github.com/scalaz/scalaz spire/algebra: https://github.com/non/algebra (now - part of cats) //Potenial problem: premature abstraction // Human is an upright, featherless, ripped with broad, flat nails + Z / 10^64 Z << BigInt Z{ |x| < 10^32} <<ERROR
  • 25. Extension methods. //implicit-based technique (pimp my library pattern [obsolete name]) implicit class WithPow(x: Int) { def pow(y: Int): Int = Math.pow(x,y).toInt } scala> 2 pow 3 scala> res1: Int = 8 • pow — Int have no pow method • => compiler search for implicit with pow
  • 26. Scala types. //whats-left for advanced talks: 42.type Dynamic // Homework: Path dependency issues. What’s left out of scala type system (?)
  • 27. Call by ………. Value. Reference: Name Need // value is copied. // reference is copied by value. // reference in language must exists // Algol 68 (today - call by closure) // lazy one-time evaluation
  • 28. Call by ………. Name // Algol 68 (today - call by closure) def doWhile(x: => Boolean)(f : =>Unit) { while(x) { f } } doWhile(x < 10)(x = x + 1)
  • 29. Call by ………. Need def dupN[A](n: Int, v : =>A): Seq[A] = { lazy val neededV = v for( i <- 1 to N) yield v }
  • 30. Scala. Scala / Dotty : like grand unification theory for large subset of type theories. Mathematical jargon hide quite simple patterns. Questions ? // ruslan@shevchenko.kiev.ua