[Haskell-cafe] Why no instance of Happstack.Data.Default.Default for Data.ByteString.Lazy

Jeremy Shaw jeremy at n-heptane.com
Fri Mar 19 17:30:33 EDT 2010

sloppiness probably. If you submit a patch that adds an instance I will
apply it.

That said, I am not sure it is going to solve your particular problem.

simpleHTTP requires something that is an instance of ToMessage. ToMessage is
a class that turns values into a Response. It happens that anything that is
an instance of  Xml is also an instance of ToMessage. And to be an instance
of Xml it needs to be an instance of Default. So that is where the Default
requirement is coming from. Since there is no explicit ByteString instance
for ToMessage, it is trying to use the general Xml instance instead. I often
wish the Xml instance for ToMessage did not exist. I am not sure anyone uses
it, and I might remove it someday..

Ultimately what you need to do is get the value returned by Network.HTTP
converted into a value of type Response. If you pass that to simpleHTTP,
then everything should be fine, since Response is an instance of ToMessage.

Now, if you just want to directly echo the Response from Network.HTTP to the
output socket with no munging around, then the current Response type might
not be so friendly, because it expects that you are going to set the http
response code, the headers, and the body separately. So, you would have to
parse the bytestring into a Response just to turn it back into the the same
bytestring. But if your proxying requires munging some headers anyway, then
that is not a big deal. We could consider adding another constructor to the
Response type that just takes a lazy bytestring that is supposed to
represent a fully-formed response..

- jeremy

On Fri, Mar 19, 2010 at 12:18 PM, Mads Lindstrøm
<mads_lindstroem at yahoo.dk>wrote:

> Hi
> Why is that Happstack has:
> instance Happstack.Data.Default.Default Data.ByteString
> But not one for:
> instance Happstack.Data.Default.Default Data.ByteString.Lazy
> I am trying to make a HTTP proxy using Happstack and the client part
> with the Network.HTTP (see Hackage). Network.HTTP.simpleHttp returns a
> lazy Bytestring when given a lazy Bytestring (which makes sense).
> Happstack on the other hand contains a lazy ByteString in its request
> type:
> data Request = Request { ... rqHeaders :: Headers, ... rqBody ::
> RqBody ... }
> newtype RqBody = Body Data.ByteString.Lazy.Internal.ByteString
> which Happstack.Server.SimpleHttp.simpleHTTP feeds into my application.
> However Happstack.Server.SimpleHttp.simpleHTTP expects something
> returned which is an instance of Happstack.Data.Default.Default which
> lazy ByteString is not.
> Confused? So am I. Who thought String handling could be so complex.
> Greetings,
> Mads Lindstrøm
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100319/d163442e/attachment.html

More information about the Haskell-Cafe mailing list