Data.HashMap: Strict or lazy by default?
johan.tibell at gmail.com
Fri Feb 18 01:51:28 CET 2011
I'm about to release my new unordered-containers library, which
includes a Data.HashMap module. I have one remaining design issue I'd
like to get some feedback on. Here are the constraints:
* There are a number of functions that need both lazy and strict
versions. Example: insertWith
* There are a number of functions that don't need a strict version,
but where having a strict version would help avoid space leaks and
support the common strict use case. Example: insert
* A particular use case for a map rarely uses both the lazy and
strict versions (suggesting a module split).
* Keeping both the strict and lazy versions in the same module makes
the module very large and users typically want to see only half of the
functions in there (the ones that fit their current use case).
My current thinking is to provide lazy and strict versions in
different modules. The two modules could still share the same data
type. The question is, what should be the default? Haskell is a lazy
language but the most common use cases for maps are strict (e.g. a map
from strings to integer counters).
I intend to to use one of three possible module layouts:
Data.HashMap (re-export one of the two modules below)
I'd like to see some arguments for and against each of the two
possible defaults (lazy or strict). Also, real life examples of cases
where lazy maps are useful would be appreciated.
More information about the Libraries