title: Sort a multimap with respect to another list?
body: <p>Given a certain order of keys, how can I sort a multimap (list of tuples with duplicate keys) with respect to this list, where the order of duplicate elements doesn't matter?</p>
  
  <p>I'm looking for a function with the following signature</p>
  
  <pre><code>sortByList :: [(a,b)] -&gt; [a] -&gt; [(a,b)]
  </code></pre>
  
  <p>such that, for instance,</p>
  
  <pre><code>a = [(1,'a'), (2, 'b'), (102, 'c'), (2, 'z')]
  b = [2,102,1]
  sortByList a b   --    [(2,'b'), (2,'z'), (102, 'c'), (1, 'a')]
                   -- or [(2,'z'), (2,'b'), (102, 'c'), (1, 'a')] 
                   -- (order in duplicate keys irrelevant)
  </code></pre>
  
  <p>I have some ideas how to implement this, but they all seem ugly and cumbersome (using <code>lookup</code> and repeated find-and-delete on the given multimap).</p>