RFC: Should Data.IntMap.Strict be value-strict in the function arguments or the map itself
Edward Z. Yang
ezyang at MIT.EDU
Thu Oct 27 19:03:35 CEST 2011
I'd like to remark that the situation with keys is not /quite/ comparable.
Even if we don't need to look at the key for inserting into an empty map,
it will get forced anyway because IntMaps are spine-strict (in particular, they
are strict in their keys.)
Edward
Excerpts from Johan Tibell's message of Thu Oct 27 12:56:10 -0400 2011:
> Hi all,
>
> As discussed in an earlier (accepted) proposal we're adding
> Data.[Int]Map.{Strict,Lazy} APIs to make it easier for users to get the
> desired strictness.
>
> There are two subtly different ways these APIs can be strict:
>
> 1. All the functions are strict in the value argument, or
> 2. The structure is strict in the value field.
>
> The difference shows up in functions like insertWith. For example, given
>
> insertWith (\ old _new -> old + 1) k v someMap
>
> should 'v' be evaluated is the key 'k' is already in the map. (Note that the
> value isn't used in the update function.)
>
> If we go with option 2 it is more difficult for the user to reason about if
> a given value passed to the API is evaluated or not (as in the above
> example). We currently use option 1 for keys i.e.
>
> insert k v someMap
>
> is strict in the key even if the map is empty (which wouldn't require us to
> look at the key).
>
> Thoughts? I'd love to see some design pros/cons of both approaches.
>
> -- Johan
More information about the Libraries
mailing list