title: Haskell : Problem converting result of division to integral type
body: <p>I'm learning Haskell and stuck trying to understand the type system.</p>
  
  <p>I'm trying to write a function which returns the length of the series 'Half or Three Plus One' for an input. Here's my attempt at the function, using a recursive approach (the function is valid for integral inputs only):</p>
  
  <pre><code>hotpo :: (Integral a) =&gt; a-&gt;a
  hotpo n = hotpoHelper n 1
  
  hotpoHelper:: (Integral a) =&gt; a-&gt;a-&gt;a
  hotpoHelper 1 n = n
  hotpoHelper num count
      | even num = hotpoHelper (truncate (num/2)) (count+1)
      | otherwise = hotpoHelper (3*num+1) (count+1)
  </code></pre>
  
  <p>Here is the error I get when I try to load this file in GHC 6.12.3</p>
  
  <pre><code>test.hs:8:30:
      Could not deduce (RealFrac a) from the context (Integral a)
        arising from a use of `truncate' at test.hs:8:30-45
      Possible fix:
        add (RealFrac a) to the context of
          the type signature for `hotpoHelper'
      In the first argument of `hotpoHelper', namely
          `(truncate (num / 2))'
      In the expression: hotpoHelper (truncate (num / 2)) (count + 1)
      In the definition of `hotpoHelper':
          hotpoHelper num count
                        | even num = hotpoHelper (truncate (num / 2)) (count + 1)
                        | otherwise = hotpoHelper (3 * num + 1) (count + 1)
  </code></pre>
  
  <p><code>take (truncate (5/2)) [1,2,3]</code> works, so I'm unable to understand this error message.
  Where am I going wrong?</p>