title: Prefixes in haskell
body: <p>I've written 2 functions in haskell, and now i have to write a third one, for calculating the number of prefixes in haskell. here's an example:</p>
  
  <p>i have to lists. the first is the prefixes list, and the other one is the text list. what this function is suppose to do, is to calculate the number of times each word from the prefix list is a prefix of all the words in the text list, and present it in a tuple (word, number of times it appears as a prefix in the text words:</p>
  
  <p>prefix list ["go", "co"]</p>
  
  <p>text list ["golf", "company", "count"]</p>
  
  <p>this should return [("go", 1) , ("co", 2)]</p>
  
  <p>i have this:</p>
  
  <pre><code>isPrefixOf :: (Eq a) =&gt; [a] -&gt; [a] -&gt; Bool
  isPrefixOf [] _ = True
  isPrefixOf _ [] = False
  isPrefixOf (x:xs) (y:ys) = x == y  &amp;&amp; isPrefixOf xs ys
  
  
  prefixCount :: (Eq a1, Num a) =&gt; [a1] -&gt; [[a1]] -&gt; a
  prefixCount _ [] = 0
  prefixCount x (y:ys) | isPrefixOf x y = 1 + prefixCount x ys
                   | otherwise = prefixCount x ys
  
  
  howManyPrefixes [] _ = error("empty list!")
  howManyPrefixes (x:xs) y  = map (\x -&gt; (x,prefixCount x y)) xs
  </code></pre>