on master help sign in
update reactive programming example
commitf8da13f8d807e9e8aae7a6f78eade4edb5d4bc82 authorHarendra Kumar <harendra.kumar@gmail.com> dateFri 1 Dec 2017, 14:33 (9 years ago) parentcfafcff
1 file changed+29−2
src/Streamly/Tutorial.hs+29−2
src/Streamly/Tutorial.hs+29−2
@@ -796,11 +796,30 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
796796-- @
797797--
798798-- You can see how this directly maps to the imperative style
799−-- <https://en.wikipedia.org/wiki/OpenMP OpenMP> model.
799+-- <https://en.wikipedia.org/wiki/OpenMP OpenMP> model, we use combinators
800+-- and operators instead of the ugly pragmas.
801+--
802+-- For more concurrent programming examples see,
803+-- "Streamly.Examples.ListDirRecursive", "Streamly.Examples.MergeSortedStreams"
804+-- and "Streamly.Examples.SearchEngineQuery".
800805
801806-- $reactive
802807--
803−-- Let us see a reactive programming example:
808+-- Reactive programming is nothing but concurrent streaming which is what
809+-- streamly is all about. With streamly we can generate streams of events,
810+-- merge streams that are generated concurrently and process events
811+-- concurrently. We can do all this without any knowledge about the specifics
812+-- of the implementation of concurrency. In the following example you will see
813+-- that the code is just regular Haskell code without much streamly APIs used
814+-- (active hyperlinks are the streamly APIs) and yet it is a reactive
815+-- application.
816+--
817+--
818+-- This application has two independent and concurrent sources of event
819+-- streams, @acidRain@ and @userAction@. @acidRain@ continuously generates
820+-- events that deteriorate the health of the game character. @userAction@ can
821+-- be "potion" or "quit". When the user types "potion" the health improves and
822+-- the game continues.
804823--
805824-- @
806825-- {-\# LANGUAGE FlexibleContexts #-}
@@ -844,6 +863,14 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
844863-- _ <- runStateT ('runStreamT' game) 60
845864-- return ()
846865-- @
866+--
867+-- You can also find the source of this example in
868+-- "Streamly.Examples.AcidRainGame". It has been adapted from Gabriel's
869+-- <https://hackage.haskell.org/package/pipes-concurrency-2.0.8/docs/Pipes-Concurrent-Tutorial.html pipes-concurrency>
870+-- package.
871+-- This is much simpler compared to the pipes version because of the builtin
872+-- concurrency in streamly. You can also find a SDL based reactive programming
873+-- example adapted from Yampa in "Streamly.Examples.CirclingSquare".
847874
848875-- $statemachine
849876-- State machine stuff