[Haskell-cafe] More Efficient Recursion
lemming at henning-thielemann.de
Sun Feb 21 00:50:52 UTC 2021
On Sat, 20 Feb 2021, A. Mc. wrote:
> I'm just starting off, but I'm wondering if anyone has any suggestions. I've made a recursive function that's goal is to handle a
> base raised to a very large power.
> modLoop :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer
> modLoop iterator exponent result base modulus
> | (iterator == exponent) = result
> | (iterator < exponent) = modLoop (iterator + 1) (exponent) (mod (result * base) modulus) base modulus
> | (iterator > exponent) = (-1)
Btw. what about:
case compare iterator exponent of
GT -> ...
More information about the Haskell-Cafe