daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 40 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Main where
  2.  
  3. import FRP.BearRiver    
  4. import Control.Monad.Trans.MSF.Reader
  5.  
  6. type Game = Ball
  7. type Ball = Int
  8.  
  9. type GameEnv = ReaderT GameSettings
  10.  
  11. data GameSettings
  12.     = GameSettings
  13.       { leftPlayerPos  :: Int
  14.       , rightPlayerPos :: Int
  15.       }
  16.  
  17. ballToRight :: Monad m => MSF (GameEnv m) () Ball
  18. ballToRight =
  19.     count >>> arrM addToLeftPlayerPos
  20.     where
  21.       addToLeftPlayerPos =
  22.           (n -> (n +) <$> asks leftPlayerPos)
  23.  
  24. hitRight :: Monad m => MSF (GameEnv m) Ball Bool
  25. hitRight = arrM (i -> (i >=) <$> asks rightPlayerPos)
  26.      
  27. module Main where
  28.  
  29. import FRP.BearRiver
  30. import Control.Monad
  31. import Control.Monad.Trans.MSF.Reader
  32. import Control.Monad.Trans.MSF.Writer
  33.  
  34. type Game = Ball
  35. type Ball = Int
  36.  
  37. type GameEnv m =
  38.     WriterT [String] (ReaderT GameSettings m)
  39.  
  40. data GameSettings
  41.     = GameSettings
  42.       { leftPlayerPos  :: Int
  43.       , rightPlayerPos :: Int
  44.       }
  45.  
  46. ballToRight :: Monad m => MSF (GameEnv m) () Ball
  47. ballToRight =
  48.     count >>> arrM addLeftPlayerPos >>> arrM checkHitR
  49.     where
  50.       addLeftPlayerPos =
  51.           (n -> (n +) <$> asks leftPlayerPos)
  52.       checkHitR n = do
  53.           rp <- asks rightPlayerPos
  54. when (rp > n) $ tell ["Ball is at " ++ (show n)]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top