Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Check out <a href="http://hackage.haskell.org/packages/archive/pipes/2.3.0/doc/html/Control-Proxy-Tutorial.html" rel="nofollow">Control.Proxy.Tutorial</a>. If you can write a Proxy wrapper around your type, then you can easily swap out the test interface and a real interface like this:</p> <pre><code>client &lt;-&lt; simulatedServer client &lt;-&lt; realServer </code></pre> <p>Edit: To answer your question in the comment, you use a <code>Server</code> to write a wrapper around your <code>simpleHTTP</code> requests:</p> <pre><code>realServer :: HStream ty =&gt; Request ty -&gt; Server (Request ty) (Result (Response ty)) IO r realServer = foreverK $ \req -&gt; do result &lt;- lift $ simpleHTTP req respond result </code></pre> <p>The simulated server would look like:</p> <pre><code>simulatedServer :: (Monad m, HStream ty) =&gt; Request ty -&gt; Server (Request ty) (Result (Response ty)) m r simulatedServer = foreverK $ \req -&gt; do result &lt;- lift $ simulatedRequest req respond result </code></pre> <p>And your client would look like:</p> <pre><code>client :: (Monad m, HStream ty) =&gt; () -&gt; Client (Request ty) (Result (Response ty)) m r client () = forever $ do let req = &lt;something&gt; result &lt;- request req lift $ doSomethingWith result </code></pre> <p>Then you can test the real server and fake server using:</p> <pre><code>-- Test the real server main = runSession $ client &lt;-&lt; realServer -- Test the fake server main = runSession $ client &lt;-&lt; simulatedServer </code></pre> <p>The <code>client</code> and <code>simulatedServer</code> are polymorphic in the base monad only because I don't know what base monad they would use for your testing. The only requirement is that the two things you compose have the same base monad or that at least one is polymorphic in the base monad.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload