[Haskell-cafe] strange stack overflow with Data.Map

Jean-Philippe Bernardy jeanphilippe.bernardy at gmail.com
Fri Dec 30 03:49:51 EST 2005

On 12/29/05, David Roundy <droundy at abridgegame.org> wrote:
> On the subject of excessive functions, what are the uses of insertWithKey?
> It seems like anything you do with insertWithKey you could just as
> efficiently do with insertWith... it seems pretty trivial to write
> insertWithKey f k x = insertWith (f k) k x

This is the case if the key type has structural equality. Otherwise,
the key passed to the combining function, which comes from the map,
can have a different value. Not that I support this style of coding,
but dropping the withKey functions cannot be done so lightly.

> There may be a use to all the WithKey variants, but I'd much rather have
> strict varients...

It's a change to consider. We might want to deprecate the withKey
variants (and implicitly the non-structural-equalilty types for keys).
The rationale behind this is that the components of the map are
already separated in to Key and Value, so the chosen key have no
reason to carry extra information: it's what the value is for.

How do you people feel about that?


More information about the Libraries mailing list