1
Dominik Charousset, January 2016
Towards Type-safe Composition of Actors Dominik Charousset, January - - PowerPoint PPT Presentation
Towards Type-safe Composition of Actors Dominik Charousset, January 2016 1 Problem Statement 1. Actors lack (message) interfaces 2. Actors hard-code receivers 3. Actors do not compose 2 Actors lack Interfaces Erlang and Akka use dynamic
1
Dominik Charousset, January 2016
2
3
4
5
combined to produce the same or a similar type
6
* Loosely based on the definition in "Why Functional Programming Matters"
7
* Allow deducing theorems for polymorphic functions, see "Theorems for free!"
(.) :: (b -> c) -> (a -> b) -> a -> c f . g = \x -> f (g x)
8
9
* We denote actors using uppercase and functions using lowercase letters
10
* Deprecated since Scala 2.11 in favor of Akka
11
12
* See "Typecasting actors: from Akka to TAkka"
13
14
15
('get', string) -> (int) ('set', string, int) -> ()
16
17
18
19
* $ is the apply operator, δ is a user-defined bind operation
20
21
22
adapter H = F.bind(δ) H F x δ $ x y
h = λ(x) -> f(δ $ x)
FP equivalent:
23
result adapter H = F.rbind(δ) H F x x δ $ y
h = λ(x) -> δ $ f(x)
FP equivalent:
H’ y
24
sequencer H = F * G H G x x z F y
h = f · g
FP equivalent:
25
splitter H = splice(F, G) H F x (y, z) G y H’ x z x
h = λ(x) -> (f(x), g(x))
FP equivalent:
26
* in(F) denotes all accepted input tuples for F
27
(‘add’, int, int) -> (int) (‘sub’, int, int) -> (int) (‘mul’, int, int) -> (int) (‘div’, int, int) -> (int) (int, int) -> (int) .bind(‘add’, _1, _2) calculator adder =
28
(‘add’, int, int) -> (int) (‘sub’, int, int) -> (int) (‘mul’, int, int) -> (int) (‘div’, int, int) -> (int) (int) -> (int) .bind(‘mul’, _1, 2) calculator doubler =
29
(int) -> (int) (int, int) -> (int, int) (int) -> (‘res’, int) (int, int) -> (‘res’, int) .rbind(‘res’, _1) calculator adder =
30
(int, string) -> (int) (int, double) -> (string, int) (string) -> (string, string) (int, string) -> (double) (string) -> (string) ○ F H (int) -> (double) (string, string) -> (string) G =
31
(int) -> (int, int) (string) -> (int) (string, string) -> (bool) (int) -> (double, int, int) (string) -> (string, int) ++ F H (int) -> (double) (string) -> (string) G =
32
➡ Transmit result of F and G regardless of error
33
34
splitter H = splice(F, G) H F x G ERR H’ x z x ((F , ERR), (G, z))
35
36
H = F * splice(?, G) H ? x G x H’ x G(x) x
h = λ(x) -> f(x, g(x))
FP equivalent:
F (x, G(x))
37
H = F.bind(_1, _3) * splice(?, F) * splice(?, ?) H ? x ? x H’ x x x
h = λ(x) -> f(x, f(x, x))
FP equivalent:
F (x, F(x, x)) ? F (x, x) H’' (x, x) F(x, x) (x, x) (x, x, F(x, x)) H'''
38
39
40
41
* from "Distributed REScala: An Update Algorithm for Distributed Reactive Programming"
42
43
44
Journal, pp. 98-107, Oxford University Press, Oxford, UK, 1989
international conference on Functional programming languages and computer architecture, pp. 347-359. ACM, 1989
Akka to TAkka." In Proceedings of the Fifth Annual Scala Workshop, pp. 23-33. ACM, 2014.
"Distributed REScala: an update algorithm for distributed reactive programming." In Proceedings of the 2014 ACM OOPSLA '14, pp. 361-376 ACM, 2014.
45