<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"><<a href="mailto:toad3k@gmail.com" target="_blank">toad3k@gmail.com</a>></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 => IO a -> m a, which means that if you replace m with CGIT IO, you would get IO a -> 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"><<a href="mailto:objitsu@gmail.com" target="_blank">objitsu@gmail.com</a>></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's going OK. I was inspired to do so after installing "IPCamera" 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('stomoServices', ['ngResource']).</font></div><div><font face="courier new, monospace"> factory(</font></div><div>
<font face="courier new, monospace"><span style="white-space:pre-wrap">        </span>'IPCamera',</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: 'GET', params: {featureReq: 'enabletorch' }},</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap">                </span> ledOff: { method: 'GET', params: {featureReq: 'disabletorch' }},</font></div><div><font face="courier new, monospace"><span style="white-space:pre-wrap">                </span> focusOn: { method: 'GET', params: {featureReq: 'focus' }},</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap">                </span> focusOff: { method: 'GET', params: {featureReq: 'nofocus'}}</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 "IPCamera.ledOn()" etc. All very nice except that it doesn't work yet because I can't get the worlds seemingly simplest CGI application to compile yet! Here is the code that I have, it could be "cleared up" 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 <- getVar "PATH_INFO"</font></div>
<div><font face="courier new, monospace"> case command of</font></div><div><font face="courier new, monospace"> Nothing -></font></div><div><font face="courier new, monospace"> outputError 400 "Missing IPCamera instruction (PATH_INFO)" []</font></div>
<div><font face="courier new, monospace"> Just cmd -></font></div><div><font face="courier new, monospace"> ipCamExec (tail cmd) >> output "OK" -- tail drops the "/"</font></div><div>
<font face="courier new, monospace"> where</font></div>
<div><font face="courier new, monospace"> ipCamExec :: String -> IO ()</font></div><div><font face="courier new, monospace"> ipCamExec url = do</font></div><div><font face="courier new, monospace"> simpleHTTP (getRequest url) -- don'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'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't match expected type `CGIT IO a0' with actual type `IO ()'</font></div>
<div><font face="courier new, monospace"> In the return type of a call of `ipCamExec'</font></div><div><font face="courier new, monospace"> In the first argument of `(>>)', namely `ipCamExec (tail cmd)'</font></div>
<div><font face="courier new, monospace"> In the expression: ipCamExec (tail cmd) >> output "OK"</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>