Haskell compile time function calculation

Posted by egon on Stack Overflow See other posts from Stack Overflow or by egon
Published on 2010-03-19T08:17:55Z Indexed on 2010/03/19 8:21 UTC
Read the original article Hit count: 337

Filed under:
|

I would like to precalculate values for a function at compile-time.

Example (real function is more complex, didn't try compiling):

base = 10
mymodulus n = n `mod` base -- or substitute with a function that takes
                            -- too much to compute at runtime
printmodules 0 = [mymodulus 0]
printmodules z = (mymodulus z):(printmodules (z-1))

main = printmodules 64

I know that mymodulus n will be called only with n < 64 and I would like to precalculate mymodulus for n values of 0..64 at compile time. The reason is that mymodulus would be really expensive and will be reused multiple times.

© Stack Overflow or respective owner

Related posts about haskell

Related posts about compile-time