<div dir="ltr">David, <div><br></div><div>At times like this I think am not even fit to code PHP for my day job.</div><div>I am going to have to read that very carefully when I wake up tomorrow.<br><div style><br></div><div style>

Thanks.</div><div style><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 10 March 2013 22:59, David McBride <span dir="ltr">&lt;<a href="mailto:toad3k@gmail.com" target="_blank">toad3k@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Your ipCamExec is IO (), but you are running it in the CGI a monad which is a type alias for CGIT IO a.  CGIT is an instance of MonadIO, so try liftIO ipCamExec.  liftIO has a type MonadIO m =&gt; IO a -&gt; m a, which means that if you replace m with CGIT IO, you would get IO a -&gt; CGIT IO a, which is exactly what you need.<br>


<br><div class="gmail_quote">On Sun, Mar 10, 2013 at 6:40 PM, emacstheviking <span dir="ltr">&lt;<a href="mailto:objitsu@gmail.com" target="_blank">objitsu@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div dir="ltr"><div>I am writing a stop-motion capture application using AngularJS and it&#39;s going OK. I was inspired to do so after installing &quot;IPCamera&quot; on my phone and Sony tablet. A typical IPCamera session lives on an internal address like this, this example will turn on the LED on the camera:</div>




<div><br></div><div>   <a href="http://192.168.0.5:8080/enabletorch" target="_blank">http://192.168.0.5:8080/enabletorch</a></div><div><br></div><div>Just because I can (or so I thought), I decided to write a tiny little FastCGI application in Haskell to act as a proxy using the PATH_INFO variable. This means that in to my Javascript code I have this code in a service file:</div>




<div><br></div><div><div><font face="courier new, monospace">angular.module(&#39;stomoServices&#39;, [&#39;ngResource&#39;]).</font></div><div><font face="courier new, monospace">    factory(</font></div><div>

<font face="courier new, monospace"><span style="white-space:pre-wrap">        </span>&#39;IPCamera&#39;,</font></div><div><font face="courier new, monospace"><span style="white-space:pre-wrap">        </span>function($resource, urlIPCameraAPI) {</font></div>




<div><font face="courier new, monospace"><span style="white-space:pre-wrap">        </span>    return $resource(</font></div><div><font face="courier new, monospace"><span style="white-space:pre-wrap">                </span>urlIPCameraAPI,<br>




</font></div><div><font face="courier new, monospace"><span style="white-space:pre-wrap">                </span>{}, {</font></div><div><font face="courier new, monospace"><span style="white-space:pre-wrap">                </span>    ledOn:    { method: &#39;GET&#39;, params: {featureReq: &#39;enabletorch&#39; }},</font></div>




<div><font face="courier new, monospace"><span style="white-space:pre-wrap">                </span>    ledOff:   { method: &#39;GET&#39;, params: {featureReq: &#39;disabletorch&#39; }},</font></div><div><font face="courier new, monospace"><span style="white-space:pre-wrap">                </span>    focusOn:  { method: &#39;GET&#39;, params: {featureReq: &#39;focus&#39; }},</font></div>




<div><font face="courier new, monospace"><span style="white-space:pre-wrap">                </span>    focusOff: { method: &#39;GET&#39;, params: {featureReq: &#39;nofocus&#39;}}</font></div><div><font face="courier new, monospace"><span style="white-space:pre-wrap">                </span>});</font></div>




<div><font face="courier new, monospace"><span style="white-space:pre-wrap">        </span>});</font></div><div><br></div><div>and I then issue commands like &quot;IPCamera.ledOn()&quot; etc. All very nice except that it doesn&#39;t work yet because I can&#39;t get the worlds seemingly simplest CGI application to compile yet! Here is the code that I have, it could be &quot;cleared up&quot; but this is what I have so far:</div>




<div><br></div></div><div><font face="courier new, monospace">main :: IO ()</font></div><div><font face="courier new, monospace">main = runFastCGI . handleErrors $ do</font></div><div><font face="courier new, monospace">  command &lt;- getVar &quot;PATH_INFO&quot;</font></div>




<div><font face="courier new, monospace">  case command of</font></div><div><font face="courier new, monospace">    Nothing  -&gt;</font></div><div><font face="courier new, monospace">      outputError 400 &quot;Missing IPCamera instruction (PATH_INFO)&quot; []</font></div>




<div><font face="courier new, monospace">    Just cmd -&gt;</font></div><div><font face="courier new, monospace">      ipCamExec (tail cmd) &gt;&gt; output &quot;OK&quot; -- tail drops the &quot;/&quot;</font></div><div>



<font face="courier new, monospace">      where</font></div>
<div><font face="courier new, monospace">        ipCamExec :: String -&gt; IO ()</font></div><div><font face="courier new, monospace">        ipCamExec url = do</font></div><div><font face="courier new, monospace">          simpleHTTP (getRequest url) -- don&#39;t want or need response.</font></div>




<div><font face="courier new, monospace">          return () -- to match the return type or so I thought.</font></div><div><br></div><div>and the error message I cannot seem to understand as it fills me with monadic fear which I can&#39;t get out of:</div>




<div><br></div><div><div><font face="courier new, monospace">ipcamera.hs:16:7:</font></div><div><font face="courier new, monospace">    Couldn&#39;t match expected type `CGIT IO a0&#39; with actual type `IO ()&#39;</font></div>




<div><font face="courier new, monospace">    In the return type of a call of `ipCamExec&#39;</font></div><div><font face="courier new, monospace">    In the first argument of `(&gt;&gt;)&#39;, namely `ipCamExec (tail cmd)&#39;</font></div>




<div><font face="courier new, monospace">    In the expression: ipCamExec (tail cmd) &gt;&gt; output &quot;OK&quot;</font></div></div><div><br></div><div>Please could some kind souls explain to me in simple terms just what is going on and why I am close to tears right now? I have read the definitions of CGIResult and CGI and they leave me cold. I am trying to understand monads more but at times like this I once again realise what a complete rank beginner I am!</div>




<div><br></div><div>Thanks.</div><div>Sean.</div><div><br></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>