RFC: Should Data.IntMap.Strict be value-strict in the function arguments or the map itself

Johan Tibell johan.tibell at gmail.com
Thu Oct 27 19:13:56 CEST 2011

On Thu, Oct 27, 2011 at 10:03 AM, Edward Z. Yang <ezyang at mit.edu> wrote:

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

I'm not quite sure if I follow. Here's Data.IntMap.insert:

    insert :: Key -> a -> IntMap a -> IntMap a
    insert k x t = k `seq`
      case t of
        Bin p m l r
          | nomatch k p m -> join k (Tip k x) p t
          | zero k m -> Bin p m (insert k x l) r
          | otherwise -> Bin p m l (insert k x r)
        Tip ky _
          | k==ky -> Tip k x
          | otherwise -> join k (Tip k x) ky t
        Nil -> Tip k x

Without the explicit `seq`

    insert undefined 1 Nil

terminates but with the `seq` it's _|_.

Are you saying it will eventually get force if someone e.g. does a lookup
after the insert?

-- Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20111027/9986b056/attachment.htm>

More information about the Libraries mailing list