[Haskell-cafe] memorize function with number parameterized types in GHC
polyomino at f2s.com
Sun Nov 6 22:51:43 CET 2011
Bin Jin <bjin1990 <at> gmail.com> writes:
> In order to represent Z/nZ, regular way need to store two integers,
> and a data constructer. With number parameterized types, newtype+Integer
> can be used, it's much more efficient. For this project, montg reduce
> require to calculate a key for each modulus, but the modulus won't be
> changed within Num typeclass. It's better to fix it in type system.
> On Nov 7, 2011 1:38 AM, "DavidA" <polyomino <at> f2s.com> wrote:
> What's the purpose of all the type trickery?
> Why not just implement the algorithm using Integer?
> Haskell-Cafe mailing listHaskell-Cafe <at>
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
Ok, but even if you want to represent the inputs and outputs to be in Z/nZ,
that doesn't mean that you have to work in Z/nZ while performing the algorithm.
I think it would probably be faster to convert from Z/nZ to Integer, do the
algorithm, and then convert the result back to Z/nZ.
Anyway, good luck, and if you succeed in getting it fast enough, I hope you'll
make the results available somewhere.
More information about the Haskell-Cafe