
Joel Reymont wrote:
foo [] = return () foo (x:xs) = do let fps = P.packWords x installFinalizer fps putStrLn $ "fps: " ++ show fps unsafeFinalize fps <---- ??? foo xs
Is it even possible for the compiler to finalize and gc `fps' at the marked line? Without the unsafeFinalize, `fps' is still in scope and might be used after `foo xs' returns. Is GHC supposed to see that `fps' is no longer in use? Does the following code work better?
foo (x:xs) = do do let fps = P.packWords x installFinalizer fps putStrLn $ "fps: " ++ show fps foo xs
BTW, Joel, it seems, your code is creating lots of very short FastPackedStrings. That's useless, a list of Word8s could replace a list of short FastPackedStrings at essentially no additional cost. But it would simplify the code a lot, overcome any problems with finalizers in passing, and probably enable weird and wonderful optimizations by GHC. Only long FastPackedStrings will be fast, and only if you're not growing them in pieces, and if you're storing them for an extended time, and if you're consuming them more than once. It looks as if you're using them four times wrong. Udo. -- The most happy marriage I can imagine to myself would be the union of a deaf man to a blind woman. -- Samuel Taylor Coleridge