Functional reactive programming                            inSeminar Methods and Applications of Functional Programming   ...
Background   FH Hagenberg       Digital Media   FRP diploma thesis   Gamedev startup    ”Modern Alchemists”
Types of programs    Transformative      Interactive       Reactive
What is FRP?   New paradigm   Time-varying values        Behavior a :: Time → a   Hybrid modeling       Continous-time...
Paradigms (by Van Roy)
Similarities    Paradigms                     Languages   Dataflow                     Esterel         Common Lisp/Cell...
Dataflow programming
FRP implementations   Classic FRP       e.g. Fran, FrTime   Push-pull FRP       e.g. Reactive   Arrowized FRP       ...
Yampa examples   Robotics   GUIs   Games   Music synthesis   Computer vision   Networking   ...
Classic game programminginterface IUpdateable  void update( float elapsedTime )class GameObject : IUpdateable  Vector3 pos...
Yampa semanticsSignal a :: Time → a   Only used internallySF a b :: Signal a → Signal b   SF … signal functiondata Event...
Yampa design goals   Continous-time & discrete events   Denotative semantics   Dynamic structures   Higher-orderness ...
Transformative    f :: a → b
Interactive
Reactive
Temporal
Loop >
Loop > Processing (black-box)
Loop > Processing
Loop > Processing >
Loop > Processing > SF (BB)
Loop > Processing > SF
Loop > Processing > SF
Loop > Processing > SF
Loop > Processing > SF
Loop > Processing > SF Mover
Loop > Processing > Mover
Loop > Processing > Mover
Loop > Processing >
Loop > Processing
Loop > Processing
Loop > Processing Player
Example game: Fran
Haskell typeclasses   (by Yorgey)
Arrow classclass Arrow a where  arr   :: (b → c) → a b c  (<<<) :: a b c → a c d → a b d  first :: a b c → a (b, d) (c, d)...
Arrow combinators
Derived Arrow combinatorssecond :: (Arrow a) ⇒ a b c → a (d, b) (d, c)second f = arr swap >>> first f >>> arr swap  where ...
ArrowCircuitclass Arrow a ⇒ ArrowCircuit a where   loop :: a (b, d) (c, d) → a b c   init :: b → a b b+ even more laws
Arrow syntax       myArrow x y = proc (a, b) → do         c1 ← arrow1 −< a         c2 ← arrow3 <<< arrow2 −< b         c  ...
Signal function primitives
Events
Yampa switchswitch ::     SF in (out, Event t)       → (t → SF in   out)       →     SF in    out
Yampa parallel switchpSwitch :: Functor col       => (forall sf. (in → col sf → col (ext, sf)))        → col (SF ext out) ...
Yampa switches                       immediate   delayedonce                   switch      dSwitchrecurring              r...
Processingreactimate :: IO (DTime, a) –- input            → (b → IO ())   –- output            → SF a b            → IO ()
Game-Engine
Ongoing research   Semantics       "Garbage collecting the semantics of FRP"       "Why classic FRP does not fit intera...
Yampa alternatives   ELM       Web runtime and IDE => converts to JavaScript        http://elm-lang.org   Reactive-Bana...
The Endhttp://lambdor.net
Upcoming SlideShare
Loading in …5
×

Functional Reactive Programming by Gerold Meisinger

2,851 views

Published on

Published in: Technology
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,851
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
45
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

Functional Reactive Programming by Gerold Meisinger

  1. 1. Functional reactive programming inSeminar Methods and Applications of Functional Programming Johannes Kepler University, Linz SS2012 by Gerold Meisinger
  2. 2. Background FH Hagenberg  Digital Media FRP diploma thesis Gamedev startup ”Modern Alchemists”
  3. 3. Types of programs Transformative Interactive Reactive
  4. 4. What is FRP? New paradigm Time-varying values Behavior a :: Time → a Hybrid modeling  Continous-time  Discrete events React to input
  5. 5. Paradigms (by Van Roy)
  6. 6. Similarities Paradigms Languages Dataflow  Esterel  Common Lisp/Cells  Lustre Temporal logic  Lucid Control theory  Signal ...  Synchrone  Simulink  Modelica  ...
  7. 7. Dataflow programming
  8. 8. FRP implementations Classic FRP  e.g. Fran, FrTime Push-pull FRP  e.g. Reactive Arrowized FRP  e.g. Yampa, Elera
  9. 9. Yampa examples Robotics GUIs Games Music synthesis Computer vision Networking ...
  10. 10. Classic game programminginterface IUpdateable void update( float elapsedTime )class GameObject : IUpdateable Vector3 position Vector3 velocity void update( float elapsedTime ) position += elapsedTime * velocity
  11. 11. Yampa semanticsSignal a :: Time → a Only used internallySF a b :: Signal a → Signal b SF … signal functiondata Event t = NoEvent | Event t
  12. 12. Yampa design goals Continous-time & discrete events Denotative semantics Dynamic structures Higher-orderness Avoid time and space leaks ⇒ Arrow typeclass Synchronous (vs concurrent)
  13. 13. Transformative f :: a → b
  14. 14. Interactive
  15. 15. Reactive
  16. 16. Temporal
  17. 17. Loop >
  18. 18. Loop > Processing (black-box)
  19. 19. Loop > Processing
  20. 20. Loop > Processing >
  21. 21. Loop > Processing > SF (BB)
  22. 22. Loop > Processing > SF
  23. 23. Loop > Processing > SF
  24. 24. Loop > Processing > SF
  25. 25. Loop > Processing > SF
  26. 26. Loop > Processing > SF Mover
  27. 27. Loop > Processing > Mover
  28. 28. Loop > Processing > Mover
  29. 29. Loop > Processing >
  30. 30. Loop > Processing
  31. 31. Loop > Processing
  32. 32. Loop > Processing Player
  33. 33. Example game: Fran
  34. 34. Haskell typeclasses (by Yorgey)
  35. 35. Arrow classclass Arrow a where arr :: (b → c) → a b c (<<<) :: a b c → a c d → a b d first :: a b c → a (b, d) (c, d)+ lots of arrow lawsderive combinators: second, (***), (&&&)
  36. 36. Arrow combinators
  37. 37. Derived Arrow combinatorssecond :: (Arrow a) ⇒ a b c → a (d, b) (d, c)second f = arr swap >>> first f >>> arr swap where 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)
  38. 38. ArrowCircuitclass Arrow a ⇒ ArrowCircuit a where loop :: a (b, d) (c, d) → a b c init :: b → a b b+ even more laws
  39. 39. 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)
  40. 40. Signal function primitives
  41. 41. Events
  42. 42. Yampa switchswitch :: SF in (out, Event t) → (t → SF in out) → SF in out
  43. 43. Yampa parallel switchpSwitch :: 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)
  44. 44. Yampa switches immediate delayedonce switch dSwitchrecurring rSwitch drSwitchparallel broadcasted pSwitchB dpSwitchB rpSwitchB drpSwitchBparallel routed pSwitch dpSwitch rpSwitch drpSwitchcontinuation kSwitch dkSwitch
  45. 45. Processingreactimate :: IO (DTime, a) –- input → (b → IO ()) –- output → SF a b → IO ()
  46. 46. Game-Engine
  47. 47. 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
  48. 48. Yampa alternatives ELM  Web runtime and IDE => converts to JavaScript http://elm-lang.org Reactive-Banana  Many examples http://apfelmus.nfshost.com
  49. 49. The Endhttp://lambdor.net

×