Skip to content

Instantly share code, notes, and snippets.

@urbanslug
Created March 21, 2014 03:52
Show Gist options
  • Save urbanslug/9679201 to your computer and use it in GitHub Desktop.
Save urbanslug/9679201 to your computer and use it in GitHub Desktop.
import Data.Monoid
power :: (Monoid a, Integral i) => a -> i -> a
power _ 0 = mempty
power a n | r==0 = b
| otherwise = a `mappend` b
where (q,r) = n `divMod` 2
b = (a `mappend` a) `power` q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment