title: Division in Haskell for Numeric class
body: <p>I am trying to define a function <code>toVal :: (Num a) =&gt; (Fraction a) -&gt; a</code>. The function takes a fraction and evaluates its numeric value. But since the function uses division, I can do the following since division is defined by different functions on the subclasses of <code>Num a</code>:</p>
  
  <pre><code>data Fraction a = Constant a
      |Rational{numerator :: (Fraction a), denominator :: (Fraction a)}
  
  
  toVal1 :: (Integral a) =&gt; (Fraction a) -&gt; a
  toVal1 (Constant a) = a
  toVal1 (Rational num den) = (toVal1 num) `div` (toVal1 den)
  
  toVal2 :: (Fractional a) =&gt; (Fraction a) -&gt; a
  toVal2 (Constant a) = a
  toVal2 (Rational num den) = (toVal2 num) / (toVal2 den)
  </code></pre>
  
  <p>Is there a way I can combine the two functions so that I can have a generic function <code>toVal :: (Num a) =&gt; (Fraction a) -&gt; a</code>?</p>