I am very interested in Haskell and currently trying to solve this problem.
To solve the problem it is necessary to output List C (x,z) that matches (x,y) from List A and (y,z) from List B (without duplicates) y must be equal in A and B.
So for example:
A = [("z","x")]
B = [("x","c"), ("x","d")]
Result:
C = [("z","c"), ("z","d")]
Any ideas? I have started today with:
main = print(map describeList3 list_A)
describeList3 :: ([Char], [Char]) ->Maybe [[Char]]
describeList3 element = printParam(snd element)
printParam :: String -> Maybe [[Char]]
printParam param = (Map.lookup param $ myFilter list_B)
myFilter :: (Ord k) => [(k, a)] -> Map.Map k [a]
myFilter xs = Map.fromListWith (++) $ map (\(k,v) -> (k,[v])) xs
Currently stuck… help?
List comprehensions quick and dirty solution. As for duplicates you can remove them with either nub (from Data.List), or with converting result to Data.Set and back to list.
Or with map. We create auxiliary map for list b, where value is list of values from list. And then just build for each (x,y) pair list of required (x,z) pairs (with non-nil check). Actually i think you were stuck precisely because you didn’t use list comprehensions. 🙂 Maps / filters are great for processing, but building is much easier understood in terms of list comprehensions.