[Haskell-cafe] Newbie vs. laziness

Jules Bean jules at jellybean.co.uk
Tue Mar 20 09:46:32 EDT 2007

Alex Queiroz wrote:
> quickQuery returns a lazy list of results, and I expected ($!) to make
> it strict. But my program crashes if I use it this way. But, if I add
> a print to the function:

'Making things strict' isn't that simple.

What $! does is force its arguments into WHNF before applying the 
function. WHNF means, roughly, either a lambda or a constructor at the 

In terms of your list (ids) you are forcing it to either (:) or [] at 
the top level (the two list constructors). So you force the 'top layer' 
of the list; you check if it's empty or not.

If you want to force the whole spine of the list (that's the shape but 
not the values) then (length ids) `seq` return () would do that.

However that's a bit clumsy. What kind of error are you seeing when you 
say 'it crashes'?

It looks to me like your program creates a lazily generated list in the 
DB monad which looks superficially like a sensible thing to do.


More information about the Haskell-Cafe mailing list