Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: foldM with tuple and maybe (Dominik Bollmann)
----------------------------------------------------------------------
Message: 1
Date: Mon, 03 Feb 2014 10:55:12 -0500
From: Dominik Bollmann <[email protected]>
To: David McBride <[email protected]>, Miro Karpis
<[email protected]>, The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] foldM with tuple and maybe
Message-ID:
<87wqhcur6n.fsf@debox.i-did-not-set--mail-host-address--so-tickle-me>
Content-Type: text/plain
Or maybe what you really want is mapM instead of foldM? In this case,
your function f2 will look like this:
f2 :: [(String, String)] -> IO [Maybe String]
f2 xs = mapM f1 xs
And this will first map (=apply) your function f1 over all elements in
the given input list xs and then it will sequence this list, thus
creating a resulting list of type IO [Maybe String]
David McBride <[email protected]> writes:
> You have a foldM function which takes a " a -> b -> m a " as a first
> argument. But you are passing it f1 which has a type (a, b) -> m a.
>
> Unfortunately I'm not sure what you were trying to do. The function
> you have just doesn't fit. :(
>
> Maybe you intended to have f1 :: String -> (String, String) -> IO
> String, and then go
>
> :t foldM f1 "" x
> foldM f1 "" [("a","b"),("c","d")] :: IO String
>
>
> ?
>
> On Mon, Dec 30, 2013 at 6:42 PM, Miro Karpis <[email protected]>
> wrote:
>> Hi, please can you help me with following?
>>
>> I have a following function:
>> f1 :: (String, String) -> IO (Maybe String)
>>
>> which I would like to apply to a list of tuples.I have defined the function
>> like this, but that gives me error (below):
>>
>> f2 :: [(String, String)] -> IO (Maybe String)
>> f2 x = foldM f1 0 x
>>
>>
>> error:
>> Couldn't match expected type `IO (Maybe String)' with actual type `[b0] ->
>> m0 (String, String)' In the return type of a call of `foldM'
>>
>> thanks,
>> m.
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 68, Issue 2
****************************************