I'm trying to take an input, which I will call "Names", and use it to get an output, "Values" from a list in which "Value" is all lists that contain the given "Name". For example, if the list of lists is:
listOfLists = [("Name1", [Value1]), ("Name2", [Value2, Value3]), ("Name3", [Value1, Value2, Value3])]
and I give the input "Name 1, Name3" it will return "Value 1", as that is the value found in each.
Currently, what I have is this:
find_languages [] [] = []
find_languages ((x, y):xs) (courses) = filter ((x `elem` courses)((x, y):xs))
This is not working and I'm hoping for some tips. Some notes:
- There should be no recursion
- I can only use the Prelude Library
- I can use a function I have already written,
commons_all, which returns all common values across a list of lists - this should make it easy but I'm not sure how to implement it.
commons_all :: Eq a => [[a]] -> [a]
commons_all [] = []
commons_all (x:xs) = foldl commons x xs
The expected form will be
find_languages :: (Eq a1, Eq a2) => [(a2, [a1])] -> [a2] -> [a1]
Currently, this isn't the form the function takes.