[Haskell] How to make sure that a function is evaluated only once?

Axel Jantsch axel at kth.se
Thu Dec 21 05:22:53 EST 2006


Hello,

I have a function with type

f :: Int -> Int -> Int -> Int -> Int -> NRup -> NRdown

and I want to make sure it is evaluated only once for the same set of
arguments but I observe that it is always evaluated several times.

f is implemented in C and called via the FFI. The C function may or may
not be pure. In principle it is but it is convenient to keep some state
for debugging and monitoring.
Anyway, even if it is pure, I want it to evaluate only once for a set of
arguments because of performance.

How can I enforce this? 
Is there a GHC option for that?
Is there a way to write the Haskell code to achieve this?


I have asked the same question in the context of FFI, but now it seems to
me this question is not directly related to the FFI.


Any hints?
Thanks, Axel


-- 
Phone: +46 8 790 4124, Email: axel at kth.se, Web: www.it.kth.se/~axel

-- 

---
Phone: +46 8 790 4124, Email: axel at imit.kth.se, Web: www.imit.kth.se/~axel


More information about the Haskell mailing list