SlideShare a Scribd company logo
1 of 40
Download to read offline
Wix R&D meetup;
CSP & Scala: theory and
implementation.
https://github.com/rssh/scala-gopher
Ruslan Shevchenko
<ruslan@shevchenko.kiev.ua>
https://github.com/rssh
@rssh1
2. Outline
❖ Theory & History
❖ CSP = Communication Sequence Processes
❖ !-calculus (CCS = Calculus of Communicating System)
❖ Languages: (Occam,Limbo, Go[Clojure, Scala, … ])
❖ Main constructions / idioms, how they looks
❖ Channels, Selectors, Transputers
❖ Implementation Techniques
3. Theory & History
❖ If you familiar with basic concepts, skip to slide 8
❖ Just show me scala API: skip to slide 14
4. Theory & History
❖ CPS = Communication Sequence Processes.
❖ CSS = Calculus of Communicating System.
❖ 1978 First CSP Paper by Tony Hoar.
❖ 1980. CSS by Robert Milner. (Algebraic Processes)
❖ 1985 CSP formalism (influenced by CSS) in CSP Book
❖ http://www.usingcsp.com/
❖ 1992 !-calculus [CSS + Channels] (Robert Milner, Joachim Parrow,
David Walker)
❖ …. (large family of Process Algebras, including Actor Model, ACP, )
5. CSP Notation(basic)
❖ (A, B, C … ) — processes,
❖ (x, y, z … ) — events
❖ atomic: x , STOP, BEEP, or c.v (channel/value)
❖ c!v - send v to channel c (after this c.v happens)
❖ c?v - receive v from channel c (wait until c.v)
❖ trace(…) — sequence of events.
6. CSP Notation(basic)
// after event
Operations on processes:
// fix point (loops, recursion
// interleave concurrently
// choice, if a then P if b then Q
// seq
7. CSP Notation(examples)
COPY(left,right)=
left right
P1 P2
Q1 Q2
P1 P2
Q1 Q2
8. Occam language
William Occam, 1287-1347
‘Occam razor’ principle
Occam language. (1983)
INT x, y:
SEQ
x := 4
y := (x + 1)
CHAN INT c:
PAR
some.procedure (x, y, c!)
another.procedure (c?)
y := 5
braces via indentation. (before python)
minimal language. (processor constructors)
9. Occam language
❖ created by INMOS
❖ targeted Transputers CHIP architecture (bare metal)
❖ latest dialect: occam-! [1996]
❖ extensions from !-calculus
❖ (more dynamic, channels can be send via channels)
❖ http://concurrency.cc — occam for Aurdino.
10. Inferno, Limbo, Go
❖ Unix, Plan9, Inferno: [At&t; Bell labs; vita nuova]
❖ http://www.vitanuova.com/inferno/
❖ Limbo … C-like language + channels + buffered channels.
❖ Go … channels as in Limbo (Go roots is from hell is not a metaphor)
Sean Forward
David Leo Presotto
Rob Pike
Dennis M. Ritchie
Ken Thompson
11. CPS in Limbo/Go/Scala: main constructions
❖ processes: operator for spawning new lightweight
process.
❖ channels: can be unbuffered (synchronised) or buffered
❖ unbuffered — writer wait until reader start to work
❖ buffered — if channel buffer is not full, writer not
blocked
❖ selector: wait for few events (channel), eval first.
12. Go: simple code example
func fibonacci(c chan int, quit chan bool) {
go {
x, y := 0, 1
for (){
select {
case c <- x :
x, y = y, x+y
case q<-quit:
break;
}
}
close(c)
}
}
c = make(chan int);
quit= make(chan bool);
fibonacci(c,quit)
for i := range c {
fmt.Println(i)
if (i > 2000) {
quit <- true
}
}
Go
13. Go: simple code example
func fibonacci(c chan int, quit chan bool) {
go {
x, y := 0, 1
for (){
select {
case c <- x :
x, y = y, x+y
case q<- quit:
break;
}
}
close(c)
}
}
c = make(chan int);
quit= make(chan bool);
fibonacci(c,quit)
for i := range c {
fmt.Println(i)
if (i > 2000) {
quit <- true
}
}
Go
14. scala-gopher
❖ Akka extension + Macros on top of SIP22-async
❖ Integrate CSP primitives and scala concurrency
❖ Provide:
❖ asynchronous API inside general control-flow
❖ pseudo-synchronous API inside go{ .. } or async{ ..}
blocks
def fibonacci(c: Channel[Int], quit: Channel[Boolean]): Future[Unit] = go {
var (x, y) = (0, 1)
select.forever{
case x : c.write =>
val z = x
x = y; y = x+z
case q: quit.read =>
CurrentFlowTermination.exit(())
}
c.close()
}
15. Scala: simple code example (direct translation)
val c = makeChannel[Int]()
val quit= makeChannel[Boolean]();
val f = fibonacci(c,quit)
for ( i <- c) {
System.out.print(i)
if (i > N) {
quit.awrite( true )
Scala
16. Scala-gopher: main constructions
❖ Gopher: Akka extension.
❖ go[T](body: T): Future[T]
❖ inside body we can use pseudosynchronous API
❖ defer
❖ select [forever, once] => [choice]
❖ case matching macros; for statement, fold, ..
❖ channels
❖ channels/ Input[X]/Output[X] / collection API
val gopherApi = GopherAPI(actorsSystem)
import gopherApi._
def fibonacci(c: Channel[Int], quit: Channel[Boolean]): Future[Unit] = go {
var (x, y) = (0, 1)
select.forever{
case x : c.write =>
val z = x
x = y; y = x+z
case q: quit.read =>
CurrentFlowTermination.exit(())
}
c.close()
}
}
17. Scala: simple code example (direct translation)
val c = makeChannel[Int]()
val quit= makeChannel[Boolean]();
val f = fibonacci(c,quit)
for ( i <- c) {
System.out.print(i)
if (i > N) {
quit.awrite( true )
Scala
(mutable var, WTF ?)
def fibonacci(c: Channel[Int], quit: Channel[Boolean]): Future[Unit] = go {
select.fold((0,1)){ case ((x,y),s) =>
s match {
case x : c.write =>
(y, x+y)
case q: quit.read =>
CurrentFlowTermination.exit((x,y))
}
}
c.close()
}
18. Scala: simple code example (fold)
val c = makeChannel[Int]()
val quit= makeChannel[Boolean]();
val f = fibonacci(c,quit)
for ( i <- c) {
System.out.print(i)
if (i > N) {
quit.awrite( true )
Scala
def fibonacci(c: Channel[Int], quit: Channel[Boolean]): Future[Unit] = go {
val (x,y) = select.fold((0,1)){ case ((x,y),s) =>
s match {
case x : c.write =>
(y, x+y)
case q: quit.read =>
CurrentFlowTermination.exit((x,y))
}
}
c.close()
}
19. Scala: simple code example (fold)
val c = makeChannel[Int]()
val quit= makeChannel[Boolean]();
val f = fibonacci(c,quit)
for ( i <- c) {
System.out.print(i)
if (i > N) {
quit.awrite( true )
Scala
def fibonacci(c: Channel[Int], quit: Channel[Boolean]): Future[(Int,Int)] =
select.afold((0,1)){ case ((x,y),s) =>
s match {
case x : c.write =>
(y, x+y)
case q: quit.read =>
c.close()
CurrentFlowTermination.exit((x,y))
}
}
20. Scala: simple code example (аfold)
val c = makeChannel[Int]()
val quit= makeChannel[Boolean]();
val f = fibonacci(c,quit)
for ( i <- c) {
System.out.print(i)
if (i > N) {
quit.awrite( true )
Scala
s match {
case x : c.write =>
(y, x+y)
case q: quit.read =>
c.close()
CurrentFlowTermination.exit((x,y))
}
21. scala-gopher: select
Scala
s match {
case z : c.write if (z == 1) =>
……..
case x: Int if (x == future.read()) =>
}
//special syntax
//writing expressions
//reading from expressions
22. scala-gopher: select de-‘macro’
select.forever{
case x: channel1.read => (do-something-1)
case y: channel2.read => (do-something-2)
case z: channel3.write => (do-something-3)
case _ => (do-somethig-4)
}
{ val s = select.createForeverSelectorBuilder()
s.reading(channel1, x => (do-something-1))
s.reading(channel2, y => (do-something-2))
s.write(channel3,z,….)
s.idle(do-something-4)
s.run()
}
23. scala-gopher: select de-‘macro’
s.reading(channel1, x => (do-something-1))
s.onRead(channel1, x => {
implicit f1: FlowTermination = s.flowTermination
implicit e1: ExecutionContext => s.executionContext
scala.async.Async.async( transfer(do-something-1) )
}
24. scala-gopher: select functionality
❖ select functionality
❖ wrap callbacks, supplied by user
❖ to guarantee than only one branch of select match
is running
❖ to provide reaction on flowTermination
❖ pass one to channels/inputs/outpus
25. scala-gopher: Input/Output.
❖ Input[T] - something, from which we can wait input
❖ callback-based ‘native’ trait.
❖ implementations: channels, futures, collections …
❖ collection-like methods: map, filter, fold, zip,
append, merge…
aread(): Future[T]
read: T = await(aread)
<~ = read.
26. scala-gopher: Input/Output.
❖ Output[T] - something, where we can send value
❖ callback-based ‘native’ trait.
❖ implementations: channels, promises, actor-s…
awrite(v:T): Future[T]
write(t): T = await(awrite(t))
~> = write.
27. scala-gopher: Timeouts
val (in, inTimeouts) = in.withTimeout(1 minute)
val (out, outTimeouts) = out.withTimeout(10 minutes)
select.fold(s0){ (state,selector) =>
selector match {
case x: in.read => out.write(x)
case t: inTimeouts.read =>
log(“input timeout”);
case t: outTimeouts.read =>
log(“output timeout”);
}
}
28. Example: broadcast without listener registry
❖ Sender:
❖ create buffered channel for each message
❖ send into this channel: message + channel for next message
❖ can report value of channel for next message
❖ Receiver:
❖ read message from channel,
❖ put one back (to allow other readers to receive one)
❖ change channel to listen on just receive.
29. Example: broadcast without listener registry
case class Message[V](
value: Value,
nextChannel: Channel[Message[V]]
)
class Receiver[V](initChannel: Message, handle: V => Unit)
{
val current = makeEffectedChannel(initChannel)
val future = current.forever{ message =>
current write message.value
current := message.nextChannel
go { handle(message.value) }
}
}
30. Example: broadcast without listener registry
class Broadcaster[V]() // single-threaded
{
var last = makeNextChannel
def send(v: V) : Unit = {
val next = makeNextChannel
last write Message(v, next)
last = next
}
def makeReceiver(handler: V => Unit) =
new Receiver(current, next)
def makeNextChannel = makeChannel[Message[V]](1)
}
31. Example: broadcast without listener registry
class Broadcaster[V]()
{
val sendc = makeChannel[V]()
val requestLast = makeChannel[Channel[Channel[Value[V]]]()
val future = select.fold(makeNextChannel){ (last,s) =>
s match {
case v:sendc.read => val next = makeNextChannel
last <~ Message(v,next)
next
case r:requestLast.read =>
r <~ last
last
}
}
def send(v: V) : Unit = sendc.send(v)
31. Example: broadcast without listener registry
class Broadcaster[V]()
{
val sendc = makeChannel[V]()
val requestLast = makeChannel[Channel[Channel[Value[V]]]()
val future = select.fold(makeNextChannel){ (last,s) =>
s match {
case v:sendc.read => val next = makeNextChannel
last <~ Message(v,next)
next
case r:requestLast.read =>
r <~ last
last
}
}
def makeReceiver(handler): Future[Receiver] = go {
val r = makeChannel[Channel[Message[V]]
requestLast <- r
Receiver(await(r.read),handler)
33. CPS / Scala
❖ Test of
❖ essential CPS functionality
❖ dynamic channels
❖ state inside selector folds
❖ More : Transputers
34. Transputers
❖ Structure => schemes.
❖ Entity,
❖ set of input ports
❖ set of output ports
❖ logic
❖ Process/Transputer
35 Transputers.
trait Bingo extends Transputer
{
val inX = inPort[Int]()
val inY = inPort[Int]()
val out = OutPort[String]()
loop {
case x: inX.read =>
val y = inY.read
if (x == y) {
out <~ “Bingo!”
}
}
}
36. Transputers
❖ like actors, but for channels
❖ can be supervised ‘as actors’.
❖ can be connected to each other
val (inX,inY) = (makeChannel[Int](), makeChannel[Int])
val bing = makeTransputer[Bingo]
val acceptor = makeTransputer[Acceptor]
bingo.inX connect inX
bingo.inY connect inY
bingo.out connect acceptor
(bingo + acceptor).start()
37. Transputers
❖ Selector (Custom logic)
❖ Par (|| execution)
❖ Replicate
38. Scala concurrency ecosystem
❖ Future [?]
❖ Erlang-Style ? (actors)
❖ Ozz-Style ? (async [partially])
❖ CPS (gopher)
❖ Rx [?]
❖ Can be used together.
39. Scala-Gopher, problems
❖ async implementation
❖ (buggy, not complete)
❖ need application programmer use macros for providing
‘pseudo synchronised’ API
❖ Need more experience.
❖ // details will be in ScalaUA talk.
40. Questions?
❖ It was about: https://github.com/rssh/scala-gopher
❖ Questions ?
❖ Thanks for attention.

More Related Content

What's hot

ECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing EraECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing EraAllen Wirfs-Brock
 
Go Concurrency Basics
Go Concurrency Basics Go Concurrency Basics
Go Concurrency Basics ElifTech
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6Solution4Future
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web DevsRami Sayar
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programmingRodolfo Finochietti
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015Michiel Borkent
 
Scalaz Stream: Rebirth
Scalaz Stream: RebirthScalaz Stream: Rebirth
Scalaz Stream: RebirthJohn De Goes
 
Incremental Development with Lisp: Building a Game and a Website
Incremental Development with Lisp: Building a Game and a WebsiteIncremental Development with Lisp: Building a Game and a Website
Incremental Development with Lisp: Building a Game and a WebsiteJames Long
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the webMichiel Borkent
 
Beauty and Power of Go
Beauty and Power of GoBeauty and Power of Go
Beauty and Power of GoFrank Müller
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleSaúl Ibarra Corretgé
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overviewhesher
 
Metaprogramming and Reflection in Common Lisp
Metaprogramming and Reflection in Common LispMetaprogramming and Reflection in Common Lisp
Metaprogramming and Reflection in Common LispDamien Cassou
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnMoriyoshi Koizumi
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers ToolboxStefan
 

What's hot (20)

ECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing EraECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
 
Go Concurrency Basics
Go Concurrency Basics Go Concurrency Basics
Go Concurrency Basics
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web Devs
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programming
 
Seeking Clojure
Seeking ClojureSeeking Clojure
Seeking Clojure
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
Scalaz Stream: Rebirth
Scalaz Stream: RebirthScalaz Stream: Rebirth
Scalaz Stream: Rebirth
 
Incremental Development with Lisp: Building a Game and a Website
Incremental Development with Lisp: Building a Game and a WebsiteIncremental Development with Lisp: Building a Game and a Website
Incremental Development with Lisp: Building a Game and a Website
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
 
Beauty and Power of Go
Beauty and Power of GoBeauty and Power of Go
Beauty and Power of Go
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio module
 
Clojure+ClojureScript Webapps
Clojure+ClojureScript WebappsClojure+ClojureScript Webapps
Clojure+ClojureScript Webapps
 
Modern JS with ES6
Modern JS with ES6Modern JS with ES6
Modern JS with ES6
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
Metaprogramming and Reflection in Common Lisp
Metaprogramming and Reflection in Common LispMetaprogramming and Reflection in Common Lisp
Metaprogramming and Reflection in Common Lisp
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers Toolbox
 

Viewers also liked

42.type: Literal-based Singleton types
42.type: Literal-based Singleton types42.type: Literal-based Singleton types
42.type: Literal-based Singleton typesGeorge Leontiev
 
There's a Prolog in your Scala!
There's a Prolog in your Scala!There's a Prolog in your Scala!
There's a Prolog in your Scala!George Leontiev
 
Scala Type Classes: Basics and More
Scala Type Classes:  Basics and MoreScala Type Classes:  Basics and More
Scala Type Classes: Basics and Moresukanthajra
 
Exploring the Scala ecosystem
Exploring the Scala ecosystemExploring the Scala ecosystem
Exploring the Scala ecosystemDenis
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scalaRuslan Shevchenko
 
Industrial use of formal methods
Industrial use of formal methodsIndustrial use of formal methods
Industrial use of formal methodsJonathan Bowen
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are DatabasesMartin Odersky
 
Practical type mining in Scala
Practical type mining in ScalaPractical type mining in Scala
Practical type mining in ScalaRose Toomey
 
The art of decomposing monoliths
The art of decomposing monolithsThe art of decomposing monoliths
The art of decomposing monolithsKfir Bloch
 
Introduction to Scala Macros
Introduction to Scala MacrosIntroduction to Scala Macros
Introduction to Scala MacrosKnoldus Inc.
 
Effective way to code in Scala
Effective way to code in ScalaEffective way to code in Scala
Effective way to code in ScalaKnoldus Inc.
 
Macro in Scala
Macro in ScalaMacro in Scala
Macro in Scalatakezoe
 
Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016takezoe
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaKnoldus Inc.
 
Purely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaPurely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaVladimir Kostyukov
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in ScalaPatrick Nicolas
 
ゆるふわScalaコップ本読書会 第7章
ゆるふわScalaコップ本読書会 第7章ゆるふわScalaコップ本読書会 第7章
ゆるふわScalaコップ本読書会 第7章Yuta Yokoi
 
Demystifying Scala Type System
Demystifying Scala Type SystemDemystifying Scala Type System
Demystifying Scala Type SystemDavid Galichet
 

Viewers also liked (20)

42.type: Literal-based Singleton types
42.type: Literal-based Singleton types42.type: Literal-based Singleton types
42.type: Literal-based Singleton types
 
There's a Prolog in your Scala!
There's a Prolog in your Scala!There's a Prolog in your Scala!
There's a Prolog in your Scala!
 
Scala Type Classes: Basics and More
Scala Type Classes:  Basics and MoreScala Type Classes:  Basics and More
Scala Type Classes: Basics and More
 
Slides
SlidesSlides
Slides
 
Exploring the Scala ecosystem
Exploring the Scala ecosystemExploring the Scala ecosystem
Exploring the Scala ecosystem
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scala
 
Industrial use of formal methods
Industrial use of formal methodsIndustrial use of formal methods
Industrial use of formal methods
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are Databases
 
Practical type mining in Scala
Practical type mining in ScalaPractical type mining in Scala
Practical type mining in Scala
 
The art of decomposing monoliths
The art of decomposing monolithsThe art of decomposing monoliths
The art of decomposing monoliths
 
Introduction to Scala Macros
Introduction to Scala MacrosIntroduction to Scala Macros
Introduction to Scala Macros
 
Effective way to code in Scala
Effective way to code in ScalaEffective way to code in Scala
Effective way to code in Scala
 
Macro in Scala
Macro in ScalaMacro in Scala
Macro in Scala
 
Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for Scala
 
Purely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaPurely Functional Data Structures in Scala
Purely Functional Data Structures in Scala
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
 
ゆるふわScalaコップ本読書会 第7章
ゆるふわScalaコップ本読書会 第7章ゆるふわScalaコップ本読書会 第7章
ゆるふわScalaコップ本読書会 第7章
 
Demystifying Scala Type System
Demystifying Scala Type SystemDemystifying Scala Type System
Demystifying Scala Type System
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 

Similar to Csp scala wixmeetup2016

Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Ruslan Shevchenko
 
Concurrency in go
Concurrency in goConcurrency in go
Concurrency in goborderj
 
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
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Evel xf
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eveguest91855c
 
0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdf0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdfssusere19c741
 
24-TensorFlow-Clipper.pptxnjjjjnjjjjjjmm
24-TensorFlow-Clipper.pptxnjjjjnjjjjjjmm24-TensorFlow-Clipper.pptxnjjjjnjjjjjjmm
24-TensorFlow-Clipper.pptxnjjjjnjjjjjjmmSasidharaKashyapChat
 
Kyo - Functional Scala 2023.pdf
Kyo - Functional Scala 2023.pdfKyo - Functional Scala 2023.pdf
Kyo - Functional Scala 2023.pdfFlavio W. Brasil
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...GeeksLab Odessa
 
A Simple Communication System Design Lab #4 with MATLAB Simulink
A Simple Communication System Design Lab #4 with MATLAB SimulinkA Simple Communication System Design Lab #4 with MATLAB Simulink
A Simple Communication System Design Lab #4 with MATLAB SimulinkJaewook. Kang
 
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
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional ProgrammingYiguang Hu
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...Francesco Casalegno
 

Similar to Csp scala wixmeetup2016 (20)

N flavors of streaming
N flavors of streamingN flavors of streaming
N flavors of streaming
 
Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version]
 
Concurrency in go
Concurrency in goConcurrency in go
Concurrency in go
 
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.
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eve
 
Return of c++
Return of c++Return of c++
Return of c++
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eve
 
0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdf0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdf
 
24-TensorFlow-Clipper.pptxnjjjjnjjjjjjmm
24-TensorFlow-Clipper.pptxnjjjjnjjjjjjmm24-TensorFlow-Clipper.pptxnjjjjnjjjjjjmm
24-TensorFlow-Clipper.pptxnjjjjnjjjjjjmm
 
tokyotalk
tokyotalktokyotalk
tokyotalk
 
Kyo - Functional Scala 2023.pdf
Kyo - Functional Scala 2023.pdfKyo - Functional Scala 2023.pdf
Kyo - Functional Scala 2023.pdf
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
 
A Simple Communication System Design Lab #4 with MATLAB Simulink
A Simple Communication System Design Lab #4 with MATLAB SimulinkA Simple Communication System Design Lab #4 with MATLAB Simulink
A Simple Communication System Design Lab #4 with MATLAB Simulink
 
Async fun
Async funAsync fun
Async fun
 
scalar.pdf
scalar.pdfscalar.pdf
scalar.pdf
 
Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
 
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
 
Lab
LabLab
Lab
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional Programming
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
 

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
 
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
 
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
 
Javascript in modern scala backend. [russian]
Javascript in modern scala backend.  [russian]  Javascript in modern scala backend.  [russian]
Javascript in modern scala backend. [russian] Ruslan Shevchenko
 
implementation of 'go'-like language constructions in scala (russian)
implementation of 'go'-like language constructions in scala (russian)implementation of 'go'-like language constructions in scala (russian)
implementation of 'go'-like language constructions in scala (russian)Ruslan Shevchenko
 
Play/Scala as application platform (for http://wbcamp.in.ua 2013)
Play/Scala as application platform  (for http://wbcamp.in.ua 2013)Play/Scala as application platform  (for http://wbcamp.in.ua 2013)
Play/Scala as application platform (for http://wbcamp.in.ua 2013)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
 
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
 
Scala jargon cheatsheet
Scala jargon cheatsheetScala jargon cheatsheet
Scala jargon cheatsheet
 
Java & low latency applications
Java & low latency applicationsJava & low latency applications
Java & low latency applications
 
IDLs
IDLsIDLs
IDLs
 
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.
 
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.
 
R scala 17_05_2014
R scala 17_05_2014R scala 17_05_2014
R scala 17_05_2014
 
Javascript in modern scala backend. [russian]
Javascript in modern scala backend.  [russian]  Javascript in modern scala backend.  [russian]
Javascript in modern scala backend. [russian]
 
Osdn2013 rssh
Osdn2013 rsshOsdn2013 rssh
Osdn2013 rssh
 
implementation of 'go'-like language constructions in scala (russian)
implementation of 'go'-like language constructions in scala (russian)implementation of 'go'-like language constructions in scala (russian)
implementation of 'go'-like language constructions in scala (russian)
 
Play/Scala as application platform (for http://wbcamp.in.ua 2013)
Play/Scala as application platform  (for http://wbcamp.in.ua 2013)Play/Scala as application platform  (for http://wbcamp.in.ua 2013)
Play/Scala as application platform (for http://wbcamp.in.ua 2013)
 

Recently uploaded

Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 

Recently uploaded (20)

Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 

Csp scala wixmeetup2016

  • 1. Wix R&D meetup; CSP & Scala: theory and implementation. https://github.com/rssh/scala-gopher Ruslan Shevchenko <ruslan@shevchenko.kiev.ua> https://github.com/rssh @rssh1
  • 2. 2. Outline ❖ Theory & History ❖ CSP = Communication Sequence Processes ❖ !-calculus (CCS = Calculus of Communicating System) ❖ Languages: (Occam,Limbo, Go[Clojure, Scala, … ]) ❖ Main constructions / idioms, how they looks ❖ Channels, Selectors, Transputers ❖ Implementation Techniques
  • 3. 3. Theory & History ❖ If you familiar with basic concepts, skip to slide 8 ❖ Just show me scala API: skip to slide 14
  • 4. 4. Theory & History ❖ CPS = Communication Sequence Processes. ❖ CSS = Calculus of Communicating System. ❖ 1978 First CSP Paper by Tony Hoar. ❖ 1980. CSS by Robert Milner. (Algebraic Processes) ❖ 1985 CSP formalism (influenced by CSS) in CSP Book ❖ http://www.usingcsp.com/ ❖ 1992 !-calculus [CSS + Channels] (Robert Milner, Joachim Parrow, David Walker) ❖ …. (large family of Process Algebras, including Actor Model, ACP, )
  • 5. 5. CSP Notation(basic) ❖ (A, B, C … ) — processes, ❖ (x, y, z … ) — events ❖ atomic: x , STOP, BEEP, or c.v (channel/value) ❖ c!v - send v to channel c (after this c.v happens) ❖ c?v - receive v from channel c (wait until c.v) ❖ trace(…) — sequence of events.
  • 6. 6. CSP Notation(basic) // after event Operations on processes: // fix point (loops, recursion // interleave concurrently // choice, if a then P if b then Q // seq
  • 7. 7. CSP Notation(examples) COPY(left,right)= left right P1 P2 Q1 Q2 P1 P2 Q1 Q2
  • 8. 8. Occam language William Occam, 1287-1347 ‘Occam razor’ principle Occam language. (1983) INT x, y: SEQ x := 4 y := (x + 1) CHAN INT c: PAR some.procedure (x, y, c!) another.procedure (c?) y := 5 braces via indentation. (before python) minimal language. (processor constructors)
  • 9. 9. Occam language ❖ created by INMOS ❖ targeted Transputers CHIP architecture (bare metal) ❖ latest dialect: occam-! [1996] ❖ extensions from !-calculus ❖ (more dynamic, channels can be send via channels) ❖ http://concurrency.cc — occam for Aurdino.
  • 10. 10. Inferno, Limbo, Go ❖ Unix, Plan9, Inferno: [At&t; Bell labs; vita nuova] ❖ http://www.vitanuova.com/inferno/ ❖ Limbo … C-like language + channels + buffered channels. ❖ Go … channels as in Limbo (Go roots is from hell is not a metaphor) Sean Forward David Leo Presotto Rob Pike Dennis M. Ritchie Ken Thompson
  • 11. 11. CPS in Limbo/Go/Scala: main constructions ❖ processes: operator for spawning new lightweight process. ❖ channels: can be unbuffered (synchronised) or buffered ❖ unbuffered — writer wait until reader start to work ❖ buffered — if channel buffer is not full, writer not blocked ❖ selector: wait for few events (channel), eval first.
  • 12. 12. Go: simple code example func fibonacci(c chan int, quit chan bool) { go { x, y := 0, 1 for (){ select { case c <- x : x, y = y, x+y case q<-quit: break; } } close(c) } } c = make(chan int); quit= make(chan bool); fibonacci(c,quit) for i := range c { fmt.Println(i) if (i > 2000) { quit <- true } } Go
  • 13. 13. Go: simple code example func fibonacci(c chan int, quit chan bool) { go { x, y := 0, 1 for (){ select { case c <- x : x, y = y, x+y case q<- quit: break; } } close(c) } } c = make(chan int); quit= make(chan bool); fibonacci(c,quit) for i := range c { fmt.Println(i) if (i > 2000) { quit <- true } } Go
  • 14. 14. scala-gopher ❖ Akka extension + Macros on top of SIP22-async ❖ Integrate CSP primitives and scala concurrency ❖ Provide: ❖ asynchronous API inside general control-flow ❖ pseudo-synchronous API inside go{ .. } or async{ ..} blocks
  • 15. def fibonacci(c: Channel[Int], quit: Channel[Boolean]): Future[Unit] = go { var (x, y) = (0, 1) select.forever{ case x : c.write => val z = x x = y; y = x+z case q: quit.read => CurrentFlowTermination.exit(()) } c.close() } 15. Scala: simple code example (direct translation) val c = makeChannel[Int]() val quit= makeChannel[Boolean](); val f = fibonacci(c,quit) for ( i <- c) { System.out.print(i) if (i > N) { quit.awrite( true ) Scala
  • 16. 16. Scala-gopher: main constructions ❖ Gopher: Akka extension. ❖ go[T](body: T): Future[T] ❖ inside body we can use pseudosynchronous API ❖ defer ❖ select [forever, once] => [choice] ❖ case matching macros; for statement, fold, .. ❖ channels ❖ channels/ Input[X]/Output[X] / collection API val gopherApi = GopherAPI(actorsSystem) import gopherApi._
  • 17. def fibonacci(c: Channel[Int], quit: Channel[Boolean]): Future[Unit] = go { var (x, y) = (0, 1) select.forever{ case x : c.write => val z = x x = y; y = x+z case q: quit.read => CurrentFlowTermination.exit(()) } c.close() } } 17. Scala: simple code example (direct translation) val c = makeChannel[Int]() val quit= makeChannel[Boolean](); val f = fibonacci(c,quit) for ( i <- c) { System.out.print(i) if (i > N) { quit.awrite( true ) Scala (mutable var, WTF ?)
  • 18. def fibonacci(c: Channel[Int], quit: Channel[Boolean]): Future[Unit] = go { select.fold((0,1)){ case ((x,y),s) => s match { case x : c.write => (y, x+y) case q: quit.read => CurrentFlowTermination.exit((x,y)) } } c.close() } 18. Scala: simple code example (fold) val c = makeChannel[Int]() val quit= makeChannel[Boolean](); val f = fibonacci(c,quit) for ( i <- c) { System.out.print(i) if (i > N) { quit.awrite( true ) Scala
  • 19. def fibonacci(c: Channel[Int], quit: Channel[Boolean]): Future[Unit] = go { val (x,y) = select.fold((0,1)){ case ((x,y),s) => s match { case x : c.write => (y, x+y) case q: quit.read => CurrentFlowTermination.exit((x,y)) } } c.close() } 19. Scala: simple code example (fold) val c = makeChannel[Int]() val quit= makeChannel[Boolean](); val f = fibonacci(c,quit) for ( i <- c) { System.out.print(i) if (i > N) { quit.awrite( true ) Scala
  • 20. def fibonacci(c: Channel[Int], quit: Channel[Boolean]): Future[(Int,Int)] = select.afold((0,1)){ case ((x,y),s) => s match { case x : c.write => (y, x+y) case q: quit.read => c.close() CurrentFlowTermination.exit((x,y)) } } 20. Scala: simple code example (аfold) val c = makeChannel[Int]() val quit= makeChannel[Boolean](); val f = fibonacci(c,quit) for ( i <- c) { System.out.print(i) if (i > N) { quit.awrite( true ) Scala
  • 21. s match { case x : c.write => (y, x+y) case q: quit.read => c.close() CurrentFlowTermination.exit((x,y)) } 21. scala-gopher: select Scala s match { case z : c.write if (z == 1) => …….. case x: Int if (x == future.read()) => } //special syntax //writing expressions //reading from expressions
  • 22. 22. scala-gopher: select de-‘macro’ select.forever{ case x: channel1.read => (do-something-1) case y: channel2.read => (do-something-2) case z: channel3.write => (do-something-3) case _ => (do-somethig-4) } { val s = select.createForeverSelectorBuilder() s.reading(channel1, x => (do-something-1)) s.reading(channel2, y => (do-something-2)) s.write(channel3,z,….) s.idle(do-something-4) s.run() }
  • 23. 23. scala-gopher: select de-‘macro’ s.reading(channel1, x => (do-something-1)) s.onRead(channel1, x => { implicit f1: FlowTermination = s.flowTermination implicit e1: ExecutionContext => s.executionContext scala.async.Async.async( transfer(do-something-1) ) }
  • 24. 24. scala-gopher: select functionality ❖ select functionality ❖ wrap callbacks, supplied by user ❖ to guarantee than only one branch of select match is running ❖ to provide reaction on flowTermination ❖ pass one to channels/inputs/outpus
  • 25. 25. scala-gopher: Input/Output. ❖ Input[T] - something, from which we can wait input ❖ callback-based ‘native’ trait. ❖ implementations: channels, futures, collections … ❖ collection-like methods: map, filter, fold, zip, append, merge… aread(): Future[T] read: T = await(aread) <~ = read.
  • 26. 26. scala-gopher: Input/Output. ❖ Output[T] - something, where we can send value ❖ callback-based ‘native’ trait. ❖ implementations: channels, promises, actor-s… awrite(v:T): Future[T] write(t): T = await(awrite(t)) ~> = write.
  • 27. 27. scala-gopher: Timeouts val (in, inTimeouts) = in.withTimeout(1 minute) val (out, outTimeouts) = out.withTimeout(10 minutes) select.fold(s0){ (state,selector) => selector match { case x: in.read => out.write(x) case t: inTimeouts.read => log(“input timeout”); case t: outTimeouts.read => log(“output timeout”); } }
  • 28. 28. Example: broadcast without listener registry ❖ Sender: ❖ create buffered channel for each message ❖ send into this channel: message + channel for next message ❖ can report value of channel for next message ❖ Receiver: ❖ read message from channel, ❖ put one back (to allow other readers to receive one) ❖ change channel to listen on just receive.
  • 29. 29. Example: broadcast without listener registry case class Message[V]( value: Value, nextChannel: Channel[Message[V]] ) class Receiver[V](initChannel: Message, handle: V => Unit) { val current = makeEffectedChannel(initChannel) val future = current.forever{ message => current write message.value current := message.nextChannel go { handle(message.value) } } }
  • 30. 30. Example: broadcast without listener registry class Broadcaster[V]() // single-threaded { var last = makeNextChannel def send(v: V) : Unit = { val next = makeNextChannel last write Message(v, next) last = next } def makeReceiver(handler: V => Unit) = new Receiver(current, next) def makeNextChannel = makeChannel[Message[V]](1) }
  • 31. 31. Example: broadcast without listener registry class Broadcaster[V]() { val sendc = makeChannel[V]() val requestLast = makeChannel[Channel[Channel[Value[V]]]() val future = select.fold(makeNextChannel){ (last,s) => s match { case v:sendc.read => val next = makeNextChannel last <~ Message(v,next) next case r:requestLast.read => r <~ last last } } def send(v: V) : Unit = sendc.send(v)
  • 32. 31. Example: broadcast without listener registry class Broadcaster[V]() { val sendc = makeChannel[V]() val requestLast = makeChannel[Channel[Channel[Value[V]]]() val future = select.fold(makeNextChannel){ (last,s) => s match { case v:sendc.read => val next = makeNextChannel last <~ Message(v,next) next case r:requestLast.read => r <~ last last } } def makeReceiver(handler): Future[Receiver] = go { val r = makeChannel[Channel[Message[V]] requestLast <- r Receiver(await(r.read),handler)
  • 33. 33. CPS / Scala ❖ Test of ❖ essential CPS functionality ❖ dynamic channels ❖ state inside selector folds ❖ More : Transputers
  • 34. 34. Transputers ❖ Structure => schemes. ❖ Entity, ❖ set of input ports ❖ set of output ports ❖ logic ❖ Process/Transputer
  • 35. 35 Transputers. trait Bingo extends Transputer { val inX = inPort[Int]() val inY = inPort[Int]() val out = OutPort[String]() loop { case x: inX.read => val y = inY.read if (x == y) { out <~ “Bingo!” } } }
  • 36. 36. Transputers ❖ like actors, but for channels ❖ can be supervised ‘as actors’. ❖ can be connected to each other val (inX,inY) = (makeChannel[Int](), makeChannel[Int]) val bing = makeTransputer[Bingo] val acceptor = makeTransputer[Acceptor] bingo.inX connect inX bingo.inY connect inY bingo.out connect acceptor (bingo + acceptor).start()
  • 37. 37. Transputers ❖ Selector (Custom logic) ❖ Par (|| execution) ❖ Replicate
  • 38. 38. Scala concurrency ecosystem ❖ Future [?] ❖ Erlang-Style ? (actors) ❖ Ozz-Style ? (async [partially]) ❖ CPS (gopher) ❖ Rx [?] ❖ Can be used together.
  • 39. 39. Scala-Gopher, problems ❖ async implementation ❖ (buggy, not complete) ❖ need application programmer use macros for providing ‘pseudo synchronised’ API ❖ Need more experience. ❖ // details will be in ScalaUA talk.
  • 40. 40. Questions? ❖ It was about: https://github.com/rssh/scala-gopher ❖ Questions ? ❖ Thanks for attention.