title: Haskell - Filtering Lists by Comparison
body: <p>I need to filter a list with a mask in Haskell.</p>
  
  <p>It applies the function to an element of the mask list and the corresponding element in the data list, and if the function returns true, the corresponding element in the data list is included in the returned list. </p>
  
  <p>For example, suppose I want to filter out data items that are greater than the mask items: </p>
  
  <pre><code>filtermask (\m d -&gt; d &gt; m) [1, 5, 7] [5, 6, 7]→[5, 6]
  </code></pre>
  
  <p>Any possible solution to this problem would be fantastic. So far, I've only done </p>
  
  <pre><code> filtermask f m d = f m d
  </code></pre>
  
  <p>That returns TRUE</p>
  
  <p>EDIT: Solution, thanks to help from Tikhon:</p>
  
  <pre><code>filtermask f [] [] = []
  filtermask f (fm:rm) (fd:rd)
    |f fm fd = fd:filtermask f rm rd
    |otherwise = filtermask f rm rd
  </code></pre>