Inverse Problems in Semiconductor Devices Martin Burger Johannes Kepler Universität Linz.
Functional reactive programminglambdor.net/wp-content/uploads/2012/06/2012 - Functional...Seminar...
Transcript of Functional reactive programminglambdor.net/wp-content/uploads/2012/06/2012 - Functional...Seminar...
inSeminar Methods and Applications of Functional Programming
Johannes Kepler University, Linz SS2012
by Gerold Meisinger
Functional reactive programming
What is FRP?
New paradigm Time-varying values
Behavior a :: Time → a Hybrid modeling
Continous-time Discrete events
React to input
Similarities
Paradigms Dataflow
Common Lisp/Cells Temporal logic Control theory ...
Languages Esterel Lustre Lucid Signal Synchrone Simulink Modelica ...
FRP implementations
Classic FRP e.g. Fran, FrTime
Push-pull FRP e.g. Reactive
Arrowized FRP e.g. Yampa, Elera
Classic game programming
interface IUpdateablevoid update( float elapsedTime )
class GameObject : IUpdateableVector3 positionVector3 velocityvoid update( float elapsedTime ) position += elapsedTime * velocity
Yampa semantics
Signal a :: Time → a Only used internally
SF a b :: Signal a → Signal b SF … signal function
data Event t = NoEvent | Event t
Yampa design goals
Continous-time & discrete events Denotative semantics Dynamic structures Higher-orderness Avoid time and space leaks ⇒ Arrow typeclass Synchronous (vs concurrent)
Arrow class
class Arrow a wherearr :: (b → c) → a b c(<<<) :: a b c → a c d → a b dfirst :: a b c → a (b, d) (c, d)
+ lots of arrow lawsderive combinators: second, (***), (&&&)
Derived Arrow combinators
second :: (Arrow a) a b c → a (d, b) (d, c)⇒
second f = arr swap >>> first f >>> arr swapwhere swap (a, b) = (b, a)
(***) :: (Arrow a) a b c → a b' c' → a (b, b') (c, c')⇒
f ⋆⋆⋆ g = first f >>> second g
(&&&) :: (Arrow a) a b c → a b c' → a b (c, c')⇒
f &&& g = arr (λx → (x, x)) >>> (f *** g)
ArrowCircuit
class Arrow a ArrowCircuit a where⇒
loop :: a (b, d) (c, d) → a b cinit :: b → a b b
+ even more laws
Arrow syntax
myArrow x y = proc (a, b) → do c1 ← arrow1 −< a c2 ← arrow3 <<< arrow2 −< b c ← arrow4 −< (c1, c2) rec d ← arrow5 −< (c, b, d) returnA (c, d)
Yampa parallel switch
pSwitch :: Functor col => (forall sf. (in → col sf → col (ext, sf))) → col (SF ext out) → SF (in, col out) (Event mng) → (col (SF ext out) → mng → SF in (col out)) → SF in (col out)
Yampa switches
immediate delayedonce switch dSwitchrecurring rSwitch drSwitchparallel broadcasted pSwitchB
rpSwitchBdpSwitchBdrpSwitchB
parallel routed pSwitchrpSwitch
dpSwitchdrpSwitch
continuation kSwitch dkSwitch
Ongoing research
Semantics "Garbage collecting the semantics of FRP" "Why classic FRP does not fit interactive behavior"
Performance Causal Commutative Arrows (CCA) Concurrency Arrow tuples vs. signal combining
Yampa alternatives
ELM Web runtime and IDE => converts to JavaScripthttp://elm-lang.org
Reactive-Banana Many exampleshttp://apfelmus.nfshost.com