on master help sign in
update reactive programming example
f8da13fHarendra Kumar
src/Streamly/Tutorial.hs+29−2
@@ -796,11 +796,30 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
796-- @
796-- @
797--
797--
798-- You can see how this directly maps to the imperative style
798-- 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".
800
805
801-- $reactive
806-- $reactive
802--
807--
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.
804--
823--
805-- @
824-- @
806-- {-\# LANGUAGE FlexibleContexts #-}
825-- {-\# LANGUAGE FlexibleContexts #-}
@@ -844,6 +863,14 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
844-- _ <- runStateT ('runStreamT' game) 60
863-- _ <- runStateT ('runStreamT' game) 60
845-- return ()
864-- return ()
846-- @
865-- @
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".
847
874
848-- $statemachine
875-- $statemachine
849-- State machine stuff
876-- State machine stuff