In my opinion, the Fractional and/or Numeric type-classes lack one feature that I personally end up recoding a lot: being able to exponentiate by an integer.
Currently, only the math package has the function pow, acting only on Doubles. But any group can be equipped with integer exponentiation, and any monoid with non negative integer exponentiation. Of course, in the case of Numeric and Fractional, exponentiation is naturally associated with the “times” and “div” (for the latter) methods. This, for the case of Numeric, leaves a question mark: should a negative exponentiation of a numeric return 0, or raise an exception?
numericPow and a
fractionalPow to both of these type classes.
I would use
** since ^ is already taken, and it is consistent with some other languages, such as python.
To be discussed
What should a negative exponentiation on numeric give? And perhaps the symbol…
Simply defining the two afore mentioned functions in the math package, asking for implicit Numeric or Fractional, so something like
def numericPow[A: Numeric](base: A, exponent: Int): A = ???