[Haskell-cafe] Re: A typeclass for Data.Map etc?

Alexander Dunlap alexander.dunlap at gmail.com
Sat Feb 21 01:10:26 EST 2009

On Fri, Feb 20, 2009 at 6:40 AM, Achim Schneider <barsoap at web.de> wrote:
> wren ng thornton <wren at freegeek.org> wrote:
>> (b) allows
>> instances to have a fixed type for keys (like Data.Trie and
>> Data.IntMap have),
> Can't we do some type magic to automagically select Data.Trie if the
> key is a (strict) bytestring?

I believe this is a key feature of Associated Types: you can create
"self-optimizing libraries" that select a different container
structure depending on the type.

For example,

class XMapK k where
  type XMap k :: * -> *
  insert :: k -> XMap k v -> XMap k v

and then

instance XMapK Int where
  type XMap Int = Data.IntMap.IntMap
  insert = Data.IntMap.insert



More information about the Haskell-Cafe mailing list