SlideShare a Scribd company logo
Frontier Developers
         6:00: Pizza & Networking
         6:20: Presentation
         https://github.com/jdegoes/fun-with-automata

         WIFI: Scriblove / scribble


Thursday, May 24, 12
Fun with Automata!
                       https://github.com/jdegoes/fun-with-automata




    John A. De Goes
    @jdegoes                                               http://precog.com
Thursday, May 24, 12
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
DTs vs Functions?
                             Function

                         A              B


                               DT

                         A              (B, DT)


Thursday, May 24, 12
“Functions with a
                          memory.”


Thursday, May 24, 12
Benefits
                       • Purely-functional yet stateful
                       • Incredibly composable
                       • Safely concurrent
                       • Recoverable


Thursday, May 24, 12
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
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
val (v1, d2) = d1 ! 1

                 // v1 = 1

                 val (v2, d3) = d2 ! 1

                 // v2 = 2

                 ...




Thursday, May 24, 12
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
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
Exercise 1

             Develop DT and some of its helper methods in a
             language of your choice.




Thursday, May 24, 12
Exercise 2

             Develop a simple streaming analytics framework,
             with aggregation and windowing.




Thursday, May 24, 12
Exercise 3

             Create a recognizer for the language defined 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

More Related Content

PDF
Paper Summary of Infogan-CR : Disentangling Generative Adversarial Networks w...
PDF
Variational inference using implicit distributions
PDF
Digital Differential Analyzer Line Drawing Algorithm in C
PPTX
Ccard Layout
PDF
Factoring trinomials lc1
PDF
Boolean type
PDF
Sigma type
Paper Summary of Infogan-CR : Disentangling Generative Adversarial Networks w...
Variational inference using implicit distributions
Digital Differential Analyzer Line Drawing Algorithm in C
Ccard Layout
Factoring trinomials lc1
Boolean type
Sigma type

Viewers also liked (13)

PDF
First-Class Patterns
PDF
Advanced Analytics & Statistics with MongoDB
PDF
Quirrel & R for Dummies
PDF
All Aboard The Scala-to-PureScript Express!
PDF
MTL Versus Free
PDF
Rise of the scientific database
PDF
Streams for (Co)Free!
PDF
In-Database Predictive Analytics
PDF
Analytics Maturity Model
PPTX
The Dark Side of NoSQL
PDF
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
PDF
Halogen: Past, Present, and Future
PDF
The Next Great Functional Programming Language
First-Class Patterns
Advanced Analytics & Statistics with MongoDB
Quirrel & R for Dummies
All Aboard The Scala-to-PureScript Express!
MTL Versus Free
Rise of the scientific database
Streams for (Co)Free!
In-Database Predictive Analytics
Analytics Maturity Model
The Dark Side of NoSQL
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
Halogen: Past, Present, and Future
The Next Great Functional Programming Language
Ad

More from John De Goes (18)

PDF
Refactoring Functional Type Classes
PDF
One Monad to Rule Them All
PDF
Error Management: Future vs ZIO
PDF
Atomically { Delete Your Actors }
PDF
The Death of Final Tagless
PDF
Scalaz Stream: Rebirth
PDF
Scalaz Stream: Rebirth
PDF
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
PDF
ZIO Queue
PDF
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
PDF
Scalaz 8: A Whole New Game
PDF
Scalaz 8 vs Akka Actors
PDF
Orthogonal Functional Architecture
PDF
The Design of the Scalaz 8 Effect System
PDF
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
PDF
Post-Free: Life After Free Monads
PDF
Getting Started with PureScript
PPTX
SlamData - How MongoDB Is Powering a Revolution in Visual Analytics
Refactoring Functional Type Classes
One Monad to Rule Them All
Error Management: Future vs ZIO
Atomically { Delete Your Actors }
The Death of Final Tagless
Scalaz Stream: Rebirth
Scalaz Stream: Rebirth
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
ZIO Queue
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
Scalaz 8: A Whole New Game
Scalaz 8 vs Akka Actors
Orthogonal Functional Architecture
The Design of the Scalaz 8 Effect System
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Post-Free: Life After Free Monads
Getting Started with PureScript
SlamData - How MongoDB Is Powering a Revolution in Visual Analytics
Ad

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The AUB Centre for AI in Media Proposal.docx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Understanding_Digital_Forensics_Presentation.pptx
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
Spectral efficient network and resource selection model in 5G networks
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
Dropbox Q2 2025 Financial Results & Investor Presentation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

Fun with automata

  • 1. Frontier Developers 6:00: Pizza & Networking 6:20: Presentation https://github.com/jdegoes/fun-with-automata WIFI: Scriblove / scribble Thursday, May 24, 12
  • 2. Fun with Automata! https://github.com/jdegoes/fun-with-automata John A. De Goes @jdegoes http://precog.com Thursday, May 24, 12
  • 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. DTs vs Functions? Function A B DT A (B, DT) Thursday, May 24, 12
  • 5. “Functions with a memory.” Thursday, May 24, 12
  • 6. Benefits • Purely-functional yet stateful • Incredibly composable • Safely concurrent • Recoverable Thursday, May 24, 12
  • 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. 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. val (v1, d2) = d1 ! 1 // v1 = 1 val (v2, d3) = d2 ! 1 // v2 = 2 ... Thursday, May 24, 12
  • 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. 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. Exercise 1 Develop DT and some of its helper methods in a language of your choice. Thursday, May 24, 12
  • 13. Exercise 2 Develop a simple streaming analytics framework, with aggregation and windowing. Thursday, May 24, 12
  • 14. Exercise 3 Create a recognizer for the language defined 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