Specialized exponentiation operators

David Feuer david.feuer at gmail.com
Thu Nov 1 17:24:17 UTC 2018


We currently have

  (^) :: (Num a, Integral b) => a -> b -> a
  (^^) :: (Fractional a, Integral b) => a -> b -> a
  stimes :: (Semigroup a, Integral b) => b -> a -> a

These are very general, but the ergonomics are terrible. The trouble
is that in each case, the `b` type variable is a (constrained) type
that appears only in one argument and not in the result. In the
extremely common case where the exponent is a literal, we rely on
defaulting to fix `b ~ Integer`. When the exponent is very small, it
will then be rewritten to a simple multiplication. Otherwise, it will
pay the price of bignum arithmetic, whether that's required or not.

Is there a canonical package providing versions of these functions
with the exponent specialized to `Int` and/or `Word`? If not, where
might such fit well?


More information about the Libraries mailing list