[Haskell-cafe] Laziness leaks

Ronald Guida oddron at gmail.com
Tue Jun 3 17:14:30 EDT 2008

I was looking at the real time queues in [1] and I wanted to see what
would happen if I tried to write one in Haskell.  The easy part was
translating the real time queue from [1], p43 into Haskell.

The hard part is testing to see if the rotations really happen what
they should.  Basically, I decided to use Debug.Trace.trace to see
when rotations were actually occurring.

I pushed the numbers 1 to 10 into the queue, and then I popped the
queue ten times.  What I found is that none of the rotations would
actually take place until the first time I actually tried to /display
the value/ of a popped element.  What I realized is that my test
driver is lazy.  I figured out that I could put a bunch of 'seq'
functions in the test driver to get the rotations to happen.

My demonstration code is in:

This leads to two questions:

1. If I find a laziness leak, is 'seq' the appropriate way to plug it?

2. Is there any way to systematically search for or detect laziness

More information about the Haskell-Cafe mailing list