Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import FRP.Elerea.Param
- import Control.Monad
- {-
- This program is an example of functional reactive programming. There are two people a father and a son
- they each have an amount of money and initially each of their values is 0 and 10. However , The father always has £10
- more than his son. An updater signal keep track and tells when an amount of money has been added or removed from the
- amounts of the father and the son. Here is the code written with the FRP library Elerea.
- -}
- main :: IO ()
- main = do
- smp <- start $ do
- b <- stateful 0 (+)
- d <- transfer 10 (\d b x -> b + 10) b
- g <- input
- gs <- effectful1 (inputCheck) g
- bs <- effectful2 (\b d -> (shout b d)) b d
- return g
- res <- forM [1,0,1,(-1),1,1,0, 6] smp
- return ()
- shout :: Int -> Int -> IO ()
- shout b d = putStrLn $ "The Boy has £" ++ show b ++ "\n" ++ "The Dad has £" ++ show d ++ "\n"
- inputCheck :: Int -> IO ()
- inputCheck x
- | x == 6 = return ()
- | x > 0 = putStrLn $ "--Increased by £" ++ show x
- | x < 0 = putStrLn $ "* Decreased by £" ++ show (abs x)
- | x == 0 = putStrLn "..No Change"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement