Some Help with Haskell

Associate
Joined
2 Feb 2011
Posts
133
I'm not sure if this is the right place to post this, apologies if it isn't!

I'm currently learning Haskell and have come across a problem I can't get my head around.

I'll try to explain it as best as I can.

Essentially I have two lists of tuples which are as follows: [(String,Integer)] and [(Float,Integer)] - (each list has several tuples)

What I need to do is: For every integer that has a float in the second list check if it's integer matches the integer in the first list and if it does return the string, although this function needs to return a list of strings, i.e. [String] with all the results.

I have already defined a function which returns a list of Integers from the second list (for the comparison on the integers in the first list).

This should be solvable using "high-order functions" of which I've spent a considerably amount of time playing with map and filter but haven't found a solution!

Thanks
 
Think i've understood whay you're trying to do, but something like this?

PHP:
matchingStrings a b = [x | (x,y) <- a, y `elem` (map snd b)]

Running:

PHP:
matchingStrings [("One", 1), ("Three", 3)] [(1.0, 1), (2.0, 2)]

Gives

PHP:
["One"]

Not done Haskell in a while
 
Last edited:
Back
Top Bottom