Data.IntMap.Strict.findWithDefault is too strict
Johan Tibell
johan.tibell at gmail.com
Thu Dec 13 17:04:09 CET 2012
Hi,
On Thu, Dec 13, 2012 at 7:49 AM, Ben Gamari <bgamari.foss at gmail.com> wrote:
> Christian Maeder <Christian.Maeder at dfki.de> writes:
>> when trying out Data.IntMap.Strict instead of Data.IntMap, I've noticed
>> (after some confusion) that Data.IntMap.Strict.findWithDefault evaluates
>> the default value, even if it is not used!
>>
>> I usually pass an error-call to IntMap.findWithDefault to get a more
>> informative crash-message than by using IntMap.!
>>
> I have also found this to be problematic in the past. Is there a
> compelling reason to keep the current behavior? I would find this
> function far more useful if the default value were lazily evaluated.
The behavior is at least documented. From Data.IntMap.Strict:
"This module satisfies the following strictness properties:
Key and value arguments are evaluated to WHNF;
Keys and values are evaluated to WHNF before they are stored in the map."
We agonized over this choice when we made it. The reasoning for the
current behavior is that these strictness properties help you reason
about whether values passed to the API are evaluated or not, as that
no longer depend on the contents of them map. We're not really looking
to support passing undefined values in the API.
-- Johan
More information about the Libraries
mailing list