<div dir="ltr"><p> I think I'm on the right track. I have commented out all test harness code and have changed the signature for <code>bufferPopulated</code></p>

<pre style="" class=""><code><span class="">bufferPopulated </span><span class="">::</span><span class=""> UAC </span><span class="">-></span><span class=""> IO Bool
bufferPopulated ev </span><span class="">=</span><span class=""> </span><span class="">do</span><span class="">
  </span><span class="">let</span><span class=""> eInput </span><span class="">=</span><span class=""> ev </span><span class=""><$</span><span class=""> never
      eValidated </span><span class="">=</span><span class=""> toVAC </span><span class=""><$></span><span class=""> eInput
  bBufferMap </span><span class=""><-</span><span class=""> liftMoment </span><span class="">((</span><span class="">buffer eValidated eClear</span><span class="">)</span><span class=""> </span><span class="">::</span><span class=""> Moment    </span><span class="">(</span><span class="">Behavior BufferMap</span><span class="">))</span><span class=""> 
  </span><span class="">let</span><span class=""> r2 </span><span class="">=</span><span class=""> </span><span class="">[(</span><span class="">Just </span><span class="">$</span><span class=""> BufferMap </span><span class="">$</span><span class=""> M.insert </span><span class="">(</span><span class="">AID </span><span class="">(</span><span class="">Data.Text.pack </span><span class="">"100"</span><span class="">))</span><span class=""> </span><span class="">(</span><span class="">toVAC ev</span><span class="">)</span><span class=""> </span><span class="">(</span><span class="">M.empty </span><span class="">::</span><span class=""> M.Map AID VAC</span><span class="">))]</span><span class="">
  r1 </span><span class=""><-</span><span class=""> </span><span class="">(</span><span class="">interpret </span><span class="">(</span><span class="">eBuffer bBufferMap</span><span class="">)</span><span class=""> </span><span class="">[])</span><span class=""> </span><span class="">::</span><span class=""> IO </span><span class="">[</span><span class="">Maybe BufferMap</span><span class="">])</span><span class="">          
  return </span><span class="">$</span><span class=""> r1 </span><span class="">==</span><span class=""> r2</span></code></pre><div class="gmail_extra"><p>I believe this should work, but here's the error</p>

<pre style="" class=""><code><span class="">tests</span><span class="">/</span><span class="">Spec.hs</span><span class="">:</span><span class="">35</span><span class="">:</span><span class="">17</span><span class="">:</span><span class="">
    No </span><span class="">instance</span><span class=""> for </span><span class="">(</span><span class="">MonadMoment IO</span><span class="">)</span><span class=""> arising from a use </span><span class="">of</span><span class=""> </span><span class="">‘</span><span class="">liftMoment</span><span class="">’</span><span class="">
    In a stmt </span><span class="">of</span><span class=""> a </span><span class="">'d</span><span class="">o' block</span><span class="">:</span><span class="">
      bBufferMap </span><span class=""><-</span><span class=""> liftMoment
                      </span><span class="">((</span><span class="">buffer eValidated eClear</span><span class="">)</span><span class=""> </span><span class="">::</span><span class=""> Moment </span><span class="">(</span><span class="">Behavior   BufferMap</span><span class="">))<br><br></span></code></pre><p>Let's take a look at <code>MonadMoment</code> from <code>Reactive.Banana.Combinators</code></p>

<code><span class="">class</span><span class=""> Monad m </span><span class="">=></span><span class=""> MonadMoment m </span><span class="">where</span><span class=""><br> An </span><span class="">instance</span><span class=""> </span><span class="">of</span><span class=""> the MonadMoment </span><span class="">class</span><span class=""> denotes a computation that happens at one particular moment </span><span class="">in</span><span class=""> time</span><span class="">.<br></span><span class=""> Unlike the Moment monad</span><span class="">,</span><span class=""> it need not be pure anymore</span><span class="">.</span><span class=""><br> Methods<br>   liftMoment </span><span class="">::</span><span class=""> Moment a </span><span class="">-></span><span class=""> m a<br> Instances<br> MonadMoment MomentIO<br> MonadMoment Moment<br><br></span></code><code>m</code> can be any <code>Monad</code>, <code>IO</code> is a <code>Monad</code>. so <code>liftMoment</code> should lift the <code>Moment Behavior (BufferMap)</code> to <code>IO Behavior (BufferMap)</code> , why doesn't it. What's wrong with my reasoning?<br><pre style="" class=""><br></pre><div class="gmail_quote">On Fri, Nov 13, 2015 at 7:16 AM, Michael Litchard <span dir="ltr"><<a href="mailto:michael@schmong.org" target="_blank">michael@schmong.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><pre>Below is some test code I am writing for my game, the link to the entire codebase, the error message and some discussion

main :: IO ()
main = defaultMain
  [ testGroup "EventNetwork Input"
    [testBuffer "bBuffer" Populated]
  ]

testBuffer :: String -> BufferState -> Test
testBuffer name Populated =
  testCase name $ assert $ bufferPopulated (UAC (PlayerCommand (Move (ToPlanetName Mongo)) (AID (Data.Text.pack "100"))))
testBuffer name Empty =
  testCase name $ assert $ bufferEmptied (UAC (PlayerCommand (Move (ToPlanetName Mongo)) (AID (Data.Text.pack "100"))))

bufferPopulated :: UAC -> MomentIO Bool
bufferPopulated ev = do
  let eInput = ev <$ never
      eValidated = toVAC <$> eInput
  bBufferMap <- (buffer eValidated eClear) :: MomentIO (Behavior BufferMap)
  let r2 = [(Just $ BufferMap $ M.insert (AID (Data.Text.pack "100")) (toVAC ev) (M.empty :: M.Map AID VAC))]
  r1 <- liftIO $ ((interpret (eBuffer bBufferMap) []) :: IO [Maybe BufferMap])
  return $ r1 == r2

bufferEmptied :: UAC -> MomentIO Bool
bufferEmptied ev = undefined

eBuffer :: Behavior BufferMap -> Event a -> Event BufferMap
eBuffer bBufferMap nvr =
  bBufferMap <@ (() <$ nvr)

eClear = Clear <$ (() <$ never)


When I run stack build I get

tests/Spec.hs:26:19:
    No instance for (Test.HUnit.Base.Assertable (MomentIO Bool))
      arising from a use of ‘assert’
In the expression: assert
In the second argument of ‘($)’, namely
  ‘assert
   $ bufferPopulated
       (UAC
          (PlayerCommand (Move (ToPlanetName Mongo)) (AID (pack "100"))))’
In the expression:
  testCase name
  $ assert
    $ bufferPopulated
        (UAC
           (PlayerCommand (Move (ToPlanetName Mongo)) (AID (pack "100"))))

The problem lies with buffer. It relies on accumB which requires the MomentIO monad. I considered writing an
instance for Assertable, but I think that's a red-herring and the answer lies elsewhere. I need to reconcile the 
fact that assert wants an IO Bool, but accumB wants a MomentIO. Maybe I do need to write an instance for Assertable.

Here's the link to the project:
<a href="https://github.com/mlitchard/emporos/tree/banana-1.0.0/src" target="_blank">https://github.com/mlitchard/emporos/tree/banana-1.0.0/src</a></pre></div>
</blockquote></div><br></div></div>