title: Linear recursive method for counting palindrome numbers between 2 integers in Haskell
body: <p>I'm solving a practice problem in Haskell where I'm trying to count the palindrome numbers between 2 given integers. Single-digit numbers are palindromes. I've tried solving it with a helper function but I can't make it take the smaller number from the main function. Any help would be appreciated!
  So far I typed this:</p>
  <pre><code>main :: IO()
  main = do
  print $ countPalindromes 5 13 == 5 -- 6 7 8 9 11
  print $ countPalindromes 13 5 == 5 -- 6 7 8 9 11
  
  rev :: Int -&gt; Int
  rev n = helper n 0
  where
   helper :: Int -&gt; Int -&gt; Int
   helper 0 result = result
   helper n result = helper (div n 10) (result * 10 + mod n 10)
  
  isPalindrome :: Int -&gt; Bool
  isPalindrome x = rev x == x
  
  countPalindromes :: Int -&gt; Int -&gt; Int
  countPalindromes a b
    | a &gt; b = helper b a 0
    | otherwise = helper a b 0
    where
        helper :: Int -&gt; Int -&gt; Int -&gt; Int
        helper a b count
         | a &lt;= b &amp;&amp; isPalindrome (a - 1) = count + 1 
         | otherwise = helper (a - 1) b count
  </code></pre>