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.
On Sun, Mar 10, 2013 at 6:40 PM, emacstheviking <objitsu@gmail.com> wrote: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: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:angular.module('stomoServices', ['ngResource']).factory('IPCamera',function($resource, urlIPCameraAPI) {return $resource(urlIPCameraAPI,
{}, {ledOn: { method: 'GET', params: {featureReq: 'enabletorch' }},ledOff: { method: 'GET', params: {featureReq: 'disabletorch' }},focusOn: { method: 'GET', params: {featureReq: 'focus' }},focusOff: { method: 'GET', params: {featureReq: 'nofocus'}}});});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:main :: IO ()main = runFastCGI . handleErrors $ docommand <- getVar "PATH_INFO"case command ofNothing ->outputError 400 "Missing IPCamera instruction (PATH_INFO)" []Just cmd ->ipCamExec (tail cmd) >> output "OK" -- tail drops the "/"whereipCamExec :: String -> IO ()ipCamExec url = dosimpleHTTP (getRequest url) -- don't want or need response.return () -- to match the return type or so I thought.and the error message I cannot seem to understand as it fills me with monadic fear which I can't get out of:ipcamera.hs:16:7:Couldn't match expected type `CGIT IO a0' with actual type `IO ()'In the return type of a call of `ipCamExec'In the first argument of `(>>)', namely `ipCamExec (tail cmd)'In the expression: ipCamExec (tail cmd) >> output "OK"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!Thanks.Sean.
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners