SlideShare une entreprise Scribd logo
1  sur  14
Télécharger pour lire hors ligne
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

Contenu connexe

En vedette

En vedette (13)

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

Plus de John De Goes

Refactoring Functional Type Classes
Refactoring Functional Type ClassesRefactoring Functional Type Classes
Refactoring Functional Type Classes
John De Goes
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final Tagless
John De Goes
 
Orthogonal Functional Architecture
Orthogonal Functional ArchitectureOrthogonal Functional Architecture
Orthogonal Functional Architecture
John De Goes
 
Post-Free: Life After Free Monads
Post-Free: Life After Free MonadsPost-Free: Life After Free Monads
Post-Free: Life After Free Monads
John De Goes
 

Plus de John De Goes (18)

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

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.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