SlideShare a Scribd company logo
Scala’s	

Types of Types
bg = game @ http://www.swordandsworcery.com/

Konrad 'ktoso' Malawski	

Lambda Days 2014 @ Kraków
_@

Konrad `@ktosopl` Malawski

geecon.org	

Java.pl / KrakowScala.pl	

sckrk.com / meetup.com/Paper-Cup @ London	

GDGKrakow.pl 	

meetup.com/Lambda-Lounge-Krakow
Types
Types

“Implementation is an implementation detail.”	

~ ktoso
Types in Scala
Types in Scala
Types in Scala
Types are:	

!

static

class Robot!
class Human !
!
val human: Human = new Human!
val roman: Human = new Robot!
!
!
error: type mismatch;!
!
found
: Robot!
!
required: Human!
!
val robot: Human = new Robot!
!

^
Types in Scala
Types are:	

!

static
strong

var two = 2!
two = "two"!
!

error: type mismatch;!
found
: String("two")!
required: Int!
two = "two"!
^
Types in Scala
Types are:	

!

static
strong
inferred
!

val n = 2!
n.getClass.toString == "int"!
!
!
!class Human!
!val p = new Human!

p.getClass.toString == "class Human"
Types in Scala
Types are:	

!
val n: Int = 2

!

static
strong
inferred
annotated after :	


!
!

!
def add(a: Int, b: Int): Int!
Types with Traits
Types with Traits
Traits are:	

!

interfaces
!

implementation:	


trait HasName { !
def name: String!
}!
!
!

class Human extends HasName {!
def name = ""!
}
class Human(val name: String) !
extends HasName!
Types with Traits
Traits are:	

!

interfaces
with implementation
!

trait HasName { def name = "name" }!
!

object Human extends HasName!
!

Human.name == "name"!
Types with Traits
Traits are:	

!

interfaces
with implementation
can be “mixed in”

trait Robot!
trait Humanoid!
trait Lasers!
!

object X extends Robot !
with Humanoid!
with Lasers!
!

Multiple inheritance panic?!
Type linearization

trait Robot extends Lasers!
trait Humanoid!
trait Lasers

object X extends Robot !
with Humanoid!
with Lasers

// type linearization:!
X Robot Humanoid Lasers
// reverse!
X Lasers Humanoid Robot! !
!
// expand!
X Lasers Humanoid Robot Lasers
// right-keep-unique!
X Lasers Humanoid Robot Lasers!
X
Humanoid Robot Lasers
// add common!
X
Humanoid Robot Lasers Object Any
Type linearization

trait Robot extends Lasers!
trait Humanoid!
trait Lasers

object X extends Robot !
with Humanoid!
with Lasers

// don’t trust me, trust the compiler:!
import scala.reflect.runtime.universe._!
typeOf[X.type].baseClasses.map(_.name).mkString(“ extends ")!
!

// output:!
X extends Humanoid !
extends Robot extends Lasers !
extends Object extends Any!
Type linearization
reordered slightly
trait Robot extends Lasers!
trait Humanoid!
trait Lasers

object X extends Humanoid!
with Lasers!
with Robot

// type linearization:!
X Humanoid Lasers Robot
// reverse!
X Robot Lasers Humanoid! !
!
// expand!
X Robot Lasers Lasers Humanoid
// right-keep-unique!
X Robot Lasers Lasers Humanoid!
X Robot
Lasers Humanoid
// add common!
X Robot
Lasers Humanoid Object Any
Type linearization

trait Robot extends Lasers!
trait Humanoid!
trait Lasers

object X extends Humanoid!
with Lasers!
with Robot

// don’t trust me, trust the compiler:!
import scala.reflect.runtime.universe._!
typeOf[X.type].baseClasses.map(_.name).mkString(“ extends ")!
!

// output:!
X extends Robot !
extends Lasers extends Humanoid!
extends Object extends Any!
Type Refinement
Type Refinement
trait Human!
trait Robot

val human: Human = new Human {}!
val roman: Human = new Robot!
Type Refinement
trait Human!
trait Robot

val human: Human = new Human {}!
val roman: Human = new Robot with Human!

plain trait composition
type refinement

Waaah! 	

It’s a robot with human traits!
Compound Types
Compound Types
are	

intersections
of types
!
!
!
!
!

trait
def
}!
trait
def
}!

Openable {!
open()!
Closable {!
close()!
Compound Types
are	

intersections
!

!
!
!
!

open()

trait
def
}!
trait
def
}!

Openable {!
open()!
Closable {!
close()!

close()
Compound Types
are	

intersections
!

trait
def
}!
trait
def
}!

Openable {!
open()!
Closable {!
close()!

!
!
! def openAndClose(it: Openable with Closable) {!
it.open()
!
!

it.close()!
}
Compound Types
are	

intersections
!

trait
def
}!
trait
def
}!

Openable {!
open()!
Closable {!
close()!

!
!
! def openAndClose(it: Openable with Closable) {!
it.open()
!
!

it.close()!
}
Compound Types

this.type

trait
def
}!
trait
def
}!

Openable {!
open(): this.type!
Closable {!
close()!

!
!
!
def openAndClose(it: Openable with Closable) =!
!

it.open().close()
!

Type Parameters
!

Type Parameters	

[Type Variance]
!

Type Parameters	

[Type Variance]	

<: Type Bounds >:
Type Parameters
type constructor

class C[T]
type parameter
Type Variance

class C[T] // in-variant!
class C[+T] // co-variant!
class C[-T] // contra-variant!
Type Bounds (still variance)

class Parent!
class Bottom extends Parent!
!

Type Bounds	

!

Parent >: Bottom
Bottom <: Parent
Parent =:= Parent

// parent is “more” general!
// bottom is “less” general!
// parent is “equal” parent
Type Variance
class C[T]

// in-variant

val x: C[Parent] = new C[Parent]!
!

val x: C[Parent] = new C[Bottom]!
error: type mismatch; found: C[Bottom] required: C[Parent]!
Note: Bottom <: Parent, but class C is invariant in type A.!
You may wish to define A as +A instead. (SLS 4.5)!
!

val x: C[Bottom] = new C[Parent]!
error: type mismatch; found: C[Parent] required: C[Bottom]!
Note: Parent >: Bottom, but class C is invariant in type A.!
You may wish to define A as -A instead. (SLS 4.5)!
Type Variance
class C[+T]

// co-variant

val x: C[Parent] = new C[Parent]!
!

val x: C[Parent] = new C[Bottom]!
!

val x: C[Bottom] = new C[Parent]!
error: type mismatch; found: C[Parent] required: C[Bottom]!
!
!
Type Variance
class C[-T]

// contra-variant

val x: C[Parent] = new C[Parent]!
!

val x: C[Parent] = new C[Bottom]!
error: type mismatch; found: C[Bottom] required: C[Parent]!
!

val x: C[Bottom] = new C[Parent]!
!
!
Structural Type
Structural Types

// a type!
class Closeable {!
def close()!
}

=>

// structural type!
type Closeable = {!
def close()!
}
Structural Types
Kinda’ like “duck typing”

def send(msg: String, box: {def receive(a: String)}) =!
box receive msg

structural type
Structural Types
type alias
type MailBoxLike = { !
def receive(a: String)!
}
def send(msg: String, box: MailboxLike) =!
box receive msg
Structural Types

type MailBoxLike = { !
def receive(a: String)!
}
def send(msg: String, box: MailboxLike) =!
box receive msg
object Home { def receive(a: String) = ??? }!
object Work { def receive(a: String) = ??? }
send("hello at home", Home)!
send("hello at work", Work)
Type Member
Type Member
Same goal as	

Type Parameter
if List was using Type Params
trait StringList!
extends List[String]

=>

trait StringList !
extends List {!
type A = String!
}

if List was using Type Members
Type Member + Type Bound
Same as + / - variance
trait List {!
type A!
}

=>

trait NumbersList extends List {!
type A <: Number!
}

trait IntegerList extends NumbersList {!
type A = Integer!
}
trait FailList extends NumbersList {!
type A = Human // Human is not <: Number!!
}
Type Alias
Without Type Alias
“1st” and “2nd” type param
ALL HOPE IS LOST!
object `bytes -> string` !
extends Builder[Array[Byte], String] {!
!
def make(in: Array[Byte]): String = new String(in)!
}!
Without Type Alias
“1st” and “2nd” type param
Some meaning is lost!
object `bytes -> string` !
extends Builder[Array[Byte], String] {!
!
def make(in: Array[Byte]): String = new String(in)!
}!
Type Alias
From Type Parameter to Type Members

trait Builder[From, To]

=>

trait Builder {!
type From!
type To!
def make(in: From): To!
}
Type Alias

trait Builder { type From; type To; def make(in: From): To }!
trait StringBuilder extends Builder {!
type To = String!
}
trait FromBytesBuilder extends Builder {!
type From = Array[Byte]!
}
object `bytes -> string` extends Builder!
with FromBytesBuilder!
with StringBuilder {!
!
def make(in: From): To = new String(in)!
}!
Type Alias

trait Builder { type From; type To; def make(in: From): To }!

object `bytes -> string` extends Builder {!
type From = Array[Bytes]!
type To = String!
!

def make(in: From): To = new String(in)!
}!
Phantom Types
Phantom Types

Phantom Types are never actually instanciated.

Exactly!

uhm… where are they?
Phantom Types
Marker traits:
sealed trait DoorState!
final class Open
extends DoorState!
final class Closed extends DoorState!
Phantom Types
Marker traits:
sealed trait DoorState!
final class Open
extends DoorState!
final class Closed extends DoorState!

trait Door[State <: DoorState] {!
!

def open[T >: State <: Closed](): Door[Open] !
!
!

def close[T >: State <: Open](): Door[Closed]!
!

}!
!
Phantom Types
Only slide in this talk with implementation!

class Door[State <: DoorState] private () {!
!

def open[T >: State <: Closed]() = !
this.asInstanceOf[Door[Open]]!
!

def close[T >: State <: Open]() =
this.asInstanceOf[Door[Closed]]!

!

}!
!

object Door { def apply() = new Door[Closed] }
Phantom Types
Marker traits:
sealed trait DoorState!
final class Open
extends DoorState!
final class Closed extends DoorState!

class Door[State <: DoorState] private () {!
!

def open[T >: State <: Closed]() = !
this.asInstanceOf[Door[Open]]!
!

def stop[T >: State <: Open]() =
!
this.asInstanceOf[Door[Closed]]!
}!
!

object Door { def apply() = new Door[Closed] }
Phantom Types
Marker traits:
sealed trait DoorState!
final class Open
extends DoorState!
final class Closed extends DoorState!

class Door[State <: DoorState] private () {!
!

def open[T >: State <: Closed]() = !
this.asInstanceOf[Door[Open]]!
!

def stop[T >: State <: Open]() =
!
this.asInstanceOf[Door[Closed]]!
}!
!

object Door { def apply() = new Door[Closed] }
Phantom Types
Marker traits:
sealed trait DoorState!
final class Open
extends DoorState!
final class Closed extends DoorState!

class Door[State <: DoorState] private () {!
!

def open[T >: State <: Closed]() = !
this.asInstanceOf[Door[Open]]!
!

def stop[T >: State <: Open]() =
!
this.asInstanceOf[Door[Closed]]!
}!
!

object Door { def apply() = new Door[Closed] }
Phantom Types
Marker traits:
sealed trait DoorState!
final class Open
extends DoorState!
final class Closed extends DoorState!

class Door[State <: DoorState] private () {!
!

def open[T >: State <: Closed]() = !
this.asInstanceOf[Door[Open]]!
!

def stop[T >: State <: Open]() =
!
this.asInstanceOf[Door[Closed]]!
}!
!

object Door { def apply() = new Door[Closed] }
Phantom Types
val closed = Door()!
// closed: Door[Closed]
Phantom Types
val closed = Door()!
// closed: Door[Closed]!
!

val opened = closed.open()!
// opened: Door[Open]
Phantom Types
val closed = Door()!
// closed: Door[Closed]!
!

val opened = closed.open()!
// opened: Door[Open]!
!

val closedAgain = opened.close()!
// closedAgain: Door[Closed]!
Phantom Types
val closed = Door()!
// closed: Door[Closed]!
!

val opened = closed.open()!
// opened: Door[Open]!
!

val closedAgain = opened.close()!
// closedAgain: Door[Closed]!
!

closed.close()!
error: type arguments [Closed] do not conform to method
close's type parameter bounds [T >: Closed <: Open]
Phantom Types
val closed = Door()!
// closed: Door[Closed]!
!

val opened = closed.open()!
// opened: Door[Open]!
!

val closedAgain = opened.close()!
// closedAgain: Door[Closed]!
!

closed.close()!
error: type arguments [Closed] do not conform to method
close's type parameter bounds [T >: Closed <: Open]!
!

opened.open()!
error: type arguments [Open] do not conform to method !
open's type parameter bounds [T >: Open <: Closed]
Higher Kinded Types
Kind:

x
Proper Kind
Int!

scala> :kind -v 42!
!

scala.Int's kind is A!
*!
!

This is a proper type.
Kind: x -> x
Type Constructor
List[+A]!

scala> :kind -v List!
!

scala.collection.immutable.List's kind is F[+A]!
* -(+)-> *!
!

This is a type constructor: !
a 1st-order-kinded type.
Kind:

(x -> x) -> x
Higher Kind
import language.higherKinds!
!
class Functor[M[_]]!

scala> :kind -v Functor[List]!
!

Functor's kind is X[F[A]]!
(* -> *) -> *!
!

This is a type constructor that takes type constructor(s): !
a higher-kinded type
Higher Kinded Types

import scala.language.higherKinds!
!

takes Type Constructor

trait Functor [F[_]] {!
def map[A,B] (fn: A => B)(fa: F[A]): F[B]!
}
Higher Kinded Types
import scala.language.higherKinds!
!

trait Functor [F[_]] {!
def map[A,B] (fn: A => B)(fa: F[A]): F[B]!
}

trait Functor [List] {!
def map[Int,String] (fn: Int => String)!
(fa: List[Int]): List[String]!
}
Higher Kinded Types
import scala.language.higherKinds!
!

trait Functor [F[_]] {!
def map[A,B] (fn: A => B)(fa: F[A]): F[B]!
}

val funct = new Functor[List] {!
def map[String, Int] !
(f: String => Int)!
(fa: List[String])!
: List[Int] = fa map f // cheating ;-)!
}
Higher Kinded Types
import scala.language.higherKinds!
!

trait Functor [F[_]] {!
def map[A,B] (fn: A => B)(fa: F[A]): F[B]!
}
val funct = new Functor[List] {!
def map[String, Int] !
(f: String => Int)!
(fa: List[String]): List[Int] = !
! ! !!!
fa map f // cheating ;-)!
}
val f: Int => String = _.toString!
funct.map(f)(List(1, 2)) == List("1", "2")!
Power up: Ad-Hoc Polymorphism
trait Container[M[_]] { !
def put[A](x: A): M[A]; def get[A](m: M[A]): A !
}!
implicit val listContainer = new Container[List] { !
def put[A](x: A) = List(x)!
def get[A](m: List[A]) = m.head !
}!
!

implicit val optionContainer = new Container[Some] {!
def put[A](x: A) = Some(x);!
def get[A](m: Some[A]) = m.get !
}!
Power up: Ad-Hoc Polymorphism
trait Container[M[_]] { !
def put[A](x: A): M[A]; def get[A](m: M[A]): A !
}!

def tupleize[M[_]: Container, A, B]!
(fst: M[A], snd: M[B]) !
(implicit c: Container[M]): M[(A, B)] =
c.put(c.get(fst), c.get(snd))
tupleize(Some(1), Some(2))!
Some((1,2)): Some[(Int, Int)]!
!

tupleize(List(1), List(“2”))!
List((1,2)): List[(Int, String)]!
Power up: Ad-Hoc Polymorphism
trait Container[M[_]] { !
def put[A](x: A): M[A]; def get[A](m: M[A]): A !
}!

def tupleize[M[_]: Container, A, B]!
(fst: M[A], snd: M[B]) !
(implicit c: Container[M]): M[(A, B)] =
c.put(c.get(fst), c.get(snd))
tupleize(Some(1), Some(2))!
Some((1,2)): Some[(Int, Int)]!
!

tupleize(List(1), List(“2”))!
List((1,2)): List[(Int, String)]!
Type Class
Type Class	

A.K.A. “ad-hoc polymorphism”
Type Class	

A.K.A. “More pattern, than type”
Type Class	

A.K.A. “Stay in this room”
Type Class	

A.K.A. “Stay in this room”	

Jerzy has an entire talk about them
Type Class

// no type classes yet!
trait Writeable[Out] {!
def write: Out!
}!
!

case class Num(a: Int, b: Int) extends Writeable[Json] {!
def write = Json.toJson(this)!
}!
Type Class
trait Writes[In, Out] {
def write(in: In): Out!
}!
!
!

Separated “what” from “who”

trait Writeable[Self] {
def writeAs[Out]()!
(implicit writes: Writes[Self, Out]): Out =!
! ! ! !
writes write this!
}!
!
!
!
implicit val jsonNum = Writes[Num, Json] {!
! def write(n: Num) = Json.toJson(n)!
!
}!
!

case class Num(a: Int) extends Writeable[Num]
Type Class
trait Writes[In, Out] {
def write(in: In): Out!
}!
!
!

trait Writeable[Self] {
def writeAs[Out]()!
(implicit writes: Writes[Self, Out]): Out =!
! ! ! !
writes write this!
}!

Implicit parameter

!
!
!
implicit val jsonNum = Writes[Num, Json] {!
! def write(n: Num) = Json.toJson(n)!
!
}!
!

Implicit value

case class Num(a: Int) extends Writeable[Num]
Type Class
implicit val jsonNum = Writes[Num, Json] {
def (n1: Num, n2: Num) = n1.a < n1.!
}!
!

case class Num(a: Int) extends Writeable[Num]
Type Class
implicit val jsonNum = Writes[Num, Json] {
def (n1: Num, n2: Num) = n1.a < n1.!
}!
!

case class Num(a: Int) extends Writeable[Num]

you write:
val jsonNum = Num(12).writeAs[Json]()!
Type Class
implicit val jsonNum = Writes[Num, Json] {
def (n1: Num, n2: Num) = n1.a < n1.!
}!
!

case class Num(a: Int) extends Writeable[Num]

you write:
val jsonNum = Num(12).writeAs[Json]()!

compiler does:
val jsonNum = Num(12).writeAs[Json]()(jsonNum)!
Links & Kudos
ktoso/scala-types-of-types @ github

12444 words and growing
Other Types of Types

type annotation	

case class	

type projection 	

unified type system	

value class	

self recursive type	

bottom types	

type class	

type constructor 	

type variance	

universal trait	

specialized type	

traits	

self type annotation	

dynamic type	

type refinements	

phantom type	

existential type	

type alias	

structural type	

type lambda	

abstract type member	

 path dependent type	

 algebraic data type
Links and Kudos
http://docs.scala-lang.org/
!
http://ktoso.github.io/scala-types-of-types/	

!
!
http://blog.echo.sh/post/68636331334/experimenting-with-peano-numbers-on-scalas-type-system-1	

!
http://stackoverflow.com/questions/6246719/what-is-a-higher-kinded-type-in-scala	

!
http://twitter.github.io/scala_school/advanced-types.html	

!
https://github.com/earldouglas/scala-scratchpad/tree/master/type-lambdas	

!
http://www.scala-lang.org/old/node/136	

!
http://eed3si9n.com/learning-scalaz/polymorphism.html	

!
!
!
Dziękuję!
Thank you!
あろがとう!

(guess “type” occurrences)

K.Malawski @ ebay.com
Konrad.Malwski @ geecon.org
t: ktosopl / g: ktoso
blog: project13.pl

Lambda Days 2014 @ Kraków
Ad

More Related Content

What's hot (20)

SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.
Ruslan Shevchenko
 
07. haskell Membership
07. haskell Membership07. haskell Membership
07. haskell Membership
Sebastian Rettig
 
Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
Kazunobu Tasaka
 
More expressive types for spark with frameless
More expressive types for spark with framelessMore expressive types for spark with frameless
More expressive types for spark with frameless
Miguel Pérez Pasalodos
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
Alfonso Ruzafa
 
Practically Functional
Practically FunctionalPractically Functional
Practically Functional
djspiewak
 
Introduction to Swift 2
Introduction to Swift 2Introduction to Swift 2
Introduction to Swift 2
Joris Timmerman
 
JavaScript Data Types
JavaScript Data TypesJavaScript Data Types
JavaScript Data Types
Charles Russell
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1
Mukesh Kumar
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
Kazunobu Tasaka
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
Isaias Barroso
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
Tomer Gabel
 
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
Skills Matter
 
From android/java to swift (1)
From android/java to swift (1)From android/java to swift (1)
From android/java to swift (1)
allanh0526
 
Scala Intro
Scala IntroScala Intro
Scala Intro
Alexey (Mr_Mig) Migutsky
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
Tomer Gabel
 
Intermediate JavaScript
Intermediate JavaScriptIntermediate JavaScript
Intermediate JavaScript
☆ Milan Adamovsky ☆
 
Csharp_mahesh
Csharp_maheshCsharp_mahesh
Csharp_mahesh
Ananthu Mahesh
 
Typeclasses
TypeclassesTypeclasses
Typeclasses
ekalyoncu
 
What can scala puzzlers teach us
What can scala puzzlers teach usWhat can scala puzzlers teach us
What can scala puzzlers teach us
Daniel Sobral
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.
Ruslan Shevchenko
 
More expressive types for spark with frameless
More expressive types for spark with framelessMore expressive types for spark with frameless
More expressive types for spark with frameless
Miguel Pérez Pasalodos
 
Practically Functional
Practically FunctionalPractically Functional
Practically Functional
djspiewak
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1
Mukesh Kumar
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
Kazunobu Tasaka
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
Isaias Barroso
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
Tomer Gabel
 
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
Skills Matter
 
From android/java to swift (1)
From android/java to swift (1)From android/java to swift (1)
From android/java to swift (1)
allanh0526
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
Tomer Gabel
 
What can scala puzzlers teach us
What can scala puzzlers teach usWhat can scala puzzlers teach us
What can scala puzzlers teach us
Daniel Sobral
 

Viewers also liked (20)

Real-World Scala Design Patterns
Real-World Scala Design PatternsReal-World Scala Design Patterns
Real-World Scala Design Patterns
NLJUG
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
Mudasir Qazi
 
Artigo igala
Artigo igalaArtigo igala
Artigo igala
Caroline Chioquetta Lorenset
 
The Scottish Information Literacy Project
The Scottish Information Literacy ProjectThe Scottish Information Literacy Project
The Scottish Information Literacy Project
guest9f3d11
 
Functional Programming and Concurrency Patterns in Scala
Functional Programming and Concurrency Patterns in ScalaFunctional Programming and Concurrency Patterns in Scala
Functional Programming and Concurrency Patterns in Scala
kellogh
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming Patterns
Vasil Remeniuk
 
Type Parameterization
Type ParameterizationType Parameterization
Type Parameterization
Knoldus Inc.
 
Effective Programming In Scala
Effective Programming In ScalaEffective Programming In Scala
Effective Programming In Scala
Harsh Sharma
 
Scala collections
Scala collectionsScala collections
Scala collections
Inphina Technologies
 
Simple Scala DSLs
Simple Scala DSLsSimple Scala DSLs
Simple Scala DSLs
linxbetter
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scala
b0ris_1
 
Open soucerers - jak zacząć swoją przygodę z open source
Open soucerers - jak zacząć swoją przygodę z open sourceOpen soucerers - jak zacząć swoją przygodę z open source
Open soucerers - jak zacząć swoją przygodę z open source
Konrad Malawski
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
Konrad Malawski
 
The Eff monad, one monad to rule them all
The Eff monad, one monad to rule them allThe Eff monad, one monad to rule them all
The Eff monad, one monad to rule them all
Eric Torreborre
 
Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014
Konrad Malawski
 
HBase RowKey design for Akka Persistence
HBase RowKey design for Akka PersistenceHBase RowKey design for Akka Persistence
HBase RowKey design for Akka Persistence
Konrad Malawski
 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applications
Konrad Malawski
 
Scala’s implicits
Scala’s implicitsScala’s implicits
Scala’s implicits
Pablo Francisco Pérez Hidalgo
 
Ebay legacy-code-retreat
Ebay legacy-code-retreatEbay legacy-code-retreat
Ebay legacy-code-retreat
Konrad Malawski
 
Scala dsls-dissecting-and-implementing-rogue
Scala dsls-dissecting-and-implementing-rogueScala dsls-dissecting-and-implementing-rogue
Scala dsls-dissecting-and-implementing-rogue
Konrad Malawski
 
Real-World Scala Design Patterns
Real-World Scala Design PatternsReal-World Scala Design Patterns
Real-World Scala Design Patterns
NLJUG
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
Mudasir Qazi
 
The Scottish Information Literacy Project
The Scottish Information Literacy ProjectThe Scottish Information Literacy Project
The Scottish Information Literacy Project
guest9f3d11
 
Functional Programming and Concurrency Patterns in Scala
Functional Programming and Concurrency Patterns in ScalaFunctional Programming and Concurrency Patterns in Scala
Functional Programming and Concurrency Patterns in Scala
kellogh
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming Patterns
Vasil Remeniuk
 
Type Parameterization
Type ParameterizationType Parameterization
Type Parameterization
Knoldus Inc.
 
Effective Programming In Scala
Effective Programming In ScalaEffective Programming In Scala
Effective Programming In Scala
Harsh Sharma
 
Simple Scala DSLs
Simple Scala DSLsSimple Scala DSLs
Simple Scala DSLs
linxbetter
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scala
b0ris_1
 
Open soucerers - jak zacząć swoją przygodę z open source
Open soucerers - jak zacząć swoją przygodę z open sourceOpen soucerers - jak zacząć swoją przygodę z open source
Open soucerers - jak zacząć swoją przygodę z open source
Konrad Malawski
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
Konrad Malawski
 
The Eff monad, one monad to rule them all
The Eff monad, one monad to rule them allThe Eff monad, one monad to rule them all
The Eff monad, one monad to rule them all
Eric Torreborre
 
Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014
Konrad Malawski
 
HBase RowKey design for Akka Persistence
HBase RowKey design for Akka PersistenceHBase RowKey design for Akka Persistence
HBase RowKey design for Akka Persistence
Konrad Malawski
 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applications
Konrad Malawski
 
Ebay legacy-code-retreat
Ebay legacy-code-retreatEbay legacy-code-retreat
Ebay legacy-code-retreat
Konrad Malawski
 
Scala dsls-dissecting-and-implementing-rogue
Scala dsls-dissecting-and-implementing-rogueScala dsls-dissecting-and-implementing-rogue
Scala dsls-dissecting-and-implementing-rogue
Konrad Malawski
 
Ad

Similar to Scala Types of Types @ Lambda Days (20)

RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!
Gautam Rege
 
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...
MongoDB
 
Scala Workshop
Scala WorkshopScala Workshop
Scala Workshop
Clueda AG
 
42.type: Literal-based Singleton types
42.type: Literal-based Singleton types42.type: Literal-based Singleton types
42.type: Literal-based Singleton types
George Leontiev
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
Aleš Najmann
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
Konrad Malawski
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
Garth Gilmour
 
scala reloaded
scala reloadedscala reloaded
scala reloaded
Mac Liaw
 
Gunosy.go#7 reflect
Gunosy.go#7 reflectGunosy.go#7 reflect
Gunosy.go#7 reflect
Taku Fukushima
 
Inheritance
InheritanceInheritance
Inheritance
Sardar Alam
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Heiko Behrens
 
Intermediate Swift Language by Apple
Intermediate Swift Language by AppleIntermediate Swift Language by Apple
Intermediate Swift Language by Apple
jamesfeng2
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
KennyPratheepKumar
 
Java/Scala Lab 2016. Руслан Шевченко: Несколько трюков scala-разработки, приг...
Java/Scala Lab 2016. Руслан Шевченко: Несколько трюков scala-разработки, приг...Java/Scala Lab 2016. Руслан Шевченко: Несколько трюков scala-разработки, приг...
Java/Scala Lab 2016. Руслан Шевченко: Несколько трюков scala-разработки, приг...
GeeksLab Odessa
 
How would you describe Swift in three words?
How would you describe Swift in three words?How would you describe Swift in three words?
How would you describe Swift in three words?
Colin Eberhardt
 
Milano JS Meetup - Gabriele Petronella - Codemotion Milan 2016
Milano JS Meetup -  Gabriele Petronella - Codemotion Milan 2016Milano JS Meetup -  Gabriele Petronella - Codemotion Milan 2016
Milano JS Meetup - Gabriele Petronella - Codemotion Milan 2016
Codemotion
 
C# basics
 C# basics C# basics
C# basics
Dinesh kumar
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)
Igor Khotin
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practices
Iwan van der Kleijn
 
RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!
Gautam Rege
 
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...
MongoDB World 2019: BSON Transpilers: Transpiling from Any Language to Any La...
MongoDB
 
Scala Workshop
Scala WorkshopScala Workshop
Scala Workshop
Clueda AG
 
42.type: Literal-based Singleton types
42.type: Literal-based Singleton types42.type: Literal-based Singleton types
42.type: Literal-based Singleton types
George Leontiev
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
Aleš Najmann
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
Konrad Malawski
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
Garth Gilmour
 
scala reloaded
scala reloadedscala reloaded
scala reloaded
Mac Liaw
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Heiko Behrens
 
Intermediate Swift Language by Apple
Intermediate Swift Language by AppleIntermediate Swift Language by Apple
Intermediate Swift Language by Apple
jamesfeng2
 
Java/Scala Lab 2016. Руслан Шевченко: Несколько трюков scala-разработки, приг...
Java/Scala Lab 2016. Руслан Шевченко: Несколько трюков scala-разработки, приг...Java/Scala Lab 2016. Руслан Шевченко: Несколько трюков scala-разработки, приг...
Java/Scala Lab 2016. Руслан Шевченко: Несколько трюков scala-разработки, приг...
GeeksLab Odessa
 
How would you describe Swift in three words?
How would you describe Swift in three words?How would you describe Swift in three words?
How would you describe Swift in three words?
Colin Eberhardt
 
Milano JS Meetup - Gabriele Petronella - Codemotion Milan 2016
Milano JS Meetup -  Gabriele Petronella - Codemotion Milan 2016Milano JS Meetup -  Gabriele Petronella - Codemotion Milan 2016
Milano JS Meetup - Gabriele Petronella - Codemotion Milan 2016
Codemotion
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)
Igor Khotin
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practices
Iwan van der Kleijn
 
Ad

More from Konrad Malawski (20)

Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Konrad Malawski
 
Akka Typed (quick talk) - JFokus 2018
Akka Typed (quick talk) - JFokus 2018Akka Typed (quick talk) - JFokus 2018
Akka Typed (quick talk) - JFokus 2018
Konrad Malawski
 
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in'tScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
Konrad Malawski
 
State of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to comeState of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to come
Konrad Malawski
 
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCBuilding a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Konrad Malawski
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming World
Konrad Malawski
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka Streams
Konrad Malawski
 
Not Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsNot Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabs
Konrad Malawski
 
Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!
Konrad Malawski
 
End to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to SocketEnd to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to Socket
Konrad Malawski
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
Konrad Malawski
 
Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016
Konrad Malawski
 
Krakow communities @ 2016
Krakow communities @ 2016Krakow communities @ 2016
Krakow communities @ 2016
Konrad Malawski
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and Akka
Konrad Malawski
 
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
Konrad Malawski
 
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
Konrad Malawski
 
Zen of Akka
Zen of AkkaZen of Akka
Zen of Akka
Konrad Malawski
 
How Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemHow Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM Ecosystem
Konrad Malawski
 
The Need for Async @ ScalaWorld
The Need for Async @ ScalaWorldThe Need for Async @ ScalaWorld
The Need for Async @ ScalaWorld
Konrad Malawski
 
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka StreamsFresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Konrad Malawski
 
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Konrad Malawski
 
Akka Typed (quick talk) - JFokus 2018
Akka Typed (quick talk) - JFokus 2018Akka Typed (quick talk) - JFokus 2018
Akka Typed (quick talk) - JFokus 2018
Konrad Malawski
 
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in'tScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
Konrad Malawski
 
State of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to comeState of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to come
Konrad Malawski
 
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCBuilding a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Konrad Malawski
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming World
Konrad Malawski
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka Streams
Konrad Malawski
 
Not Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsNot Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabs
Konrad Malawski
 
Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!
Konrad Malawski
 
End to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to SocketEnd to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to Socket
Konrad Malawski
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
Konrad Malawski
 
Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016
Konrad Malawski
 
Krakow communities @ 2016
Krakow communities @ 2016Krakow communities @ 2016
Krakow communities @ 2016
Konrad Malawski
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and Akka
Konrad Malawski
 
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
Konrad Malawski
 
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
Konrad Malawski
 
How Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemHow Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM Ecosystem
Konrad Malawski
 
The Need for Async @ ScalaWorld
The Need for Async @ ScalaWorldThe Need for Async @ ScalaWorld
The Need for Async @ ScalaWorld
Konrad Malawski
 
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka StreamsFresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Konrad Malawski
 

Recently uploaded (20)

Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Top 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing ServicesTop 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing Services
Infrassist Technologies Pvt. Ltd.
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 

Scala Types of Types @ Lambda Days

  • 1. Scala’s Types of Types bg = game @ http://www.swordandsworcery.com/ Konrad 'ktoso' Malawski Lambda Days 2014 @ Kraków
  • 2. _@ Konrad `@ktosopl` Malawski geecon.org Java.pl / KrakowScala.pl sckrk.com / meetup.com/Paper-Cup @ London GDGKrakow.pl meetup.com/Lambda-Lounge-Krakow
  • 4. Types “Implementation is an implementation detail.” ~ ktoso
  • 7. Types in Scala Types are: ! static class Robot! class Human ! ! val human: Human = new Human! val roman: Human = new Robot! ! ! error: type mismatch;! ! found : Robot! ! required: Human! ! val robot: Human = new Robot! ! ^
  • 8. Types in Scala Types are: ! static strong var two = 2! two = "two"! ! error: type mismatch;! found : String("two")! required: Int! two = "two"! ^
  • 9. Types in Scala Types are: ! static strong inferred ! val n = 2! n.getClass.toString == "int"! ! ! !class Human! !val p = new Human! p.getClass.toString == "class Human"
  • 10. Types in Scala Types are: ! val n: Int = 2 ! static strong inferred annotated after : ! ! ! def add(a: Int, b: Int): Int!
  • 12. Types with Traits Traits are: ! interfaces ! implementation: trait HasName { ! def name: String! }! ! ! class Human extends HasName {! def name = ""! } class Human(val name: String) ! extends HasName!
  • 13. Types with Traits Traits are: ! interfaces with implementation ! trait HasName { def name = "name" }! ! object Human extends HasName! ! Human.name == "name"!
  • 14. Types with Traits Traits are: ! interfaces with implementation can be “mixed in” trait Robot! trait Humanoid! trait Lasers! ! object X extends Robot ! with Humanoid! with Lasers! ! Multiple inheritance panic?!
  • 15. Type linearization trait Robot extends Lasers! trait Humanoid! trait Lasers object X extends Robot ! with Humanoid! with Lasers // type linearization:! X Robot Humanoid Lasers // reverse! X Lasers Humanoid Robot! ! ! // expand! X Lasers Humanoid Robot Lasers // right-keep-unique! X Lasers Humanoid Robot Lasers! X Humanoid Robot Lasers // add common! X Humanoid Robot Lasers Object Any
  • 16. Type linearization trait Robot extends Lasers! trait Humanoid! trait Lasers object X extends Robot ! with Humanoid! with Lasers // don’t trust me, trust the compiler:! import scala.reflect.runtime.universe._! typeOf[X.type].baseClasses.map(_.name).mkString(“ extends ")! ! // output:! X extends Humanoid ! extends Robot extends Lasers ! extends Object extends Any!
  • 17. Type linearization reordered slightly trait Robot extends Lasers! trait Humanoid! trait Lasers object X extends Humanoid! with Lasers! with Robot // type linearization:! X Humanoid Lasers Robot // reverse! X Robot Lasers Humanoid! ! ! // expand! X Robot Lasers Lasers Humanoid // right-keep-unique! X Robot Lasers Lasers Humanoid! X Robot Lasers Humanoid // add common! X Robot Lasers Humanoid Object Any
  • 18. Type linearization trait Robot extends Lasers! trait Humanoid! trait Lasers object X extends Humanoid! with Lasers! with Robot // don’t trust me, trust the compiler:! import scala.reflect.runtime.universe._! typeOf[X.type].baseClasses.map(_.name).mkString(“ extends ")! ! // output:! X extends Robot ! extends Lasers extends Humanoid! extends Object extends Any!
  • 20. Type Refinement trait Human! trait Robot val human: Human = new Human {}! val roman: Human = new Robot!
  • 21. Type Refinement trait Human! trait Robot val human: Human = new Human {}! val roman: Human = new Robot with Human! plain trait composition type refinement Waaah! It’s a robot with human traits!
  • 25. Compound Types are intersections ! trait def }! trait def }! Openable {! open()! Closable {! close()! ! ! ! def openAndClose(it: Openable with Closable) {! it.open() ! ! it.close()! }
  • 26. Compound Types are intersections ! trait def }! trait def }! Openable {! open()! Closable {! close()! ! ! ! def openAndClose(it: Openable with Closable) {! it.open() ! ! it.close()! }
  • 27. Compound Types this.type trait def }! trait def }! Openable {! open(): this.type! Closable {! close()! ! ! ! def openAndClose(it: Openable with Closable) =! ! it.open().close()
  • 32. Type Variance class C[T] // in-variant! class C[+T] // co-variant! class C[-T] // contra-variant!
  • 33. Type Bounds (still variance) class Parent! class Bottom extends Parent! ! Type Bounds ! Parent >: Bottom Bottom <: Parent Parent =:= Parent // parent is “more” general! // bottom is “less” general! // parent is “equal” parent
  • 34. Type Variance class C[T] // in-variant val x: C[Parent] = new C[Parent]! ! val x: C[Parent] = new C[Bottom]! error: type mismatch; found: C[Bottom] required: C[Parent]! Note: Bottom <: Parent, but class C is invariant in type A.! You may wish to define A as +A instead. (SLS 4.5)! ! val x: C[Bottom] = new C[Parent]! error: type mismatch; found: C[Parent] required: C[Bottom]! Note: Parent >: Bottom, but class C is invariant in type A.! You may wish to define A as -A instead. (SLS 4.5)!
  • 35. Type Variance class C[+T] // co-variant val x: C[Parent] = new C[Parent]! ! val x: C[Parent] = new C[Bottom]! ! val x: C[Bottom] = new C[Parent]! error: type mismatch; found: C[Parent] required: C[Bottom]! ! !
  • 36. Type Variance class C[-T] // contra-variant val x: C[Parent] = new C[Parent]! ! val x: C[Parent] = new C[Bottom]! error: type mismatch; found: C[Bottom] required: C[Parent]! ! val x: C[Bottom] = new C[Parent]! ! !
  • 38. Structural Types // a type! class Closeable {! def close()! } => // structural type! type Closeable = {! def close()! }
  • 39. Structural Types Kinda’ like “duck typing” def send(msg: String, box: {def receive(a: String)}) =! box receive msg structural type
  • 40. Structural Types type alias type MailBoxLike = { ! def receive(a: String)! } def send(msg: String, box: MailboxLike) =! box receive msg
  • 41. Structural Types type MailBoxLike = { ! def receive(a: String)! } def send(msg: String, box: MailboxLike) =! box receive msg object Home { def receive(a: String) = ??? }! object Work { def receive(a: String) = ??? } send("hello at home", Home)! send("hello at work", Work)
  • 43. Type Member Same goal as Type Parameter if List was using Type Params trait StringList! extends List[String] => trait StringList ! extends List {! type A = String! } if List was using Type Members
  • 44. Type Member + Type Bound Same as + / - variance trait List {! type A! } => trait NumbersList extends List {! type A <: Number! } trait IntegerList extends NumbersList {! type A = Integer! } trait FailList extends NumbersList {! type A = Human // Human is not <: Number!! }
  • 46. Without Type Alias “1st” and “2nd” type param ALL HOPE IS LOST! object `bytes -> string` ! extends Builder[Array[Byte], String] {! ! def make(in: Array[Byte]): String = new String(in)! }!
  • 47. Without Type Alias “1st” and “2nd” type param Some meaning is lost! object `bytes -> string` ! extends Builder[Array[Byte], String] {! ! def make(in: Array[Byte]): String = new String(in)! }!
  • 48. Type Alias From Type Parameter to Type Members trait Builder[From, To] => trait Builder {! type From! type To! def make(in: From): To! }
  • 49. Type Alias trait Builder { type From; type To; def make(in: From): To }! trait StringBuilder extends Builder {! type To = String! } trait FromBytesBuilder extends Builder {! type From = Array[Byte]! } object `bytes -> string` extends Builder! with FromBytesBuilder! with StringBuilder {! ! def make(in: From): To = new String(in)! }!
  • 50. Type Alias trait Builder { type From; type To; def make(in: From): To }! object `bytes -> string` extends Builder {! type From = Array[Bytes]! type To = String! ! def make(in: From): To = new String(in)! }!
  • 52. Phantom Types Phantom Types are never actually instanciated. Exactly! uhm… where are they?
  • 53. Phantom Types Marker traits: sealed trait DoorState! final class Open extends DoorState! final class Closed extends DoorState!
  • 54. Phantom Types Marker traits: sealed trait DoorState! final class Open extends DoorState! final class Closed extends DoorState! trait Door[State <: DoorState] {! ! def open[T >: State <: Closed](): Door[Open] ! ! ! def close[T >: State <: Open](): Door[Closed]! ! }! !
  • 55. Phantom Types Only slide in this talk with implementation! class Door[State <: DoorState] private () {! ! def open[T >: State <: Closed]() = ! this.asInstanceOf[Door[Open]]! ! def close[T >: State <: Open]() = this.asInstanceOf[Door[Closed]]! ! }! ! object Door { def apply() = new Door[Closed] }
  • 56. Phantom Types Marker traits: sealed trait DoorState! final class Open extends DoorState! final class Closed extends DoorState! class Door[State <: DoorState] private () {! ! def open[T >: State <: Closed]() = ! this.asInstanceOf[Door[Open]]! ! def stop[T >: State <: Open]() = ! this.asInstanceOf[Door[Closed]]! }! ! object Door { def apply() = new Door[Closed] }
  • 57. Phantom Types Marker traits: sealed trait DoorState! final class Open extends DoorState! final class Closed extends DoorState! class Door[State <: DoorState] private () {! ! def open[T >: State <: Closed]() = ! this.asInstanceOf[Door[Open]]! ! def stop[T >: State <: Open]() = ! this.asInstanceOf[Door[Closed]]! }! ! object Door { def apply() = new Door[Closed] }
  • 58. Phantom Types Marker traits: sealed trait DoorState! final class Open extends DoorState! final class Closed extends DoorState! class Door[State <: DoorState] private () {! ! def open[T >: State <: Closed]() = ! this.asInstanceOf[Door[Open]]! ! def stop[T >: State <: Open]() = ! this.asInstanceOf[Door[Closed]]! }! ! object Door { def apply() = new Door[Closed] }
  • 59. Phantom Types Marker traits: sealed trait DoorState! final class Open extends DoorState! final class Closed extends DoorState! class Door[State <: DoorState] private () {! ! def open[T >: State <: Closed]() = ! this.asInstanceOf[Door[Open]]! ! def stop[T >: State <: Open]() = ! this.asInstanceOf[Door[Closed]]! }! ! object Door { def apply() = new Door[Closed] }
  • 60. Phantom Types val closed = Door()! // closed: Door[Closed]
  • 61. Phantom Types val closed = Door()! // closed: Door[Closed]! ! val opened = closed.open()! // opened: Door[Open]
  • 62. Phantom Types val closed = Door()! // closed: Door[Closed]! ! val opened = closed.open()! // opened: Door[Open]! ! val closedAgain = opened.close()! // closedAgain: Door[Closed]!
  • 63. Phantom Types val closed = Door()! // closed: Door[Closed]! ! val opened = closed.open()! // opened: Door[Open]! ! val closedAgain = opened.close()! // closedAgain: Door[Closed]! ! closed.close()! error: type arguments [Closed] do not conform to method close's type parameter bounds [T >: Closed <: Open]
  • 64. Phantom Types val closed = Door()! // closed: Door[Closed]! ! val opened = closed.open()! // opened: Door[Open]! ! val closedAgain = opened.close()! // closedAgain: Door[Closed]! ! closed.close()! error: type arguments [Closed] do not conform to method close's type parameter bounds [T >: Closed <: Open]! ! opened.open()! error: type arguments [Open] do not conform to method ! open's type parameter bounds [T >: Open <: Closed]
  • 66. Kind: x Proper Kind Int! scala> :kind -v 42! ! scala.Int's kind is A! *! ! This is a proper type.
  • 67. Kind: x -> x Type Constructor List[+A]! scala> :kind -v List! ! scala.collection.immutable.List's kind is F[+A]! * -(+)-> *! ! This is a type constructor: ! a 1st-order-kinded type.
  • 68. Kind: (x -> x) -> x Higher Kind import language.higherKinds! ! class Functor[M[_]]! scala> :kind -v Functor[List]! ! Functor's kind is X[F[A]]! (* -> *) -> *! ! This is a type constructor that takes type constructor(s): ! a higher-kinded type
  • 69. Higher Kinded Types import scala.language.higherKinds! ! takes Type Constructor trait Functor [F[_]] {! def map[A,B] (fn: A => B)(fa: F[A]): F[B]! }
  • 70. Higher Kinded Types import scala.language.higherKinds! ! trait Functor [F[_]] {! def map[A,B] (fn: A => B)(fa: F[A]): F[B]! } trait Functor [List] {! def map[Int,String] (fn: Int => String)! (fa: List[Int]): List[String]! }
  • 71. Higher Kinded Types import scala.language.higherKinds! ! trait Functor [F[_]] {! def map[A,B] (fn: A => B)(fa: F[A]): F[B]! } val funct = new Functor[List] {! def map[String, Int] ! (f: String => Int)! (fa: List[String])! : List[Int] = fa map f // cheating ;-)! }
  • 72. Higher Kinded Types import scala.language.higherKinds! ! trait Functor [F[_]] {! def map[A,B] (fn: A => B)(fa: F[A]): F[B]! } val funct = new Functor[List] {! def map[String, Int] ! (f: String => Int)! (fa: List[String]): List[Int] = ! ! ! !!! fa map f // cheating ;-)! } val f: Int => String = _.toString! funct.map(f)(List(1, 2)) == List("1", "2")!
  • 73. Power up: Ad-Hoc Polymorphism trait Container[M[_]] { ! def put[A](x: A): M[A]; def get[A](m: M[A]): A ! }! implicit val listContainer = new Container[List] { ! def put[A](x: A) = List(x)! def get[A](m: List[A]) = m.head ! }! ! implicit val optionContainer = new Container[Some] {! def put[A](x: A) = Some(x);! def get[A](m: Some[A]) = m.get ! }!
  • 74. Power up: Ad-Hoc Polymorphism trait Container[M[_]] { ! def put[A](x: A): M[A]; def get[A](m: M[A]): A ! }! def tupleize[M[_]: Container, A, B]! (fst: M[A], snd: M[B]) ! (implicit c: Container[M]): M[(A, B)] = c.put(c.get(fst), c.get(snd)) tupleize(Some(1), Some(2))! Some((1,2)): Some[(Int, Int)]! ! tupleize(List(1), List(“2”))! List((1,2)): List[(Int, String)]!
  • 75. Power up: Ad-Hoc Polymorphism trait Container[M[_]] { ! def put[A](x: A): M[A]; def get[A](m: M[A]): A ! }! def tupleize[M[_]: Container, A, B]! (fst: M[A], snd: M[B]) ! (implicit c: Container[M]): M[(A, B)] = c.put(c.get(fst), c.get(snd)) tupleize(Some(1), Some(2))! Some((1,2)): Some[(Int, Int)]! ! tupleize(List(1), List(“2”))! List((1,2)): List[(Int, String)]!
  • 77. Type Class A.K.A. “ad-hoc polymorphism”
  • 78. Type Class A.K.A. “More pattern, than type”
  • 79. Type Class A.K.A. “Stay in this room”
  • 80. Type Class A.K.A. “Stay in this room” Jerzy has an entire talk about them
  • 81. Type Class // no type classes yet! trait Writeable[Out] {! def write: Out! }! ! case class Num(a: Int, b: Int) extends Writeable[Json] {! def write = Json.toJson(this)! }!
  • 82. Type Class trait Writes[In, Out] { def write(in: In): Out! }! ! ! Separated “what” from “who” trait Writeable[Self] { def writeAs[Out]()! (implicit writes: Writes[Self, Out]): Out =! ! ! ! ! writes write this! }! ! ! ! implicit val jsonNum = Writes[Num, Json] {! ! def write(n: Num) = Json.toJson(n)! ! }! ! case class Num(a: Int) extends Writeable[Num]
  • 83. Type Class trait Writes[In, Out] { def write(in: In): Out! }! ! ! trait Writeable[Self] { def writeAs[Out]()! (implicit writes: Writes[Self, Out]): Out =! ! ! ! ! writes write this! }! Implicit parameter ! ! ! implicit val jsonNum = Writes[Num, Json] {! ! def write(n: Num) = Json.toJson(n)! ! }! ! Implicit value case class Num(a: Int) extends Writeable[Num]
  • 84. Type Class implicit val jsonNum = Writes[Num, Json] { def (n1: Num, n2: Num) = n1.a < n1.! }! ! case class Num(a: Int) extends Writeable[Num]
  • 85. Type Class implicit val jsonNum = Writes[Num, Json] { def (n1: Num, n2: Num) = n1.a < n1.! }! ! case class Num(a: Int) extends Writeable[Num] you write: val jsonNum = Num(12).writeAs[Json]()!
  • 86. Type Class implicit val jsonNum = Writes[Num, Json] { def (n1: Num, n2: Num) = n1.a < n1.! }! ! case class Num(a: Int) extends Writeable[Num] you write: val jsonNum = Num(12).writeAs[Json]()! compiler does: val jsonNum = Num(12).writeAs[Json]()(jsonNum)!
  • 89. Other Types of Types type annotation case class type projection unified type system value class self recursive type bottom types type class type constructor type variance universal trait specialized type traits self type annotation dynamic type type refinements phantom type existential type type alias structural type type lambda abstract type member path dependent type algebraic data type
  • 91. Dziękuję! Thank you! あろがとう! (guess “type” occurrences) K.Malawski @ ebay.com Konrad.Malwski @ geecon.org t: ktosopl / g: ktoso blog: project13.pl Lambda Days 2014 @ Kraków