[Haskell-beginners] Trying to use map

Michael Litchard michael at schmong.org
Thu Jan 27 00:36:57 CET 2011


google hosed my indentation

> obtainCookies :: IO Curl -> String -> IO ()
> obtainCookies curl responseBody = do
>               curl' <- curl
>               mapM_ (flip (curlResp curl') resourceOpts) $
>                     screenScraping responseBody



On Wed, Jan 26, 2011 at 3:32 PM, Michael Litchard <michael at schmong.org>wrote:

> Thank you.
>
> Here is where things stand now
>
>
> > obtainCookies :: IO Curl -> String -> IO ()
> > obtainCookies curl responseBody = do
> > curl' <- curl
> > mapM_ (flip (curlResp curl') resourceOpts) $
>
> > screenScraping responseBody
>
>
> and the error
>
> htmlParsing.lhs:78:2:
>
> Couldn't match expected type `[Char]'
> against inferred type `GHC.IO.Exception.IOException'
> Expected type: String
>
> Inferred type: IOError
> When using functional dependencies to combine
> MonadError IOError IO,
> arising from the dependency `m -> e'
> in the instance declaration at <no location info>
> MonadError String IO,
>
> arising from a use of `curlResp' at HtmlParsing.lhs:80:29-42
> When generalising the type(s) for `obtainCookies'
>
> I'm way beyond my ken here, trying to grow. I have to do error handling (this will be production code when it grows up), got some suggestions on how to do so, but am flying blind in new territory.
>
> Any suggestions on how to proceed would be much appreciated.
>
>
> On Wed, Jan 26, 2011 at 3:13 PM, Daniel Fischer <
> daniel.is.fischer at googlemail.com> wrote:
>
>> On Wednesday 26 January 2011 23:51:18, Michael Litchard wrote:
>> > Here's what I'm working with, followed by what I am trying to do, and
>> > the type error I get. I'm leaving things out that I do not think are
>> > important. Let me know if I'm missing nessecary info.
>> > >
>> > >
>> > > obtainCookies :: IO Curl -> String -> IO ()
>> > > obtainCookies curl responseBody = do
>> > >               curl' <- curl
>> > >               let collectedResources = screenScraping responseBody
>> > >                   in mapM ( curlResp curl' resourceOpts)
>> >
>> > collectedResources
>> >
>>
>> Looks like you need a flip here:
>>
>>           in mapM (flip (curlResp curl') resourceOpts) collectedResources
>>
>> > >               return ()
>>
>> If you're throwing away the results of the MapM'ed actions, use mapM_
>>
>> obtainCookies curl responseBody = do
>>    curl' <- curl
>>     mapM_ (flip (curlResp curl') resourceOpts) $
>>          screenScraping responseBody
>>
>> >
>> > this function does a monadic action (all I want is the cookies) and I
>> > don't need the return value. I am not sure that the final line return
>> > (), is what I want.
>> >
>> >
>> > My primary question is this. how do I map over collectedResources
>> > correctly? Secondary question, is the return correct?
>>
>> Use mapM_
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110126/f31a3b83/attachment.htm>


More information about the Beginners mailing list