[Haskell-cafe] More Efficient Recursion

Henning Thielemann lemming at henning-thielemann.de
Sun Feb 21 00:50:52 UTC 2021


On Sat, 20 Feb 2021, A. Mc. wrote:

> Hello,
> 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
      EQ ->
      LT ->
      GT -> ...


More information about the Haskell-Cafe mailing list