I actually made my own copy of Data.Map and added an extra:
alterLookúp :: Ord k = (Maybe a - (b,Maybe a)) - k - Map k a - (b,Map k a)
function. I also changed my data type to:
type ParseChart k v = Map k (Map v ())
so I don't have to copy the Data.Set module also. Unfortunately this
doesn't
Krasimir Angelov wrote:
but notice that the set is still traversed twice.
Neil Mitchell wrote:
I don't see any way of reducing that
Yeah, it looks like the Data.Set (and Data.IntSet) library
is missing the functions
insertMember :: Ord a = a - Set a - (Bool, Set a)
deleteMember :: Ord a = a -
Hello Krasimir,
Krasimir Angelov wrote:
Hi,
I have to write ParseChart implementation with Data.Map/Set. The chart
is type like this:
type Chart k v = Map k (Set v)
now I need operation like:
insert :: k - v - Chart k v - Maybe (Chart k v)
where the result is (Just _) if the (k,v) is
Duncan Coutts wrote:
modify :: k - Map k e - (e, Maybe e - Map k e)
so it's a lookup that returns the element at k and also a continuation
that lets you rebuild a new map with an altered element. I guess that
doesn't account for the element not existing. There's probably a
generalisation that
Hi,
I have to write ParseChart implementation with Data.Map/Set. The chart
is type like this:
type Chart k v = Map k (Set v)
now I need operation like:
insert :: k - v - Chart k v - Maybe (Chart k v)
where the result is (Just _) if the (k,v) is actually added to the
chart or Nothing if it was
Hi Krasimir,
insert :: k - v - Chart k v - Maybe (Chart k v)
where the result is (Just _) if the (k,v) is actually added to the
chart or Nothing if it was already there and nothing have to be done.
insertLookupWithKey :: Ord k = (k - a - a - a) - k - a - Map k
a - (Maybe a, Map k a)
This
On Mon, 2008-06-02 at 22:35 +0200, Krasimir Angelov wrote:
The problem with this is that both the Map and the Set are traversed
twice. The first time from lookup/member and the second time from
insert. Does someone have an idea how to do this with the current
libraries?
The chart
Not completely! This is a possible implementation:
case insertLookupWithKey (\_ - Set.union) k (Set.singleton v) chart of
(Nothing, chart) - Just chart
(Just set, chart) | Set.member v set - Nothing
| otherwise - Just chart
but notice that the set is
Hi
case insertLookupWithKey (\_ - Set.union) k (Set.singleton v) chart of
(Nothing, chart) - Just chart
(Just set, chart) | Set.member v set - Nothing
| otherwise - Just chart
but notice that the set is still traversed twice.
Yes, I missed that bit. I