[Haskell-cafe] tried to use the example given in the source of
network.browser
Neil Brown
nccb2 at kent.ac.uk
Fri Oct 22 10:50:34 EDT 2010
Hi,
On 22/10/10 14:58, Michael Litchard wrote:
>
>> main =
>> do
>> rsp<- Network.Browser.browse $ do
>> setAllowRedirects True -- handle HTTP redirects
>> request $ getRequest "http://google.com/"
>> fmap (take 100) (getResponseBody rsp)
>>
> but I got this errortest.lhs:10:39:
> Couldn't match expected type `Network.Stream.Result (Response [a])'
> against inferred type `(Network.URI.URI, Response String)'
> In the first argument of `getResponseBody', namely `rsp'
> In the second argument of `fmap', namely `(getResponseBody rsp)'
> In the expression: fmap (take 100) (getResponseBody rsp)
>
>
> how did I get this error? I'm perplexed as this came right from the source.
>
To be specific, it came from the documentation of the library... which
turns out not to match the source. It seems you instead want:
> main = do
> (_, rsp) <- Network.Browser.browse $ do
> setAllowRedirects True -- handle HTTP redirects
> request $ getRequest "http://google.com/"
> print (take 100 $ rspBody rsp)
I've changed the last bit to print the first 100 lines of the result
rather than return them, as I imagine that is what you want if you're
using it as a main function.
Thanks,
Neil.
More information about the Haskell-Cafe
mailing list