Data.IntMap.Strict.findWithDefault is too strict

Christian Maeder Christian.Maeder at
Thu Dec 13 14:35:43 CET 2012


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.!

Evaluating (error "...") surely crashes, but the evaluation should only
happen when the key is not in the map!

I can easily work around this (by using fromMaybe and IntMap.lookup), 
but it is still worth at least being documented if crucial for performance.

(the same applies to Data.Map)

Cheers Christian

More information about the Libraries mailing list