title: Haskell underscore vs. explicit variable
body: <p>I've been learning Haskell for a few weeks, and I have a question about the use of the underscore (<code>_</code>) as a function parameter. I think my question will be better asked with a specific example. Let's say I want to define a function that extracts the element of a list based on the provided index—yes, I realize <code>(!!)</code> is already pre-defined. The two ways that I can define the function (I'm sure there are more) are the following:</p>
  
  <p><strong>Version 1</strong></p>
  
  <pre><code>indexedElement             :: [a] -&gt; Int -&gt; a
  indexedElement xs n | n &lt; 0 = error "Index can not be negative."
  indexedElement [] n         = error "Index must be smaller than the length of the list."
  indexedElement (x:xs) 0     = x
  indexedElement (x:xs) n     = indexedElement xs (n - 1)
  </code></pre>
  
  <p><strong>Version 2</strong></p>
  
  <pre><code>indexedElement            :: [a] -&gt; Int -&gt; a
  indexedElement _ n | n &lt; 0 = error "Index can not be negative."
  indexedElement [] _        = error "Index must be smaller than the length of the list."
  indexedElement (x:_) 0     = x
  indexedElement (_:xs) n    = indexedElement xs (n - 1)
  </code></pre>
  
  <p>The two versions are obviously very similar. The only difference between the two is the use of an explicit variable or an underscore. To me <code>_</code> means that literally anything can be written there while an explicit variable like <code>n</code> makes it more obvious that the argument must be an integer. For that reason, I prefer Version 1; but the GHC source code for <code>(!!)</code> is written like Version 2. Is there a functional advantage of the second version? If not, would "hardcore" Haskell programmers take issue with Version 1? I understand the importance of having a consistent way of writing code, so I try to follow the "unwritten rules" for programming in a particular language. This is an example where I much prefer the first version though, and I don't think it makes the code any more difficult to read. I don't know if it's due to my background in pure math or what, but I'd like to hear what you more-seasoned-Haskell vets think.</p>