Hi,<br><br>Could someone please care to explain what I am doing wrong below in cgiMain2 and how can I fix it?<br><br><br>./Main.hs:25:15:<br> No instance for (MonadCGI IO)<br> arising from a use of `output' at ./Main.hs:25:15-20<br>
Possible fix: add an instance declaration for (MonadCGI IO)<br> In the first argument of `($)', namely `output'<br> In the expression: output $ renderHtml $ page "import" fileForm<br> In the definition of `upload':<br>
upload = output $ renderHtml $ page "import" fileForm<br><br>./Main.hs:57:29:<br> Couldn't match expected type `CGI CGIResult'<br> against inferred type `IO CGIResult'<br> In the first argument of `handleErrors', namely `cgiMain2'<br>
In the second argument of `($)', namely `handleErrors cgiMain2'<br> In the expression: runCGI $ handleErrors cgiMain2<br><br><br><span style="font-family: courier new,monospace;">import IO</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">import Network.CGI</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import Text.XHtml</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import qualified Data.ByteString.Lazy as BS</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import Control.Monad (liftM)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">import Data.Maybe (fromJust)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import Interact</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">fileForm = form ! [method "post", enctype "multipart/form-data"] <<</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> [afile "file", submit "" "Upload"]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">page t b = header << thetitle << t +++ body << b</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">cgiMain1 = do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> getInputFPS "file" ↠ λms → maybe upload contents ms ↠ return</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> upload = output $ renderHtml $ page "import" fileForm</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> contents = outputFPS</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">cgiMain2 = do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> getInputFPS "file" ↠ λms → maybe upload contents ms ↠ return</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> upload = output $ renderHtml $ page "import" fileForm</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> contents = λs → do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (i,o,h,_) ← runUnzip </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> BS.hPutStr i s</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> c ← BS.hGetContents o</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> outputFPS c</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">{- </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (i,o,h,_) ← runUnzip</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> BS.hPutStr i s</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> BS.hGetContents o ↠ outputFPS</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">-}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">{-</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">liftM :: (Monad m) => (a1 -> r) -> m a1 -> m r</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">liftIO :: (MonadIO m) => IO a -> m a</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">saveFile n =</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> do cont <- liftM fromJust $ getInputFPS "file"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> let f = uploadDir ++ "/" ++ basename n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> liftIO $ BS.writeFile f cont</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return $ paragraph << ("Saved as " +++ anchor ! [href f] << f +++ ".")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">-} </span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">runUnzip = runInteractiveCommand "unzip -l /dev/stdin"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">main = runCGI $ handleErrors cgiMain2</span><br><br><span style="font-family: times new roman,serif;">Best Regards,<br>
Cetin Sert<br><br>P/s: what are lifts o_O?<br></span>