[Haskell-cafe] More Efficient Recursion

A. Mc. 47dragonfyre at gmail.com
Sun Feb 21 00:36:00 UTC 2021


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)

However, it flat breaks or takes a long time when using large numbers.

I need to get better at using strict functions, however, I compiled with
ghc -o (as it tends to implement the strict version - ?) and I still have
the same problem.  What's a better way?

Thanks in advance and thank you for your time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210220/e73a2df5/attachment.html>


More information about the Haskell-Cafe mailing list