2 ms·
In fact, exponentiation f : C x N -> C has a natural generalization to any monoid C, where f(x,n) is x "multiplied" by itself using the monoid operator n times.
by rntz 13y ago
In fact, exponentiation f : C x N -> C has a natural generalization to any monoid C, where f(x,n) is x "multiplied" by itself using the monoid operator n times. In this setting, the only sensible choice is that x^0 = 1 for any x, where 1 is the unit of the monoid in question. In particular, that is the only definition of exponentiation which is parametric in our choice of monoid.
Naive Haskell example code (using Int for Nat):
f :: Monoid m => (m,Int) -> m
f (x,0) = mempty
f (x,n) = x `mappend` f (x,n-1)
-- or equivalently
f (x,n) = msum (replicate n x)