What I'd like to be able to do is something like the following:
import Data.IxSet
newtype Key a = Key Integer
deriving (Eq, Ord, Show)
data Keyed a = Keyed { key :: (Key a), value :: a }
deriving (Eq, Ord, Show)
instance Indexable a => Indexable (Keyed a)
where empty = ixSet $ ixFun (\k -> [key k]) : _somehow_reuse_indices_of_a_
The idea is that if some data structure is Indexable, I should be able to index a Keyed wrapping it by the same types (plus an index on Key a).
It should be easy to convert the functions passed to ixFun in the wrapped type's indices to work with Keyed instead of a: just compose with value. But I can't find any way of actually getting at those functions.
I also had a look at the ixset-typed package; the version of Indexable there actually provides a list of indices, rather than an empty IxSet. This would appear to be much more amenable to reusing the indices, but the "list of indices" is a custom type which doesn't export its constructors, so I don't appear to be able to get at them.
Have I missed anything that would support this kind of usage?