SlideShare a Scribd company logo
Functional Reactive
Programming
指導老師:陳恭
學生:蔡詠捷
Introduce FRP
• FRP is a subset of Functional Programming
and Reactive Programming
What is FRP
• Use observer pattern.
• Modular way to code event-driven.
• Expressed as a reaction to its inputs.
• Expressed as a flow of data.
• Management of program state.
• Replaces the listeners and callbacks.
Why FRP?
• Compositionality.
• Declaratively programming style.
• Code structure like directed graph, and FRP
engine execution order automatically.
• FRP allows functional programming to be used
as a meta-language for writing event-based
logic
Why FRP?
• Interactive applications without the bugs
– Unpredictable order
– Missed first event
– Messy state
– Threading issues
– Leaking callbacks
– Accidental recursion
Life cycle of FRP
• Stage 1 : Initialization–Typically during
program start-up, FRP code statements are
converted into a directed graph in memory.
Life cycle of FRP
• Stage 2: Running–For the rest of the program
execution we feed values in, turn the crank
handle, and the FRP engine produces output.
Thinking in FRP
• Try to make things declaratively
• This style is referred to as declarative
programming
– We are telling the machine what the program is,
not what it does.
Sodium - FRP Library
• Sodium is a push-based system.
• Not all FRP systems use listeners internally.
• Push-based FRP systems typically do, but
there are also pull-based systems.
Fundamental data types
• Cell
– Represents a value that changes over time.
• Definition of Cell
– A container for a value that changes over time.
– Some FRP systems call it a behavior, property or a
signal
Fundamental data types
• Stream
– Represents a stream of events.
• Definition of Stream
– A stream of discrete events.
– It is also known in other FRP systems as event,
event stream, observable or signal.
– When an event propagates through a stream, we
sometimes say that the stream has fired.
Fundamental data types
• Arrows represent streams.
• Boxes represent transformations.
• Conceptual modules shown as clouds.
Lambda Syntax
• The new lambda syntax in Java 8 lets us write
this much shorter, with no fewer than six
variations of the syntax:
– (Integer k) -> { return k+1; }
– (k) -> { return k+1; }
– k -> { return k+1; }
– (Integer k) -> k+1
– (k) -> k+1
– k -> k+1
FRP Programming Tips
• Do not perform any I/O.
• Do not throw any exceptions unless they are
caught and handled within the function.
• Do not read the value of any external variable
if its value can change, but constants are
allowed and encourage.
• Do not modify any externally visible state.
FRP Programming Tips
• Do not keep any state between invocations of
the function.
• The function must have no external effects
other than through the returned value
• It must not be affected by any external state.
FRP primitives overview
Output as Stream Output as Cell Output as value
Stream map()
merge()/orElse()
snapshot()
filter()
never/new
Stream()
hold()
Cell switchS() map()
lift()
new Cell(constant)
switchC()
sample()
FRP Primitives
• map
– map transforms a Stream into a new Stream of
the same type or a different type.
FRP Primitives
• merge
– The merge primitives puts the events from two
streams together into a single stream.
FRP Primitives
• hold
– The hold primitive converts a stream into a cell in
such a way that the cell's value is that of the most
recent event received.
– Also named stepper or toProperty.
FRP Primitives
• snapshot
– The snapshot primitive captures the value of a cell
at the time when a stream event fires, and it can
then combine the stream and cell events together
with a supplied function.
– Also named withLatest, attach, or tag.
FRP Primitives
• filter
– To filter a stream is to let values through only
sometimes.
FRP Primitives
• lift
– Lift is a functional programming term meaning
(more generally) to make a function that operates
on values into a function that operates on some
type of container of those values.
FRP Primitives
• never
– In FRP a never stream is one that can't ever fire.
This name is universal in FRP systems.
– Only use in Stream.
FRP Primitives
• constant
– Cells usually change over time, but it's also
possible to construct them with a constant value.
– There is no way to modify a cell after it is created,
so its value is guaranteed to be constant forever.
– Only use in Cell.
FRP Primitives
• sample
– Return the value of the cell.
Link
• Example of the book :
– https://github.com/SodiumFRP
• Example of my own view :
– https://github.com/PhyrexTsai/SodiumFRPExample/
Reference
• S. Blackheath, A. Jones. Functional Reactive
Programming

More Related Content

What's hot

Introduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsIntroduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actors
Shashank L
 
Hm system programming class 1
Hm system programming class 1Hm system programming class 1
Hm system programming class 1
Hitesh Mohapatra
 
Introduction of A Lightweight Stage-Programming Framework
Introduction of A Lightweight Stage-Programming FrameworkIntroduction of A Lightweight Stage-Programming Framework
Introduction of A Lightweight Stage-Programming Framework
Yu Liu
 
Welch Verolog 2013
Welch Verolog 2013Welch Verolog 2013
Welch Verolog 2013Philip Welch
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1Manoj Patil
 
Concept Drift: Monitoring Model Quality In Streaming ML Applications
Concept Drift: Monitoring Model Quality In Streaming ML ApplicationsConcept Drift: Monitoring Model Quality In Streaming ML Applications
Concept Drift: Monitoring Model Quality In Streaming ML Applications
Lightbend
 
Unit 3
Unit 3Unit 3
Unit 3
pm_ghate
 
Lecture2 1 types of programming languages
Lecture2 1 types of programming languagesLecture2 1 types of programming languages
Lecture2 1 types of programming languagesYog Maya
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
Temesgen Molla
 
Streaming your Lyft Ride Prices - Flink Forward SF 2019
Streaming your Lyft Ride Prices - Flink Forward SF 2019Streaming your Lyft Ride Prices - Flink Forward SF 2019
Streaming your Lyft Ride Prices - Flink Forward SF 2019
Thomas Weise
 
Ml also helps generic compiler ?
Ml also helps generic compiler ?Ml also helps generic compiler ?
Ml also helps generic compiler ?
Ryo Takahashi
 
Владимир Иванов. JIT для Java разработчиков
Владимир Иванов. JIT для Java разработчиковВладимир Иванов. JIT для Java разработчиков
Владимир Иванов. JIT для Java разработчиковVolha Banadyseva
 
Task Parallel Library Data Flows
Task Parallel Library Data FlowsTask Parallel Library Data Flows
Task Parallel Library Data FlowsSANKARSAN BOSE
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
Malek Sumaiya
 
Functional Programming in Java
Functional Programming in JavaFunctional Programming in Java
Functional Programming in Java
Jim Bethancourt
 
Service-Oriented Architectures: From Design to Production Exploiting Workflow...
Service-Oriented Architectures: From Design to Production Exploiting Workflow...Service-Oriented Architectures: From Design to Production Exploiting Workflow...
Service-Oriented Architectures: From Design to Production Exploiting Workflow...
IMDS2014
 
Lecture1 introduction compilers
Lecture1 introduction compilersLecture1 introduction compilers
Lecture1 introduction compilers
Mahesh Kumar Chelimilla
 
Julia Computing - an alternative to Hadoop
Julia Computing - an alternative to HadoopJulia Computing - an alternative to Hadoop
Julia Computing - an alternative to Hadoop
Shaurya Shekhar
 

What's hot (20)

Introduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsIntroduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actors
 
Hm system programming class 1
Hm system programming class 1Hm system programming class 1
Hm system programming class 1
 
Introduction of A Lightweight Stage-Programming Framework
Introduction of A Lightweight Stage-Programming FrameworkIntroduction of A Lightweight Stage-Programming Framework
Introduction of A Lightweight Stage-Programming Framework
 
Welch Verolog 2013
Welch Verolog 2013Welch Verolog 2013
Welch Verolog 2013
 
Lecture6
Lecture6Lecture6
Lecture6
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Concept Drift: Monitoring Model Quality In Streaming ML Applications
Concept Drift: Monitoring Model Quality In Streaming ML ApplicationsConcept Drift: Monitoring Model Quality In Streaming ML Applications
Concept Drift: Monitoring Model Quality In Streaming ML Applications
 
Unit 3
Unit 3Unit 3
Unit 3
 
Lecture2 1 types of programming languages
Lecture2 1 types of programming languagesLecture2 1 types of programming languages
Lecture2 1 types of programming languages
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 
Streaming your Lyft Ride Prices - Flink Forward SF 2019
Streaming your Lyft Ride Prices - Flink Forward SF 2019Streaming your Lyft Ride Prices - Flink Forward SF 2019
Streaming your Lyft Ride Prices - Flink Forward SF 2019
 
Ml also helps generic compiler ?
Ml also helps generic compiler ?Ml also helps generic compiler ?
Ml also helps generic compiler ?
 
Владимир Иванов. JIT для Java разработчиков
Владимир Иванов. JIT для Java разработчиковВладимир Иванов. JIT для Java разработчиков
Владимир Иванов. JIT для Java разработчиков
 
Task Parallel Library Data Flows
Task Parallel Library Data FlowsTask Parallel Library Data Flows
Task Parallel Library Data Flows
 
Callgraph analysis
Callgraph analysisCallgraph analysis
Callgraph analysis
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
 
Functional Programming in Java
Functional Programming in JavaFunctional Programming in Java
Functional Programming in Java
 
Service-Oriented Architectures: From Design to Production Exploiting Workflow...
Service-Oriented Architectures: From Design to Production Exploiting Workflow...Service-Oriented Architectures: From Design to Production Exploiting Workflow...
Service-Oriented Architectures: From Design to Production Exploiting Workflow...
 
Lecture1 introduction compilers
Lecture1 introduction compilersLecture1 introduction compilers
Lecture1 introduction compilers
 
Julia Computing - an alternative to Hadoop
Julia Computing - an alternative to HadoopJulia Computing - an alternative to Hadoop
Julia Computing - an alternative to Hadoop
 

Viewers also liked

The essence of Reactive Programming
The essence of Reactive ProgrammingThe essence of Reactive Programming
The essence of Reactive Programming
Eddy Bertoluzzo
 
1.7 functional programming
1.7 functional programming1.7 functional programming
1.7 functional programmingfuturespective
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and Web
Publitory
 
The taste of F#
The taste of F#The taste of F#
The taste of F#
☁️ Mikhail Shilkov
 
Designing with Capabilities
Designing with CapabilitiesDesigning with Capabilities
Designing with Capabilities
Scott Wlaschin
 
Real-World Functional Programming @ Incubaid
Real-World Functional Programming @ IncubaidReal-World Functional Programming @ Incubaid
Real-World Functional Programming @ Incubaid
Nicolas Trangez
 
Doge-driven design
Doge-driven designDoge-driven design
Doge-driven design
Scott Wlaschin
 
The Theory of Chains
The Theory of ChainsThe Theory of Chains
The Theory of Chains
Scott Wlaschin
 
Slick 3.0 functional programming and db side effects
Slick 3.0   functional programming and db side effectsSlick 3.0   functional programming and db side effects
Slick 3.0 functional programming and db side effects
Joost de Vries
 
Functional programming
Functional programmingFunctional programming
Functional programming
Hideshi Ogoshi
 
Dr Frankenfunctor and the Monadster
Dr Frankenfunctor and the MonadsterDr Frankenfunctor and the Monadster
Dr Frankenfunctor and the Monadster
Scott Wlaschin
 
Swift vs. Language X
Swift vs. Language XSwift vs. Language X
Swift vs. Language X
Scott Wlaschin
 
Functional Programming with C#
Functional Programming with C#Functional Programming with C#
Functional Programming with C#
EastBanc Tachnologies
 
16 logical programming
16 logical programming16 logical programming
16 logical programmingjigeno
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
elliando dias
 
Domain Driven Design with the F# type System -- NDC London 2013
Domain Driven Design with the F# type System -- NDC London 2013Domain Driven Design with the F# type System -- NDC London 2013
Domain Driven Design with the F# type System -- NDC London 2013
Scott Wlaschin
 
Designing with capabilities (DDD-EU 2017)
Designing with capabilities (DDD-EU 2017)Designing with capabilities (DDD-EU 2017)
Designing with capabilities (DDD-EU 2017)
Scott Wlaschin
 
Thirteen ways of looking at a turtle
Thirteen ways of looking at a turtleThirteen ways of looking at a turtle
Thirteen ways of looking at a turtle
Scott Wlaschin
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
Alfonso Garcia-Caro
 
[FT-11][ltchen] A Tale of Two Monads
[FT-11][ltchen] A Tale of Two Monads[FT-11][ltchen] A Tale of Two Monads
[FT-11][ltchen] A Tale of Two Monads
Functional Thursday
 

Viewers also liked (20)

The essence of Reactive Programming
The essence of Reactive ProgrammingThe essence of Reactive Programming
The essence of Reactive Programming
 
1.7 functional programming
1.7 functional programming1.7 functional programming
1.7 functional programming
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and Web
 
The taste of F#
The taste of F#The taste of F#
The taste of F#
 
Designing with Capabilities
Designing with CapabilitiesDesigning with Capabilities
Designing with Capabilities
 
Real-World Functional Programming @ Incubaid
Real-World Functional Programming @ IncubaidReal-World Functional Programming @ Incubaid
Real-World Functional Programming @ Incubaid
 
Doge-driven design
Doge-driven designDoge-driven design
Doge-driven design
 
The Theory of Chains
The Theory of ChainsThe Theory of Chains
The Theory of Chains
 
Slick 3.0 functional programming and db side effects
Slick 3.0   functional programming and db side effectsSlick 3.0   functional programming and db side effects
Slick 3.0 functional programming and db side effects
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Dr Frankenfunctor and the Monadster
Dr Frankenfunctor and the MonadsterDr Frankenfunctor and the Monadster
Dr Frankenfunctor and the Monadster
 
Swift vs. Language X
Swift vs. Language XSwift vs. Language X
Swift vs. Language X
 
Functional Programming with C#
Functional Programming with C#Functional Programming with C#
Functional Programming with C#
 
16 logical programming
16 logical programming16 logical programming
16 logical programming
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Domain Driven Design with the F# type System -- NDC London 2013
Domain Driven Design with the F# type System -- NDC London 2013Domain Driven Design with the F# type System -- NDC London 2013
Domain Driven Design with the F# type System -- NDC London 2013
 
Designing with capabilities (DDD-EU 2017)
Designing with capabilities (DDD-EU 2017)Designing with capabilities (DDD-EU 2017)
Designing with capabilities (DDD-EU 2017)
 
Thirteen ways of looking at a turtle
Thirteen ways of looking at a turtleThirteen ways of looking at a turtle
Thirteen ways of looking at a turtle
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
 
[FT-11][ltchen] A Tale of Two Monads
[FT-11][ltchen] A Tale of Two Monads[FT-11][ltchen] A Tale of Two Monads
[FT-11][ltchen] A Tale of Two Monads
 

Similar to Frp

10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprograms
Munawar Ahmed
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
Martijn Verburg
 
Lambda.pdf
Lambda.pdfLambda.pdf
Lambda.pdf
ManishWalia18
 
Presentation systemc
Presentation systemcPresentation systemc
Presentation systemc
SUBRAHMANYA S
 
Lagom - Mircoservices "Just Right"
Lagom - Mircoservices "Just Right"Lagom - Mircoservices "Just Right"
Lagom - Mircoservices "Just Right"
Markus Jura
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural Programming
Deepam Aggarwal
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
Martijn Verburg
 
Spark Summit EU talk by Mikhail Semeniuk Hollin Wilkins
Spark Summit EU talk by Mikhail Semeniuk Hollin WilkinsSpark Summit EU talk by Mikhail Semeniuk Hollin Wilkins
Spark Summit EU talk by Mikhail Semeniuk Hollin Wilkins
Spark Summit
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014Thomas Lockney
 
Scalable Data Science with SparkR: Spark Summit East talk by Felix Cheung
Scalable Data Science with SparkR: Spark Summit East talk by Felix CheungScalable Data Science with SparkR: Spark Summit East talk by Felix Cheung
Scalable Data Science with SparkR: Spark Summit East talk by Felix Cheung
Spark Summit
 
Reactive Streams, Linking Reactive Application To Spark Streaming
Reactive Streams, Linking Reactive Application To Spark StreamingReactive Streams, Linking Reactive Application To Spark Streaming
Reactive Streams, Linking Reactive Application To Spark Streaming
Spark Summit
 
JAVA 8 Parallel Stream
JAVA 8 Parallel StreamJAVA 8 Parallel Stream
JAVA 8 Parallel StreamTengwen Wang
 
Get Functional Programming with Clojure
Get Functional Programming with ClojureGet Functional Programming with Clojure
Get Functional Programming with Clojure
John Stevenson
 
Reactive Streams, linking Reactive Application to Spark Streaming by Luc Bour...
Reactive Streams, linking Reactive Application to Spark Streaming by Luc Bour...Reactive Streams, linking Reactive Application to Spark Streaming by Luc Bour...
Reactive Streams, linking Reactive Application to Spark Streaming by Luc Bour...
Spark Summit
 
Survey of Program Transformation Technologies
Survey of Program Transformation TechnologiesSurvey of Program Transformation Technologies
Survey of Program Transformation Technologies
Chunhua Liao
 
Reactive Software Systems
Reactive Software SystemsReactive Software Systems
Reactive Software Systems
Behrad Zari
 
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Codemotion
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with Clojure
John Stevenson
 

Similar to Frp (20)

10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprograms
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Lambda.pdf
Lambda.pdfLambda.pdf
Lambda.pdf
 
Lecture7
Lecture7Lecture7
Lecture7
 
Presentation systemc
Presentation systemcPresentation systemc
Presentation systemc
 
Lagom - Mircoservices "Just Right"
Lagom - Mircoservices "Just Right"Lagom - Mircoservices "Just Right"
Lagom - Mircoservices "Just Right"
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural Programming
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
 
Spark Summit EU talk by Mikhail Semeniuk Hollin Wilkins
Spark Summit EU talk by Mikhail Semeniuk Hollin WilkinsSpark Summit EU talk by Mikhail Semeniuk Hollin Wilkins
Spark Summit EU talk by Mikhail Semeniuk Hollin Wilkins
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014
 
Scalable Data Science with SparkR: Spark Summit East talk by Felix Cheung
Scalable Data Science with SparkR: Spark Summit East talk by Felix CheungScalable Data Science with SparkR: Spark Summit East talk by Felix Cheung
Scalable Data Science with SparkR: Spark Summit East talk by Felix Cheung
 
Reactive Streams, Linking Reactive Application To Spark Streaming
Reactive Streams, Linking Reactive Application To Spark StreamingReactive Streams, Linking Reactive Application To Spark Streaming
Reactive Streams, Linking Reactive Application To Spark Streaming
 
JAVA 8 Parallel Stream
JAVA 8 Parallel StreamJAVA 8 Parallel Stream
JAVA 8 Parallel Stream
 
Get Functional Programming with Clojure
Get Functional Programming with ClojureGet Functional Programming with Clojure
Get Functional Programming with Clojure
 
Reactive Streams, linking Reactive Application to Spark Streaming by Luc Bour...
Reactive Streams, linking Reactive Application to Spark Streaming by Luc Bour...Reactive Streams, linking Reactive Application to Spark Streaming by Luc Bour...
Reactive Streams, linking Reactive Application to Spark Streaming by Luc Bour...
 
Survey of Program Transformation Technologies
Survey of Program Transformation TechnologiesSurvey of Program Transformation Technologies
Survey of Program Transformation Technologies
 
Reactive Software Systems
Reactive Software SystemsReactive Software Systems
Reactive Software Systems
 
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with Clojure
 

Recently uploaded

DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
Wasswaderrick3
 
Phenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvementPhenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvement
IshaGoswami9
 
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Sérgio Sacani
 
GBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram StainingGBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram Staining
Areesha Ahmad
 
Nucleic Acid-its structural and functional complexity.
Nucleic Acid-its structural and functional complexity.Nucleic Acid-its structural and functional complexity.
Nucleic Acid-its structural and functional complexity.
Nistarini College, Purulia (W.B) India
 
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
Studia Poinsotiana
 
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
University of Maribor
 
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
University of Maribor
 
Lateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensiveLateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensive
silvermistyshot
 
Deep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless ReproducibilityDeep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless Reproducibility
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
Richard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlandsRichard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlands
Richard Gill
 
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATIONPRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
ChetanK57
 
3D Hybrid PIC simulation of the plasma expansion (ISSS-14)
3D Hybrid PIC simulation of the plasma expansion (ISSS-14)3D Hybrid PIC simulation of the plasma expansion (ISSS-14)
3D Hybrid PIC simulation of the plasma expansion (ISSS-14)
David Osipyan
 
What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.
moosaasad1975
 
Introduction to Mean Field Theory(MFT).pptx
Introduction to Mean Field Theory(MFT).pptxIntroduction to Mean Field Theory(MFT).pptx
Introduction to Mean Field Theory(MFT).pptx
zeex60
 
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Sérgio Sacani
 
S.1 chemistry scheme term 2 for ordinary level
S.1 chemistry scheme term 2 for ordinary levelS.1 chemistry scheme term 2 for ordinary level
S.1 chemistry scheme term 2 for ordinary level
ronaldlakony0
 
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdfUnveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Erdal Coalmaker
 
in vitro propagation of plants lecture note.pptx
in vitro propagation of plants lecture note.pptxin vitro propagation of plants lecture note.pptx
in vitro propagation of plants lecture note.pptx
yusufzako14
 
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Ana Luísa Pinho
 

Recently uploaded (20)

DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
 
Phenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvementPhenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvement
 
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
 
GBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram StainingGBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram Staining
 
Nucleic Acid-its structural and functional complexity.
Nucleic Acid-its structural and functional complexity.Nucleic Acid-its structural and functional complexity.
Nucleic Acid-its structural and functional complexity.
 
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
 
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
 
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
 
Lateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensiveLateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensive
 
Deep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless ReproducibilityDeep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless Reproducibility
 
Richard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlandsRichard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlands
 
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATIONPRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
 
3D Hybrid PIC simulation of the plasma expansion (ISSS-14)
3D Hybrid PIC simulation of the plasma expansion (ISSS-14)3D Hybrid PIC simulation of the plasma expansion (ISSS-14)
3D Hybrid PIC simulation of the plasma expansion (ISSS-14)
 
What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.
 
Introduction to Mean Field Theory(MFT).pptx
Introduction to Mean Field Theory(MFT).pptxIntroduction to Mean Field Theory(MFT).pptx
Introduction to Mean Field Theory(MFT).pptx
 
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
 
S.1 chemistry scheme term 2 for ordinary level
S.1 chemistry scheme term 2 for ordinary levelS.1 chemistry scheme term 2 for ordinary level
S.1 chemistry scheme term 2 for ordinary level
 
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdfUnveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdf
 
in vitro propagation of plants lecture note.pptx
in vitro propagation of plants lecture note.pptxin vitro propagation of plants lecture note.pptx
in vitro propagation of plants lecture note.pptx
 
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
 

Frp

  • 2. Introduce FRP • FRP is a subset of Functional Programming and Reactive Programming
  • 3. What is FRP • Use observer pattern. • Modular way to code event-driven. • Expressed as a reaction to its inputs. • Expressed as a flow of data. • Management of program state. • Replaces the listeners and callbacks.
  • 4. Why FRP? • Compositionality. • Declaratively programming style. • Code structure like directed graph, and FRP engine execution order automatically. • FRP allows functional programming to be used as a meta-language for writing event-based logic
  • 5. Why FRP? • Interactive applications without the bugs – Unpredictable order – Missed first event – Messy state – Threading issues – Leaking callbacks – Accidental recursion
  • 6. Life cycle of FRP • Stage 1 : Initialization–Typically during program start-up, FRP code statements are converted into a directed graph in memory.
  • 7. Life cycle of FRP • Stage 2: Running–For the rest of the program execution we feed values in, turn the crank handle, and the FRP engine produces output.
  • 8. Thinking in FRP • Try to make things declaratively • This style is referred to as declarative programming – We are telling the machine what the program is, not what it does.
  • 9. Sodium - FRP Library • Sodium is a push-based system. • Not all FRP systems use listeners internally. • Push-based FRP systems typically do, but there are also pull-based systems.
  • 10. Fundamental data types • Cell – Represents a value that changes over time. • Definition of Cell – A container for a value that changes over time. – Some FRP systems call it a behavior, property or a signal
  • 11. Fundamental data types • Stream – Represents a stream of events. • Definition of Stream – A stream of discrete events. – It is also known in other FRP systems as event, event stream, observable or signal. – When an event propagates through a stream, we sometimes say that the stream has fired.
  • 12. Fundamental data types • Arrows represent streams. • Boxes represent transformations. • Conceptual modules shown as clouds.
  • 13. Lambda Syntax • The new lambda syntax in Java 8 lets us write this much shorter, with no fewer than six variations of the syntax: – (Integer k) -> { return k+1; } – (k) -> { return k+1; } – k -> { return k+1; } – (Integer k) -> k+1 – (k) -> k+1 – k -> k+1
  • 14. FRP Programming Tips • Do not perform any I/O. • Do not throw any exceptions unless they are caught and handled within the function. • Do not read the value of any external variable if its value can change, but constants are allowed and encourage. • Do not modify any externally visible state.
  • 15. FRP Programming Tips • Do not keep any state between invocations of the function. • The function must have no external effects other than through the returned value • It must not be affected by any external state.
  • 16. FRP primitives overview Output as Stream Output as Cell Output as value Stream map() merge()/orElse() snapshot() filter() never/new Stream() hold() Cell switchS() map() lift() new Cell(constant) switchC() sample()
  • 17. FRP Primitives • map – map transforms a Stream into a new Stream of the same type or a different type.
  • 18. FRP Primitives • merge – The merge primitives puts the events from two streams together into a single stream.
  • 19. FRP Primitives • hold – The hold primitive converts a stream into a cell in such a way that the cell's value is that of the most recent event received. – Also named stepper or toProperty.
  • 20. FRP Primitives • snapshot – The snapshot primitive captures the value of a cell at the time when a stream event fires, and it can then combine the stream and cell events together with a supplied function. – Also named withLatest, attach, or tag.
  • 21. FRP Primitives • filter – To filter a stream is to let values through only sometimes.
  • 22. FRP Primitives • lift – Lift is a functional programming term meaning (more generally) to make a function that operates on values into a function that operates on some type of container of those values.
  • 23. FRP Primitives • never – In FRP a never stream is one that can't ever fire. This name is universal in FRP systems. – Only use in Stream.
  • 24. FRP Primitives • constant – Cells usually change over time, but it's also possible to construct them with a constant value. – There is no way to modify a cell after it is created, so its value is guaranteed to be constant forever. – Only use in Cell.
  • 25. FRP Primitives • sample – Return the value of the cell.
  • 26. Link • Example of the book : – https://github.com/SodiumFRP • Example of my own view : – https://github.com/PhyrexTsai/SodiumFRPExample/
  • 27. Reference • S. Blackheath, A. Jones. Functional Reactive Programming

Editor's Notes

  1. 使用觀察者模式 用模組化方式撰寫事件驅動程式 表示輸入的反應 表示資料的流程 程序狀態管理 取代傳統的 listeners 與 callbacks
  2. 程式可組合性 聲明式的程式撰寫方式 程式結構類似圖形,並且FRP的引擎會自動執行 FRP 可以使用 functional programming 來寫 event-base 的邏輯
  3. 順序不可預期性 Miss 第一個 event 麻煩的 state
  4. Initialize 的時候會將 FRP code 都轉成圖形化存在記憶體內
  5. 在執行階段的時候會將輸入的值透過FRP引擎轉成輸出值
  6. 聲明式的表達一件事情
  7. Sodium 使用 Push-based
  8. Discrete 分離