14. What FRP isn’t
• Reactive Programming is not FRP
• ReactiveX(RxJS, RxSwift, etc), ReactiveCocoa
ReactiveX may be functional, and it may be reactive, but
“functional reactive programming” is a different animal.
On ReactiveX - Intro
@noraesae
15. What FRP isn’t
• Neither of this kind of graphs
Staltz, A. (2014). “The introduction to Reactive Programming you’ve been missing.”
• Stream, Observable, etc...
@noraesae
27. “Functional Reactive Animation.”
Elliott, C, Hudak, P. (1997). In ICFP ’97.
• Behaviour a
• Time-varying data
• red :: Behaviour Color
• view :: Behaviour Html
@noraesae
32. “Functional Reactive Animation.”
Elliott, C, Hudak, P. (1997). In ICFP ’97.
• Event a
• Time-specific data
• everySecond :: Event Int
• click :: Event Mouse
@noraesae
33. “Functional Reactive Animation.”
Elliott, C, Hudak, P. (1997). In ICFP ’97.
• Utility functions
• until :: Behaviour a ->
Event (Behaviour a) ->
Behaviour a
• andThen :: Event x ->
Behaviour a ->
Event (Behaviour a)
@noraesae
34. “Functional Reactive Animation.”
Elliott, C, Hudak, P. (1997). In ICFP ’97.
• Utility functions
• until :: Behaviour a ->
Event (Behaviour a) ->
Behaviour a
• andThen :: Event x ->
Behaviour a ->
Event (Behaviour a)
@noraesae
35. “Functional Reactive Animation.”
Elliott, C, Hudak, P. (1997). In ICFP ’97.
colorCycle =
red ‘until‘ click ‘andThen‘
blue ‘until‘ click ‘andThen‘
green ‘until‘ click ‘andThen‘
red
@noraesae
37. Looks good!
• It’s an intuitive and elegant way to describe GUI
@noraesae
38. Looks good!
• It’s an intuitive and elegant way to describe GUI
• It’s also a continuous and lazy way
• red ‘until‘ click
@noraesae
39. Surprisingly, I have a demo!
https://github.com/noraesae/purescript-behaviors
@noraesae
40. Further studies on FRP
• Real-time FRP
• Arrowized FRP
• Event-driven FRP
@noraesae
41. Real-time FRP
Wan, Z, Taha, W, Hudak, P. (2001). “Real-time frp.” In ICFP ’01.
@noraesae
42. Real-time FRP
Wan, Z, Taha, W, Hudak, P. (2001). “Real-time frp.” In ICFP ’01.
• They found interesting fact
@noraesae
43. Real-time FRP
Wan, Z, Taha, W, Hudak, P. (2001). “Real-time frp.” In ICFP ’01.
• They found interesting fact
@noraesae
44. Real-time FRP
Wan, Z, Taha, W, Hudak, P. (2001). “Real-time frp.” In ICFP ’01.
• They found interesting fact
• Event a = Behaviour (Maybe a)
@noraesae
45. Real-time FRP
Wan, Z, Taha, W, Hudak, P. (2001). “Real-time frp.” In ICFP ’01.
• They found interesting fact
• Event a = Behaviour (Maybe a)
• Now Behaviour and Event are the same!
@noraesae
46. Real-time FRP
Wan, Z, Taha, W, Hudak, P. (2001). “Real-time frp.” In ICFP ’01.
• They found interesting fact
• Event a = Behaviour (Maybe a)
• Now Behaviour and Event are the same!
• Rename Behaviour to Signal
@noraesae
47. Real-time FRP
Wan, Z, Taha, W, Hudak, P. (2001). “Real-time frp.” In ICFP ’01.
• Simplify the semantic
@noraesae
48. Real-time FRP
Wan, Z, Taha, W, Hudak, P. (2001). “Real-time frp.” In ICFP ’01.
• Simplify the semantic
• Focus on manageability
@noraesae
49. Arrowized FRP
Nilson, H, Courtney, A, Peterson, J. (2002).
“Functional reactive programming, continued.” In Haskell ’02.
@noraesae
50. Arrowized FRP
Nilson, H, Courtney, A, Peterson, J. (2002).
“Functional reactive programming, continued.” In Haskell ’02.
• Define Signal Function: SF a b
• a function accepting a signal, and returning a signal
• SF a b = Signal a -> Signal b
@noraesae
51. Arrowized FRP
Nilson, H, Courtney, A, Peterson, J. (2002).
“Functional reactive programming, continued.” In Haskell ’02.
• Expose signal functions, but not the signal itself
• render :: SF State View
@noraesae
52. Arrowized FRP
Nilson, H, Courtney, A, Peterson, J. (2002).
“Functional reactive programming, continued.” In Haskell ’02.
• Expose signal functions, but not the signal itself
• render :: SF State View
• Hide internals of Signal
@noraesae
53. Arrowized FRP
Nilson, H, Courtney, A, Peterson, J. (2002).
“Functional reactive programming, continued.” In Haskell ’02.
• Expose signal functions, but not the signal itself
• render :: SF State View
• Hide internals of Signal
• Focus on data manipulation itself
@noraesae
55. Event-driven FRP
Wan, Z, Taha, W, Hudak, P. (2002). “Event-driven frp.‘’ In PADL ’02.
• Assume Signal is discrete
@noraesae
56. Event-driven FRP
Wan, Z, Taha, W, Hudak, P. (2002). “Event-driven frp.‘’ In PADL ’02.
• Assume Signal is discrete
• Signal changes only when an event occurs
@noraesae
57. Event-driven FRP
Wan, Z, Taha, W, Hudak, P. (2002). “Event-driven frp.‘’ In PADL ’02.
• Assume Signal is discrete
• Signal changes only when an event occurs
• Prevent unnecessary behaviour updates
@noraesae
59. Elm
Czaplicki, E. (2012). “Elm: Concurrent FRP for Functional GUIs.”
• “A delightful language for reliable webapps”
@noraesae
60. Elm
Czaplicki, E. (2012). “Elm: Concurrent FRP for Functional GUIs.”
• “A delightful language for reliable webapps”
• Elm = Event-driven FRP + Arrowized FRP + Concurrent FRP
@noraesae
61. Elm
Czaplicki, E. (2012). “Elm: Concurrent FRP for Functional GUIs.”
• “A delightful language for reliable webapps”
• Elm = Event-driven FRP + Arrowized FRP + Concurrent FRP
• Discrete signal
@noraesae
62. Elm
Czaplicki, E. (2012). “Elm: Concurrent FRP for Functional GUIs.”
• “A delightful language for reliable webapps”
• Elm = Event-driven FRP + Arrowized FRP + Concurrent FRP
• Discrete signal
• Signal functions
@noraesae
63. Elm
Czaplicki, E. (2012). “Elm: Concurrent FRP for Functional GUIs.”
• “A delightful language for reliable webapps”
• Elm = Event-driven FRP + Arrowized FRP + Concurrent FRP
• Discrete signal
• Signal functions
• Global event dispatcher
@noraesae
64. Elm
Czaplicki, E. (2012). “Elm: Concurrent FRP for Functional GUIs.”
update : Event -> Color -> Color
update event color =
case event of
ColorCycle ->
case color of
Red -> Blue
Blue -> Green
Green -> Red
@noraesae
65. Elm
Czaplicki, E. (2012). “Elm: Concurrent FRP for Functional GUIs.”
view : Color -> Html Event
view color =
div [ onClick ColorCycle
, style [("background-color", color)]
]
[ ]
@noraesae
67. It doesn’t look so elegant!
• Classical FRP
red ‘until‘ click
@noraesae
68. It doesn’t look so elegant!
• Classical FRP
red ‘until‘ click
• Elm
update event color = case event of ...
view color = ...
@noraesae
69. It doesn’t look so elegant!
• Classical FRP
red ‘until‘ click
• Elm
update event color = case event of ...
view color = ...
• Elm is not classical FRP
@noraesae
71. Why not classical FRP?
• Web is discrete
• Classical FRP is based on continuity and laziness
@noraesae
72. Why not classical FRP?
• Web is discrete
• Classical FRP is based on continuity and laziness
• Hard to implement laziness on discrete env
• Timer, Polling, etc...
@noraesae
73. Why not classical FRP?
• Web is discrete
• Classical FRP is based on continuity and laziness
• Hard to implement laziness on discrete env
• Timer, Polling, etc...
• “I might argue that Elm was never about FRP”
Czaplicki, E. (2016). “A Farewell to FRP.” On Elm-lang Blog.
@noraesae
77. Why FRP matters: Maintainability
• Web app can be represented as function
• SF State View
@noraesae
78. Why FRP matters: Maintainability
• Web app can be represented as function
• SF State View
• State is SSOT(single source of truth)
@noraesae
79. Why FRP matters: Maintainability
• Web app can be represented as function
• SF State View
• State is SSOT(single source of truth)
• Bonus: Time-travel debugging is just a function call
@noraesae
80. Why FRP matters: Maintainability
• Web app can be represented as function
• SF State View
• State is SSOT(single source of truth)
• Bonus: Time-travel debugging is just a function call
• Signal a = Time -> a
@noraesae
81. Why FRP matters: Maintainability
• Web app can be represented as function
• SF State View
• State is SSOT(single source of truth)
• Bonus: Time-travel debugging is just a function call
• Signal a = Time -> a
• Signal View = Time -> View
@noraesae
84. Why FRP matters: Testability
• Signal isomorphism
• Signal a = SF RealWorld a
@noraesae
85. Why FRP matters: Testability
• Signal isomorphism
• Signal a = SF RealWorld a
• Replace RealWorld with TestWorld for tests
@noraesae
86. Why FRP matters: Testability
• Signal isomorphism
• Signal a = SF RealWorld a
• Replace RealWorld with TestWorld for tests
• Replace RealWorld with ServerWorld for free SSR(!)
@noraesae
88. Conclusion
• What FRP is
• Represent how a thing is being, in elegant and lazy way
@noraesae
89. Conclusion
• What FRP is
• Represent how a thing is being, in elegant and lazy way
• History of FRP
• FRP has firm backgrounds
@noraesae
90. Conclusion
• What FRP is
• Represent how a thing is being, in elegant and lazy way
• History of FRP
• FRP has firm backgrounds
• Why FRP matters
• Maintainability
• Testability
@noraesae
91. References I
Conal Elliott and Paul Hudak. “Functional Reactive Animation”. In:
ICFP ’97 (1997).
Evan Czaplicki. “Elm: Concurrent FRP for Functional GUIs”. In:
(2012).
Conal Elliott. “The Essence and Origins of Functional Reactive
Programming”. In: Lambda Jam. 2015.
Evan Czaplicki. A Farewell to FRP. 2016. url:
http://elm-lang.org/blog/farewell-to-frp.
@noraesae