HeinrichApfelmus/reactive-banana — Issue #23: Divergence between PushIO and Model implementations
Author: gcross
Created: 2012-01-01 06:22:43+00:00
State: open

The following code demonstrates a difference between the PushIO and Model implementations:

```Haskell
{-# LANGUAGE ScopedTypeVariables #-}

import Data.Maybe
import qualified Reactive.Banana.Implementation as PushIO
import Reactive.Banana.Incremental
import Reactive.Banana.Model as Model

data Incoming = IncomingA | IncomingB deriving (Show)

data Outgoing = Outgoing deriving (Show)

filterJust :: FRP f => Event f (Maybe a) -> Event f a
filterJust = fmap fromJust . filterE isJust

f :: forall f. FRP f => Event f Incoming -> Event f Outgoing
f incoming = outgoing
where
incomingA :: Event f ()
incomingA =
filterJust
$
(\x -> case x of
IncomingA -> Just ()
_ -> Nothing
)
<$>
incoming

incomingB :: Event f ()
incomingB =
filterJust
$
(\x -> case x of
IncomingB -> Just ()
_ -> Nothing
)
<$>
incoming

discrete = accumD () (id <$ incomingB)

outgoing = Outgoing <$ (changes discrete)

main1 = return (Model.interpret f [IncomingA,IncomingB]) >>= print
main2 = (PushIO.interpret f [IncomingA,IncomingB]) >>= print

-- Output: Prelude.last: empty list
-- main = main1

-- Output: [[],[Outgoing]]
-- main = main2
```

When the Model implementation is used, the program crashes. When the PushIO implementation is used, it runs just fine and produces the correct answer.