[Haskell-beginners] monads do not fit together?

Kees Bleijenberg k.bleijenberg at lijbrandt.nl
Mon Oct 14 11:51:30 UTC 2013


The program belows reads the get fields 'un' and 'ip'. If these get fields
both exist, the program modifies a firewall script. 

The problem is in cgiMain. 

The error at the problem line is:  parse error on input `<-' 

If I move the line above the 'if' I get: Couldn't match expected type `CGIT
IO t0' with actual type `IO [String]'.   

 

How can I extract values from the IO [String] monad in cgiMain? I don't want
to alter the type of  runRefreshFirewall.

 

Kees

 

module Main(

   main

)

 

where 

import Network.CGI

import Text.XHtml

import Text.XHtml.Transitional

import Data.Maybe

 

runRefreshFirewall :: String -> String -> IO [String]

runRefreshFirewall un ip =  do

                                               return ["test" ]

 

inputCgiOkPage :: String -> String -> [String] -> Html 

inputCgiOkPage un ip msgs = body << h1 << ("IP: " ++ (show ip)) 

                               

undefinedFieldsPage :: Html 

undefinedFieldsPage = body << h1 << "Undefined Fields" 

 

cgiMain :: CGI CGIResult   

cgiMain = do

            maybeUn <- getInput "un"

            maybeIp <- getInput "ip"

            if ((isJust maybeUn) && (isJust maybeIp)) then

               msgs <-runRefreshFirewall (fromJust maybeUn) (fromJust
maybeIp)  -- problem

               output $ renderHtml $ inputCgiOkPage (fromJust maybeUn)
(fromJust maybeIp) msgs

            else

                output $ renderHtml undefinedFieldsPage

main :: IO ()

main = runCGI $ handleErrors cgiMain

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131014/3598883f/attachment.html>


More information about the Beginners mailing list