[Haskell-beginners] Trouble in (Fast)CGI land: matching `CGIT IO a0' with actual type `IO ()'
David McBride
toad3k at gmail.com
Sun Mar 10 23:59:56 CET 2013
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 at 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:
>
> http://192.168.0.5:8080/enabletorch
>
> 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 $ do
> command <- getVar "PATH_INFO"
> case command of
> Nothing ->
> outputError 400 "Missing IPCamera instruction (PATH_INFO)" []
> Just cmd ->
> ipCamExec (tail cmd) >> output "OK" -- tail drops the "/"
> where
> ipCamExec :: String -> IO ()
> ipCamExec url = do
> simpleHTTP (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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130310/a193df67/attachment-0001.htm>
More information about the Beginners
mailing list