haskell reify, was sequencing data structures
Thu, 21 Aug 2003 11:49:56 +0100
> Things that seem important (to me) are:
> - Do you want to observe cycles and or sharing?
> Of course this is very hard to do because of garbage collection.
Only in the sense that holding onto an object pointer to detect a cycle might
cause you to hold onto the object too - causing a space leak. Weak pointers
probably play a useful role in solving this but I didn't explore this.
> In buddha I observe cycles
> but not other forms of sharing. To do this I have to be very careful
> not to cause garbage collection when I'm traversing the heap.
> I don't remember now whether you can observe cycles using the
> Hugs internals interface. I _think_ that it was possible but I don't
Yes, Hugs lets you see sharing.. The CVHAssert module makes use of cycle and
sharing detection in calculating the heap space consumed by an object.
The Hugs interface has:
- raw objects of type 'alpha' (i.e., the Haskell type of the object)
- object pointers of type 'Cell' (would be better called 'Thunk'?) which
provide a layer of indirection to the object. This indirection lets you prod
a thunk pointer ni various ways without evaluating the object it points to.
These pointers support pointer equality tests with short-circuiting of
- Cell classifications - whether it is an Int, Float, application, thunk, etc.
> - Do you want the ability to force thunks or just stop when you see
> them? The incremental approach of the Hugs interface is nice, but I'm
> worried that it will make the detection of cycles harder - that's the
> reason I moved to reify in buddha away from Hugs style. (In buddha I just
> want to print things up to the extent that they are evaluated when reify is
> called, I stop when I see a thunk, cycle, nullary constructor).
Detecting cycles is easy in the Hugs interface.
You can continue observing below an unevaluated thunk if you wish - just print
the name of the supercombinator and keep going (or disassemble the
supercombinator if you wish). Or you can force an unevaluated thunk if that
takes your fancy.