I am trying to read a line ending in \r\n from a Handle. This is an HTTP header.Im fairly new to functional programming, so I tend to use a lot of case expressions and stuff. This makes the code very long and ugly.handleRequest :: HostName -> Handle -> IO ()handleRequest host handle = do    requestLine <- readHeaderLine    putStrLn $ requestLine ++ \n-------------------    -- FIXME: This code is bad, and its author should feel bad.    where        readHeaderLine = do            readHeaderLine'             where                readHeaderLine' s = do                    chr <- hGetChar handle                    case chr of                        '\r' -> do                            nextChr <- hGetChar handle                            case nextChr of                                '\n' -> return s                                _    -> readHeaderLine' $ s ++ [chr, nextChr]                        _    -> readHeaderLine' $ s ++ [chr]How can I reduce the amount of case expressions in this code? I thought of using Parsec, but that seemed overkill to me for something this trivial, and I dont know how well it works with Handles.
How to shorten this terrible HTTP header parser?
haskell;parsing;functional programming;http
You can use hGetContents to read lazily from a handle, and the split package (which will hopefully be bundled into the next Haskell Platform release) provides some nice ways of dealing with lists.import Data.List.Split (splitOn)import System.IO (hGetContents)... do  ...  contentLines <- splitOn \r\n <$> hGetContents handlecontentLines will contain a lazy list of the entire contents of that handle, split into chunks that were originally separated by \r\n.Another approach is to use something like the conduit package. See, for example, Data.Conduit.Binary.lines. Keep an eye on conduit & friends; I get the feeling that within the next year or so the Haskell community will start to agree on the best implementation of this sort of abstraction, and then some good tutorials will inevitably follow.