title: Haskell's if statement for error checking
body: <p>I wrote a function for the Haar wavelet transformation given that the input is a List with a power of 2. I was trying to error check by making sure that the length of the List is a power of 2 before preforming the transformation. I am comparing the log base 2 of the length of the list to see if it comes out evenly (nothing to the right of the decimal point). I think there is something going on with the if statement in haskell that I am not used to in other languages. It works perfectly if I don't error check and just call haar with the proper argument. </p>
  
  <pre><code>haar :: (Fractional a) =&gt; [a] -&gt; [a]
  haar xs = if logBase 2 (fromIntegral (length xs)) /= truncate (logBase 2 (fromIntegral (length xs)))
               then error "The List must be a power of 2"
               else haarHelper xs (logBase 2 (fromIntegral (length xs)))
  
  haarHelper xs 1 = haarAvgs xs ++ haarDiffs xs
  haarHelper xs level = haarHelper (haarAvgs xs ++ haarDiffs xs) (level - 1)
  
  haarAvgs [] = []
  haarAvgs (x:y:xs) = ((x + y) / 2.0) : haarAvgs xs 
  
  haarDiffs [] = []
  haarDiffs (x:y:xs) = ((x - y) / 2.0) : haarDiffs xs
  </code></pre>
  
  <p>I am getting the following error message:</p>
  
  <pre><code>functions.hs:52:13:
      Ambiguous type variable `t' in the constraints:
        `Floating t'
          arising from a use of `logBase' at functions.hs:52:13-48
        `Integral t'
          arising from a use of `truncate' at functions.hs:52:53-99
      Probable fix: add a type signature that fixes these type variable(s)
  Failed, modules loaded: none.
  </code></pre>