[Haskell-cafe] Possible Improvements

ajb at spamcop.net ajb at spamcop.net
Mon Dec 3 18:23:59 EST 2007


G'day all.

On Mon, 2007-12-03 at 10:48 +0100, Ketil Malde wrote:

>> I find that I often need to add strictness when:
>>
>>  left thumb)  parsing [Char] into something more compact, i.e. almost
>>               all cases.
>>  right thumb) storing data into maps, especially when the values   
>> are produced by
>>               multiple updates - i.e. doing word frequency counts.

Quoting Derek Elkins <derek.a.elkins at gmail.com>:

> Indeed, this generalizes fairly well.  In general when going from a
> "large" structure (especially recursive types or arrays) to a "small"
> one (especially base types or small non-recursive types e.g. a vector
> type) you want strictness.

On the "right thumb" rule, just a quick comment.

In general, it makes sense for the "spine" of data structures to be
lazy but the "content" to be strict, if the structure depends on the
content.  So, for example, in a binary search tree, it would make
sense for the pointers-to-nodes to be lazy but the keys to be strict.

However, if the "content" does _not_ determine the structure (e.g.
lists), then it should not be strict by default.  So, for example, in
a binary search tree, while it makes sense for "keys" to be strict,
it is wrong for "values" to be strict by default.

Expressed as rules of thumb:

1. Data structure "spines" should almost always be lazy.

2. If it's logically a Functor, strictness will break the axioms,
so don't do that.

Cheers,
Andrew Bromage


More information about the Haskell-Cafe mailing list