title: Haskell: Parse error in pattern x ++ xs
body: <p>Doing the <a href="https://wiki.haskell.org/99_questions/1_to_10" rel="nofollow noreferrer">third of the 99-Haskell problems</a> (I am currently trying to learn the language) I tried to incorporate pattern matching as well as recursion into my function which now looks like this:</p>
  
  <pre><code>myElementAt :: [a] -&gt; Int -&gt; a
  myElementAt (x ++ xs) i =
    if length (x ++ xs) == i &amp;&amp; length xs == 1 then xs!!0
    else myElementAt x i
  </code></pre>
  
  <p>Which gives me <code>Parse error in pattern: x ++ xs</code>. The questions:</p>
  
  <ol>
  <li>Why does this give me a parse error? Is it because Haskell is no idea where to cut my list (Which is my best guess)?</li>
  <li>How could I reframe my function so that it works? The algorithmic idea is to check wether the list has the length as the specified inde; if yes return the last elemen; if not cut away one element at the end of the list and then do the recursion.</li>
  </ol>
  
  <p>Note: I know that this is a really bad algorithm, but it I've set myself the challenge to write that function including recursion and pattern matching. I also tried not to use the <code>!!</code> operator, but that is fine for me since the only thing it really does (or should do if it compiled) is to convert a one-element list into that element.</p>