On 2/17/06, Peter <[EMAIL PROTECTED]> wrote: > Hello, > > For the purpose of familiarizing myself with Haskell, and also because I > love Haskell :), > I am trying to re-make a script that I made in Python that sends a > request to a server and extracts the list of email addresses from a > Mailman web-page by using an XML Parser on the page's HTML that has been > converted to XHTML by "HTML Tidy". > > However, I cannot seem to figure out a way to get the state of a Monad; > Specifically I cannot get the value of an "IO String" Monad. > > I have read some tutorials on Monads but I guess I must have missed > something. > > I have read that the >>= operator is the only way to extract the state > of an action as a string, and pipe it to a function. So far so good. > But, That does not seem to work, because as I understand the >>= > operator, it expects the function on the right hand side to return an IO > Monad, which completely defeats the purpose here. > > So, How am I supposed to get the value of an IO Monad, such as "IO > String", without returning an IO Monad? > > If this is of any help, here is the function I am stuck on: > recv_headers' :: Socket.Socket -> String -> IO [[String]] > recv_headers' sock bulk > | received == "" = error "Connection died unexpectedly." > | received == "\n" > && endswith bulk "\r\n\r" = return [["foo", "bar"]] > | otherwise = recv_headers' sock (bulk ++ received) > where received = (Socket.recv sock 1)
Try: recv_headers' sock bulk = do received <- Socket.recv sock 1 case received of "" -> error ... "\n" | endswith bulk "\r\n\r" -> ... _ -> recv_headers' sock (bulk ++ received) -- Friendly, Lemmih _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe