seq as a class method

Simon Marlow simonmar at microsoft.com
Thu Mar 30 09:45:33 EST 2006


Hi Andy,

This is a good question, and something we hit in GHC quite often too.
Our "solution" is to use a mixture of strictness annotations, deepSeq,
smart constructors, and hand-waving optimism that things will be
evaluated soon enough anyway.

Having to occasionally deepSeq the structore to force the thunks has
quite a few problems, as you say.  A better approach might be to
establish a guarantee that the data type isn't leaky; that is, every
field is either strict, or guaranteed to be deepSeq'd at construction by
a smart constructor.  To enforce the smart constructor, you might want
ReadOnlyConstructors (see the Haskell' proposal).

So for things like this:

> 	regs ::  !Array Int RegVal

You either use a strict Array type, or deepSeq the Array when
constructing the record.

To support record update without having to re-deepSeq everything in the
record you would want to provide record updaters as part of the abstract
datatype.

Hope this helps...

Cheers,
	Simon


More information about the Haskell-prime mailing list