Skip to content

Instantly share code, notes, and snippets.

@trhura
Created December 8, 2014 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trhura/5c6cd143b221022133f1 to your computer and use it in GitHub Desktop.
Save trhura/5c6cd143b221022133f1 to your computer and use it in GitHub Desktop.
-- Assuming a and b are not negative
multiply a 0 = 0
multiply a 1 = a
multiply a b = a + multiply a (b-1)
-- Assuming e is not negative
power b 0 = 1
power b 1 = b
power b e = multiply b $ power b (e-1) -- aka multiply b (power b e-1)
main = do
print $ power 2 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment