0
votes
addRequestHeader (H.hContentType, "application/json")

this is a example of the usage of Network.HTTP.Simple package, i have seen a couple of times. how does that work to pass a String to that function as its signature is:

addRequestHeader :: Network.HTTP.Types.Header.HeaderName
 -> Data.ByteString.Internal.ByteString -> Request -> Request

when i try this, i get the error couldn't match expected type ‘C8.ByteString’ with actual type ‘[Char]’, so i have to use Data.ByteString.Char8.pack function to make this work. why don't the others have to do that? is there a auto-convertion or whats going on here?

1
Haskell has no autoconversions in general. All conversions are done explicitly. - Willem Van Onsem
@carcigenicate no there is only this one with ByteString hackage.haskell.org/package/http-conduit-2.3.2/docs/… - stefa ng
You may perhaps use the {-# LANGUAGE OverloadedStrings #-} language extension. - Redu

1 Answers

5
votes

There is an "autoconversion" for string literals, i.e. for those strings given explicitly between quotes "...", like your "application/json".

To turn it on you need the OverloadedStrings extension.

Other string expressions (e.g., variables of type String, return values of functions, ...) will not be automatically converted.