[Haskell-cafe] Layered maps

wren ng thornton wren at freegeek.org
Fri Oct 8 23:18:53 EDT 2010

On 10/8/10 5:46 PM, Thomas DuBuisson wrote:
> Alex,
> The containers library can do this already - there are no constraints
> on the elements of a Map.  For example:
>> type TripleNestedMap a = Map Int (Map Char (Map String a))
> But this is rather silly as you can just do:
>> type MapOfTriples a = Map (Int ,Char, String) a
> for most uses.

However, Map is a lot less efficient than IntMap when dealing with Ints. 
And the IntMap (IntMap ... a) type requires you to write (lookup m <=< 
... <=< lookup n) instead of just one lookup. Unfortunately, when you're 
interested in performance issues, the standard tricks for implementing 
polyvariadic functions aren't very useful.

FWIW, the monadic combinators are usually sufficient to create your own 
functions legiblely (e.g., using (<=<) for lookup), but it's still a lot 
noiser than it could be--- especially if you want a trie instead of a 
product map, since you have to add fst and snd everywhere. I've been 
playing around with some ad-hoc tries like these a lot lately, both for 
HMM tagging and for hunting down performance issues in bytestring-trie.

Live well,

More information about the Haskell-Cafe mailing list