{- This program works. It returns a nice 500 Server Error result if there are any SQL errors (e.g., an invalid DSN). But I want proc to return a CGIResult, not a String. So I can use output, or redirect, or whatever else from inside proc. I tried changing proc to: proc :: DB.Connection -> CGI.CGI CGI.CGIResult Then I tried putting 'lift' in all sorts of places in cgiMain. But I can't figure out how to make it work. Any hope for me? -} import qualified Control.Exception as Exception (bracket) import qualified Database.HDBC as DB import qualified Database.HDBC.ODBC as ODBC import qualified List import Control.Monad.Trans (lift) import qualified Network.NewCGI as CGI import Text.XHtml import qualified System import qualified System.IO.Error as IOE cgiMain :: CGI.CGI CGI.CGIResult cgiMain = do res <- lift $ DB.handleSqlError $ Exception.bracket (ODBC.connectODBC "DSN=lbugs") DB.disconnect proc CGI.output res proc :: DB.Connection -> IO String proc dbh = do args <- System.getArgs return (join " " ["Hello World!", (join ", " args)]) main :: IO () main = CGI.runCGI (CGI.handleErrors cgiMain) join :: [a] -> [[a]] -> [a] join sep = concat . List.intersperse sep