
On 13.12.2012 17:04, Johan Tibell wrote:
Hi,
On Thu, Dec 13, 2012 at 7:49 AM, Ben Gamari
wrote: Christian Maeder
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."
Well, but the default value of findWithDefault is not stored in the map. So why does it have to be evaluated eagerly, even before know you will use it?
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
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
-- Andreas Abel <>< Du bist der geliebte Mensch. Theoretical Computer Science, University of Munich Oettingenstr. 67, D-80538 Munich, GERMANY andreas.abel@ifi.lmu.de http://www2.tcs.ifi.lmu.de/~abel/