Hi!
Scott's solution forces (lookupFM a' x) to head normal form (or is it weak head normal form). This means that the value of type (Maybe v) is evaluated as much that it is known whether it is Nothing, Just _ or _|_ (bottom). This is probably enough to evaluate the path from FiniteMap's tree root to x. However (lookupFM a' x) in head normal form can be still something like this: Just <unevaluated: 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1> So we have to force the value at key 'x' also. My code uses maybe, which may obfuscate things a bit. Here's another version, which should be easier to understand:
let a' = addToFM_C (+) a x 1 in case lookupFM a' x of Nothing -> a' Just v -> v `seq` a'
Ok. I have 2 questions about this: 1. This means seq function evaluates only 'top' of argument, so when I pass, for example, list as argument, it will be evaluated only to [unevaluated, unevaluated, ...]? Am I right? 2. If so, is there method to _completely_ evaluate expression? -- Alexander Kogan Institute of Applied Physics Russian Academy of Sciences