我无法弄清楚为什么以下代码有效:
main = do
response <- httpLBS "http://httpbin.org/get"
let statusCode = show $ getResponseStatusCode response
putStrLn statusCode
但这不是:
getStatusCode url = do
response <- httpLBS url
let statusCode = show $ getResponseStatusCode response
putStrLn statusCode
当调用getStatusCode "http://httpbin.org/get"
时,我收到以下错误:
<interactive>:38:15: error:
* Couldn't match expected type `Request' with actual type `[Char]'
* In the first argument of `getStatusCode', namely
`"http://httpbin.org/get"'
In the expression: getStatusCode "http://httpbin.org/get"
In an equation for `it':
it = getStatusCode "http://httpbin.org/get"
错误消息似乎暗示httpLBS需要Request类型。但我无法弄清楚为什么第一个在这种情况下起作用。