What's the most idiomatic approach to multi-index collections in Haskell? -
What's the most idiomatic approach to multi-index collections in Haskell? -
in c++ , other languages, add-on libraries implement multi-index container, e.g. boost.multiindex. is, collection stores 1 type of value maintains multiple different indices on values. these indices provide different access methods , sorting behaviors, e.g. map, multimap, set, multiset, array, etc. run-time complexity of multi-index container sum of individual indices' complexities.
is there equivalent haskell or people compose own? specifically, idiomatic way implement collection of type t both set-type of index (t instance of ord
) map-type of index (assume key value of type k provided each t, either explicitly or via function t -> k
)?
in trivial case every element has unique key that's available, can utilize map
, extract key element. in less trivial case each value simply has key available, simple solution map k (set t)
. looking element straight involve first extracting key, indexing map
find set of elements share key, looking 1 want.
for part, if can done straightforwardly in above fashion (simple transformation , nesting), makes sense way. however, none of generalizes to, e.g., multiple independent keys or keys may not available, obvious reasons.
beyond that, i'm not aware of widely-used standard implementations. examples exist, illustration ixset happstack seems fit bill. suspect one-size-kinda-fits-most solutions here liable have poor benefit/complexity ratio, people tend roll own suit specific needs.
intuitively, seems problem might work improve not single implementation, rather collection of primitives composed more flexibly data.map
allows, create ad-hoc specialized structures. that's not helpful short-term needs.
haskell
Comments
Post a Comment