[Haskell-cafe] Lazy IO.

Felipe Lessa felipe.lessa at gmail.com
Sat Jun 14 13:16:56 EDT 2008

On Sat, Jun 14, 2008 at 1:50 PM, Sebastiaan Visser <sfvisser at cs.uu.nl> wrote:
> Doesn't this imply that the parseHttpHeader must work on ByteStrings instead
> of regular Strings?

I made the change because it's easier and faster to go from ByteString
to String than the converse.

> Maybe this works for HTTP headers, but sometimes
> ByteStrings are not appropriate. Especially when you are not using the
> regular `System.IO.hGetContents' but the `System.IO.UTF8.hGetContents'.

You may use the package encoding instead, take a look at [1]. It will
decode a lazy ByteString into a String. In your HTTP parsing example,
you could break the ByteString on "\r\n\r\n" and then decodeLazy only
the first part, while returning the second without modifying it.

[1] http://hackage.haskell.org/packages/archive/encoding/0.4.1/doc/html/Data-Encoding.html#v%3AdecodeLazy

-- Felipe.

More information about the Haskell-Cafe mailing list