Re: [haskell-exercises] Functions

118 views
Skip to first unread message
Message has been deleted

David Tchepak

unread,
Nov 2, 2017, 6:33:10 PM11/2/17
to Mirasol Davila, haskell-exercises
Can you clarify what you're trying to do?

Do you want to transform [(1,2), (3,4)]  to [3, 7] ? Or are you working with two lists?



On Fri, Nov 3, 2017 at 3:24 AM, Mirasol Davila <mirasol...@gmail.com> wrote:

I can't seem to use map to get the sum of the numbers in the tuples. How would you combine map with zip?

zip' :: [a] -> [b] -> [(a,b)]
zip' _ [] = []
zip' [] _ = []
zip' (x:xs) (y:ys) = (x, y):zip' xs ys
    where map (\(x,y) -> x + y)

--
You received this message because you are subscribed to the Google Groups "haskell-exercises" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-exercises+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Tony Morris

unread,
Nov 2, 2017, 8:32:13 PM11/2/17
to Mirasol Davila, haskell-exercises
zipWith (+) [4,5,6,7] [8,6,4,5] 

On 3 Nov. 2017 10:30, "Mirasol Davila" <mirasol...@gmail.com> wrote:
I'm working with two lists so an example could be [4,5,6,7] [8,6,4,5] and when we use zip' we will get [(4,8), (5,6), (6,4), (7,5)] then I want to use map that sums the number of each tuple which in this case would be [12,11,10,12]. I just don't understand how to combine map into the zip' function.


On Thursday, November 2, 2017 at 3:33:10 PM UTC-7, David Tchepak wrote:
Can you clarify what you're trying to do?

Do you want to transform [(1,2), (3,4)]  to [3, 7] ? Or are you working with two lists?


On Fri, Nov 3, 2017 at 3:24 AM, Mirasol Davila <mirasol...@gmail.com> wrote:

I can't seem to use map to get the sum of the numbers in the tuples. How would you combine map with zip?

zip' :: [a] -> [b] -> [(a,b)]
zip' _ [] = []
zip' [] _ = []
zip' (x:xs) (y:ys) = (x, y):zip' xs ys
    where map (\(x,y) -> x + y)

--
You received this message because you are subscribed to the Google Groups "haskell-exercises" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-exerci...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Message has been deleted

David Tchepak

unread,
Nov 2, 2017, 8:50:23 PM11/2/17
to Mirasol Davila, haskell-exercises
I'd avoid thinking about combining map *into* zip', and more combining map *with* zip'.

You've done the first bit: zip' [4,5,6,7] [8,6,4,5] = [(4,8), (5,6), (6,4), (7,5)].
Now you want a function along the lines of [(Int, Int)] -> [Int], which you wrote in your original post: map (\(x,y) -> x + y).

The final operation is then something like:

myFn :: [Int] -> [Int] -> [Int]
myFn xs ys = _useMapHere (zip' xs ys)

Hope that helps get you unstuck.


On Fri, Nov 3, 2017 at 11:30 AM, Mirasol Davila <mirasol...@gmail.com> wrote:
I'm working with two lists so an example could be [4,5,6,7] [8,6,4,5] and when we use zip' we will get [(4,8), (5,6), (6,4), (7,5)] then I want to use map that sums the number of each tuple which in this case would be [12,11,10,12]. I just don't understand how to combine map into the zip' function.

On Thursday, November 2, 2017 at 3:33:10 PM UTC-7, David Tchepak wrote:
Can you clarify what you're trying to do?

Do you want to transform [(1,2), (3,4)]  to [3, 7] ? Or are you working with two lists?


On Fri, Nov 3, 2017 at 3:24 AM, Mirasol Davila <mirasol...@gmail.com> wrote:

I can't seem to use map to get the sum of the numbers in the tuples. How would you combine map with zip?

zip' :: [a] -> [b] -> [(a,b)]
zip' _ [] = []
zip' [] _ = []
zip' (x:xs) (y:ys) = (x, y):zip' xs ys
    where map (\(x,y) -> x + y)

--
You received this message because you are subscribed to the Google Groups "haskell-exercises" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-exerci...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages