Search code examples
haskellfrpreactive-banana

Is there an issue with an Event and a Behavior having the same initial value?


There's something I find unsatisfying with the below code. As I develop bGameState, I will add more events. Will the fact that playerInputE (and I imagine other Events) share the same initial value lead to problems? In other words, is my initial design sound enough to build off of?

Also, is there an alternative to using changes? I think I meet the criteria for correct use, but am not sure.

makeNetworkDescription :: AddHandler PlayerCommand ->
                           TChan GameState ->
                           IO EventNetwork
makeNetworkDescription addCommandEvent gsChannel = compile $ do
  eInput <- fromAddHandler addCommandEvent
  let playerInputE = accumE initialGS $ updateGS <$> eInput
      bGameState = stepper initialGS playerInputE
      eGameState <- changes bGameState
      reactimate $ (\n -> (atomically $ writeTChan gsChannel n)) <$> eGameState

Solution

  • I do not quite understand what you are trying to do, but you can use the accumB combinator which is defined as

    accumB x e = stepper x (accumE x e)
    

    to remove the definition of playerInputE.

    It appears to me that the changes function is used correctly.