Upcoming SlideShare
×

Fun with automata

1,165 views
1,078 views

Published on

Deck used for the Fun with Automata talk at Frontier Developers, May 24 2012. Accompanying material at: https://github.com/jdegoes/fun-with-automata

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
1,165
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
2
0
Likes
0
Embeds 0
No embeds

No notes for slide

Fun with automata

1. 1. Frontier Developers 6:00: Pizza & Networking 6:20: Presentation https://github.com/jdegoes/fun-with-automata WIFI: Scriblove / scribbleThursday, May 24, 12
2. 2. Fun with Automata! https://github.com/jdegoes/fun-with-automata John A. De Goes @jdegoes http://precog.comThursday, May 24, 12
3. 3. Automata Abstract machines that transition between states based on reading of input. Transducers Automata that read and write. Deterministic Transducers Output deterministically depends on current state and prior input.Thursday, May 24, 12
4. 4. DTs vs Functions? Function A B DT A (B, DT)Thursday, May 24, 12
5. 5. “Functions with a memory.”Thursday, May 24, 12
6. 6. Beneﬁts • Purely-functional yet stateful • Incredibly composable • Safely concurrent • RecoverableThursday, May 24, 12
7. 7. trait DT[A, B] { def ! (input: A): (B, DT[A, B]) } object DT { def apply[A, B](f: A => (B, DT[A, B])) = new DT[A, B] { def ! (v: A) = f(v) } }Thursday, May 24, 12
8. 8. val d1 = { def f(b: Boolean): DT[Int, Int] = DT { v => val output = if (b) v * 2 else v (output, f(!b)) } f(false) }Thursday, May 24, 12
9. 9. val (v1, d2) = d1 ! 1 // v1 = 1 val (v2, d3) = d2 ! 1 // v2 = 2 ...Thursday, May 24, 12
10. 10. trait DT[A, B] { def ! (input: A): (B, DT[A, B]) def !! (inputs: A*): (List[B], DT[A, B]) read many def >>> [C] (that: DT[B, C]): DT[A, C] compose def map[C](f: B => C): DT[A, C] output transform def contramap[C](f: C => A): DT[C, B] input transform def & [C, D](that: DT[C, D]): parallelize DT[(A, C), (B, D)] }Thursday, May 24, 12
11. 11. Helpers def identity[A]: DT[A, A] def constant[A, B](b: B): DT[A, B] def rep[A]: DT[A, (A, A)] def rep3[A]: DT[A, ((A, A), A)] def merge[A, B, C](f: (A, B) => C): DT[(A, B), C] def merge3[A, B, C, D](f: (A, B, C) => D): DT[((A, B), C), D]Thursday, May 24, 12
12. 12. Exercise 1 Develop DT and some of its helper methods in a language of your choice.Thursday, May 24, 12
13. 13. Exercise 2 Develop a simple streaming analytics framework, with aggregation and windowing.Thursday, May 24, 12
14. 14. Exercise 3 Create a recognizer for the language deﬁned by the grammar ab* (that is, one ‘a’ character followed by zero or more ‘b’ characters). The recognizer emits true’s until a character breaks the pattern, then emits false’s continuously.Thursday, May 24, 12