title: Last element of two list recursion
body: <p>This is a part of home exercise, which I've thought through, but don't understand last obstacle.</p>
  <p>Idea of task is to implement unusual substring function, which works in following way:</p>
  <blockquote>
  <p>Write a function <code>commonSubstring :: String -&gt; String -&gt; String</code> that, given two strings <code>s1</code> and <code>s2</code>, computes a common “substring” of <code>s1</code> and <code>s2</code> as follows. The function finds the earliest common character <code>c</code> (closest to <em>head</em> of either <code>s1</code> or <code>s2</code> appearing in both sequences). The function removes <code>c</code> and all the characters before it in both strings, puts <code>c</code> in the output string, and continues.</p>
  <p>If there are two candidates for the earliest common character, pick the one from <code>s1</code>.</p>
  </blockquote>
  <p>And example of calling such function would be:</p>
  <blockquote>
  <pre class="lang-hs prettyprint-override"><code>commonSubstring &quot;XabcdefgY&quot; &quot;abcdefgXY&quot;
  &gt; &quot;XY&quot;
  
  commonSubstring &quot;abcdefgXY&quot; &quot;XabcdefgY&quot;
  &gt; &quot;abcdefgY&quot;
  </code></pre>
  </blockquote>
  <p>So, I've implemented following recursion, which kinda works:</p>
  <pre class="lang-hs prettyprint-override"><code>commonSubstring :: String -&gt; String -&gt; String
  commonSubstring first_string second_string 
      | length(second_string)==0=[]
      | take 1 first_string ==take 1 second_string=take 1 first_string ++ commonSubstring (tail first_string)(tail second_string)
      | otherwise=commonSubstring first_string (tail second_string)
  </code></pre>
  <p>Question is: Why doesnt function return final symbol from matching pairs of heads?</p>
  <pre class="lang-hs prettyprint-override"><code>commonSubstring &quot;abcdefgXY&quot; &quot;XabcdefgY&quot;
  &gt;&quot;abcdefg&quot;
  
  commonSubstring &quot;XabcdefgY&quot; &quot;abcdefgXY&quot;
  &gt;&quot;X&quot;
  </code></pre>