Proposal: containers: add indexing operations for Set
Milan Straka
fox at ucw.cz
Wed Jul 4 20:31:16 CEST 2012
> > I'd like to add the following indexing operations for
> > Data.Set.Set, to complement the existing functions for
> > Data.Map.Map:
> >
> > findIndex :: Ord a => a -> Set a -> Int
> > lookupIndex :: Ord a => a -> Set a -> Maybe Int
> > elemAt :: Int -> Set a -> a
> > deleteAt :: Int -> Set a -> Set a
>
> These seem to be abstraction-breaking.
There is a natural bijection between the elements of an ordered set and
their indexes in this ordering, and the new API works with the elements
using the indexes instead of the elements themselves. I believe the set
abstraction is not compromised by that.
> And what do we expect from
>
> let i = findIndex a s1
> in deleteAt i (s1 `union` s2)
It removes the i-th least element of (s1 `union` s2). Which element is
that is hard to say, depending on s1 and s2.
Cheers,
Milan
More information about the Libraries
mailing list