title: Haskell - replace strings in list with values from a map
body: <p>i have this problem:
  i want to have a list of strings representing math expression, and a map of arguments to replace the variables.
  so if my list is like ["x","+","y","-","5"] and arguments are [("x","5"),("y","4")]
  the function should return ["5","+","4","-","5"]</p>
  
  <p>i have this function to find key from map (from the Learn you a haskell book)</p>
  
  <pre><code>findKey :: (Eq k) =&gt; k -&gt; [(k,v)] -&gt; Maybe v
  findKey key [] = Nothing
  findKey key ((k,v): xs) = 
          if key == k
             then Just v
             else findKey key xs
  </code></pre>
  
  <p>and then my function to replace the variables with values</p>
  
  <pre><code>takeValuesFromMap (x:str) m result
          |x == [] = result
          |findKey x m == Nothing = takeValuesFromMap str m (result++[x])
          |otherwise = takeValuesFromMap str m result++[fromJust (findKey x m)]
  </code></pre>
  
  <p>if no match in the map, we pass the regular string. Otherwise we pass to the result the value staying next to the key that matches.</p>
  
  <p>but in the end when i call</p>
  
  <pre><code>takeValuesFromMap ["x","+","y","-","5"] (Map.fromList [("x","5"),("y","4")]) []
  </code></pre>
  
  <p>it says </p>
  
  <pre><code>Solver.hs:63:48:
  Couldn't match expected type `[([Char], [Char])]'
              with actual type `Map.Map [Char] [Char]'
  In the return type of a call of `Map.fromList'
  In the second argument of `takeValuesFromMap', namely
    `(Map.fromList [("x", "5"), ("y", "4")])'
  In the expression:
    takeValuesFromMap
      ["x", "+", "y", "-", ....]
      (Map.fromList [("x", "5"), ("y", "4")])
      []
  </code></pre>
  
  <p>any idea how to fix this?</p>