1
votes

It seems that the idea of a dictionary is one that gives rise to many different implementations, understandably. Since this is Haskell, I'll focus on immutable maps/hashes/dicts. I'd like to be able to use a typeclass for a little library I'm working on and allow users to choose their Hash/Map/Dict implementation.

If there isn't a standard typeclass, it seems that providing a typeclass via hackage might be useful, and failing that, one could (as a library/API provider) still find benefit from using the hackage package or one's own typeclass to allow users to choose a given implementation for a Map.

Assuming I haven't missed a typeclass for Dicts, is there anything in particular about immutable dictionaries that would not go well with typeclasses in Haskell?

Update

The more general question Why is Haskell missing "obvious" Typeclasses provides a lot of useful insight that goes a long way towards answering this question, but doesn't offer practical solutions to this particular case.

1
This might be a better use for backpack than typeclasses. - Thomas M. DuBuisson

1 Answers

2
votes

There're some unsolvable problems with having typeclass for the Map-like data structures. Fortunately, Backpack helps. You can see the interface for Map via Backpack here:

I've implemented this solution and a blog post about such interface: