RFC: template-haskell & Data.Map vs. Prelude.lookup use

Herbert Valerio Riedel hvriedel at gmail.com
Fri Apr 25 08:16:13 UTC 2014

Hello Richard,

On 2014-04-24 at 15:04:55 +0200, Richard Eisenberg wrote:
> That map seems to store the set of variables during printing TH, for
> the purposes of disambiguating identifiers with the same name but
> different uniques. If blatting out a whole lot of program text, I
> could imagine the Map getting somewhat sizeable.

When does printing TH actually occur? If it doesn't occur during regular
compilation, do we ever need to pretty print large amounts of TH?

> But, it seems to only need the lookup and insert operations... 

actually, it uses a specific combination of lookup+insert, so that it
would suffice to have the single operation in the style of Python's
dict.setdefault(), i.e.

  findWithDefaultInsert :: Ord k => k -> v -> Map k v -> (v, Map k v)
  findWithDefaultInsert k default m
    | Just v <- Map.lookup k m = (v, m)
    | otherwise = default `seq` (default, Map.insert k default m)

> is there a simpler data structure that has only these operations
> efficiently?

More information about the ghc-devs mailing list