Is there any standard or “most usual” way to represent multidimensional sparse arrays in Haskell (without sacrificing performance too much)?
Something like map< int, map< int, MyClass> > in C++, for example. I’ve Googled and found just some old academic papers and other people asking for this too.
Thanks!
Data.Map (Int,Int) MyClassis an excellent suggestion; try that first.If you run into space problems with that, try
IntMap (IntMap MyClass).IntMaps (in moduleData.IntMap) areMaps withInts as keys; being specialised they are more efficient than generic maps. It might or might not make a significant difference.There is also the Scalable, adaptive persistent container types project which might be of use to you. Those containers (including maps) use significantly less space than normal maps but they are slightly more complicated (although still reasonably easy in use).