[Haskell-cafe] (Newbie Question) How to get the value of an "IO String" Monad?

Udo Stenzel u.stenzel at web.de
Fri Feb 17 10:23:12 EST 2006

Peter wrote:
> So, How am I supposed to get the value of an IO Monad, such as "IO
> String", without returning an IO Monad?

You read correctly, this is impossible.  You already got some valid
answers, and here's another variant that preserves most of the nice
guarded expressions:

recv_headers' :: Socket.Socket -> String -> IO [[String]]
recv_headers' sock bulk = Socket.recv sock 1 >>= dispatch
  where dispatch ""            = error "Connection died unexpectedly."
        dispatch "\n" | endswith bulk "\r\n\r" = return [["foo", "bar"]]
        dispatch _             = recv_headers' sock (bulk ++ received)

"Gadgets are not necessarily an improvement, vide the succession:
Blackboard -> Overhead Projector -> PowerPoint"
	-- E. W. Dijkstra
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20060217/ce3eba68/attachment.bin

More information about the Haskell-Cafe mailing list