I have a question about Haskell. I want to know how I can create a list of data from two lists, one with data, an other with some key values. I’ll explain it with an example:
Given two lists: [('a', "red"), ('b', "blue"), ('c', "green")] and [('a','b'), ('b', 'c'), ('c','a')]. Now I want to change the values of the second list with their colors given in the first list. So the function should return [("red","blue"), ("blue","green"), ("blue","red")].
I was thinking about list comprehension, but I’m very new to Haskell and I have no idea how I should do that. Or is there an easier way to do this?
This is probably a dumb question, but if someone can give me an example, I might get used to the think process of Haskell a bit more.
running
If you consider an element of the second list cannot be found in the first list. You can write
then
(you need
import Data.Maybe (listToMaybe))