title: Merging lists on matching element
body: <p>I wrote a function to merge two pair lists, in this case each element containing a character and a number. </p>
  
  <pre><code>mergeTupleList [] blist = blist
  mergeTupleList alist [] = []
  mergeTupleList (a:ab:as) (b:bn:bs) =
      if ab == b
          then a:[] ++ bn:[] ++ mergeTupleList (a:ab:as) (bs)
          else [] ++ mergeTupleList (as) (b:bn:bs)
  
  listA = [('a',1),('b',1),('a',2),('b',1)] 
  listZ = [('b',1),('z',1),('b',1),('z',2)]
  </code></pre>
  
  <p>It seems that in the 'else' case (b:bn:bs) is not the whole pair list loaded in the beginning, but the short version (bs) because it has been filtered by the 'then' condition. 
  I'm looking for a way to transmit the original (b:bn:bs) list to this function.</p>
  
  <p>input and output:</p>
  
  <pre><code>*Main&gt; mergeTupleList ListA ListZ
  [('a',1),('z',1),('a',1),('z',2)]
  </code></pre>
  
  <p>expected output:</p>
  
  <pre><code>[('a',1),('z',1),('a',1),('z',2),('a',2),('z',1),('a',2),('z',2)]
  </code></pre>
  
  <p>For clarification : </p>
  
  <blockquote>
    <p>Perhaps merging is not the adequate word. For every (second) element in <code>ListA</code> existing in the original <code>ListZ</code> write the element following it.</p>
  </blockquote>
  
  <p>Another example:</p>
  
  <pre><code>ListA = [1,0,3,0]
  ListZ = [0,8,0,9]
  
  *Main&gt; mergeTupleList listA listZ 
  [1,8,1,9]
  </code></pre>
  
  <p>expected output:
  <code>[1,8,1,9,3,8,3,9]</code></p>