Reactive Banana 1.0.0 - Why is this old code breaking?

Here is the code that was used to work (reliably truncated)

makeNetworkDescription :: forall t . Frameworks t => Parameters -> Moment t () makeNetworkDescription params = do eInput <- fromAddHandler (input params) eTick <- fromAddHandler (tick params) .. let bResourceMap :: Behavior t ResourceMap bResourceMap = accumB initRmap $ adjustMarket <$> bMarketRolls <@ eTick 

But now the types have changed.
we have:
makeNetworkDescription :: Parameters -> MomentIO () as well as accumB :: MonadMoment m => a -> Event (a -> a) -> m (Behavior a)

Let's say I change the definition of bResourceMap to

 bResourceMap :: Behavior ResourceMap bResourceMap = accumB initRmap $ adjustMarket <$> bMarketRolls <@ eTick 

deviated slightly from the definition of accumB , but let's see what happens.

ghc gives an error

 Couldn't match type 'Behavior ResourceMap' with 'ResourceMap' Expected type: Behavior ResourceMap Actual type: Behavior (Behavior ResourceMap) 

That's right, due to the accumB type accumB behavior should be in the context of MonadMoment . Looking at MonadMoment , I find two instances

 instance MonadMoment Moment where liftMoment = id instance MonadMoment MomentIO where liftMoment = MIO . unM 

So, why the actual type allowed Behavior (Behavior ResourceMap) , the external type should be MonadMoment , which does not match.

I would like to know how to solve this problem, this happens with all my Behavior definitions.

+6
source share
1 answer

Setting up your code for the new accumB type should only be done using monadic binding, not the let bResourceMap to define bResourceMap :

 bResourceMap <- accumB initRmap (adjustMarket <$> bMarketRolls <@ eTick) 

The error of the type you are quoting seems unrelated. I assume that initRmap was accidentally changed from ResourceMap to Behavior ResourceMap , resulting in a type mismatch.

+5
source

All Articles