title: Pattern Match Failure in List in Haskell
body: <p>I have one problem with pattern matching. When I give input to <strong>(x:y:ys)</strong>  the list containing 3 elements, hugs complain that there is: <strong>pattern match failure</strong>.
  I guess that the problem is here</p>
  
  <pre><code>takeNearestOnes agent (y:ys) (x:nearestOnes)
  </code></pre>
  
  <p>because it fails to match three elements with list containing two elements</p>
  
  <p>This is full code:</p>
  
  <pre><code>takeNearestOnes agent (x:y:ys) nearestOnes
              | first == second =  takeNearestOnes agent (y:ys) (x:nearestOnes)
              | otherwise = (x:nearestOnes)
          where first=(manhattanDistance x (agentCoord agent))
                second=(manhattanDistance y (agentCoord agent)
  </code></pre>
  
  <p>How can I overcome this? Thanks in advance</p>