
On Tue, Nov 02, 2004 at 11:53:52AM +0300, Alexander Kogan wrote:
Where should I add `seq` to make FiniteMap strict? I tried merge' a x = let r = addToFM_C (+) a x 1 in r `seq` r but it doesn't help.
== an anecdote A quick note, x `seq` x is always exactly equivalant to x. the reason being that your seq would never be called to force x unless x was needed anyway. I only mention it because for some reason this realization did not hit me for a long time and once it did a zen-like understanding of seq (relative to the random placement and guessing method I had used previously) suddenly was bestowed upon me. == an opinion I find the most useful seq idioms are to force an argument to a function to be evaluated like f $! x this ensures that f is always passed an evaluated argument. or to do it from the other side, (inside the function) f x y | x `seq` False = undefined f x y = .... that first line ensures that f is strict in its first argument and can easily be added after the fact if you see a function is not strict enough. John -- John Meacham - ⑆repetae.net⑆john⑈