I'm new to Haskel, I'm trying to run a simple example using http-conduit, the example is the one provided in their documentation.
However, when running the program I always get:
• Couldn't match expected type ‘Request’ with actual type ‘[Char]’
• In the first argument of ‘httpLBS’, namely
‘"http://httpbin.org/get"’
In a stmt of a 'do' block:
response <- httpLBS "http://httpbin.org/get"
In the expression:
do response <- httpLBS "http://httpbin.org/get"
putStrLn
$ "The status code was: " ++ show (getResponseStatusCode response)
print $ getResponseHeader "Content-Type" response
L8.putStrLn $ getResponseBody response
|
12 | response <- httpLBS "http://httpbin.org/get"
| ^^^^^^^^^^^^^^^^^^^^^^^^
I've tried to create a project both with cabal and stack, add http-conduit and aeson as dependencies, but still getting the error.
Shouldn't the url be implicitly converted to a Request?
I've tried to import Request and try to create a Request from the url, but it complains:
import Network.HTTP.Client.Request
<no location info>: error:
Could not load module ‘Network.HTTP.Client.Request’
it is a hidden module in the package ‘http-client-0.6.4.1’
You need to enable the
OverloadedStringsextension [schoolofhaskell]. You can add theLANGUAGEpragma to the top of the file, so:This extension will implicitly add
fromString :: IsString a => String -> ato each string literal (not to be confused with an expression with typeString). It makes it more convenient to work with string-like data such as for exampleText.Beware however that the conversion is done at runtime, so if not all
Strings map to a (valid)Requestobject, then you will only see this when theRequestis evaluated.In Haskell, there are no implicit conversions, you always convert data through functions. The
OverloadedStringssimply adds a implicit function call to the literals, and thus this means that a string literal now can take as type any type that is a member of theIsStringtype class.