title: haskell power function
body: <p>how to write a power function which makes use of the following facts: To raise x to a power n (where n is a positive whole number), if n  is even, you can find the nth power of x by squaring half that power. For example, x^12 is x^6 * x^6. For odd powers, just subtract one from the power, and multiply the result for the smaller power by x. for example, x^13  is x * x^12, which is x * x^6 * x^6. Recursively, any power can be found with less work than multiplying x by itself the number of times indicated.
  I came up with this</p>
  
  <pre><code>power x n
      | n == 0  =  1
      | x == 0  =  0
      | even n = ( power x (n / 2) ) * ( power x (n / 2) )
      | odd n = x * ( power x ((n - 1) / 2)) * ( power x ((n - 1) / 2) )
  </code></pre>
  
  <p>but I get an error saying ERROR - Unresolved overloading
  <strong>* Type       : (Integral a, Fractional a) => Integer
  *</strong> Expression : power 2 2</p>