Haskell: Is there a more general value / value storage class than MArray?

I'm not sure if I underestimate the power of MArray or not, but for the many algorithms that I implement, all I care about is that I have some kind of data structure for storing key / value pairs. Obviously, choosing a data structure will affect performance, but it would be nice to just write an algorithm and work on optimizing the data structure as needed.

I would really like, for example, the style:

class Monad m => MStore mkv where putAt :: k -> v -> m () getAt :: k -> mv -- and possibly pairs :: m [(k,v)] 

Thus, my algorithm can manipulate things like k without worrying if it is Text , and I need to use a hash table or generalize and skip optimization of the Int key array.

+4
source share
1 answer

To repeat the comments, this is actually not the case. A quick and dirty solution is to define putAt, getAt and pairs locally as aliases for the corresponding functions in your current data structure of choice. Then you can simply switch to the new data structure by overriding the functions (and if you use a type alias for your data structure, then you can use caption signatures without revising them). This is just an abstract data type by convention on the fly. You can switch to a new type to force adt if you want.

Note that the edison library (based on Okasaki's work on functional data structures) is trying to provide a shared container API, but the API is only implemented for the structures provided by edison: http://hackage.haskell.org/package/EdisonAPI

+4
source

All Articles