now. I am pretty sure I can do the demand loading bit with some goddawful code (inspired by HOODs internals) using unsafePerformIO and Weak pointers in truly nefarious ways. The dumping to the database bit is straightforward when working with trees. but I can't figure out a way to do it for potentially complex datastructures. perhaps someone out there has an idea? perhaps some template haskell tricks can be pulled to make it happen? I realize that any solution will be quite hacky and unlikely to be very portable.
You probably want to use unsafePtrEq, and possibly something to give you a hash of a pointer... or maybe you want to look at Koen Claessen's "observable sharing" work that he developed for Lava. http://www.math.chalmers.se/~koen/Papers/obs-shar.ps --KW 8-)