On Fri, 30 Jul 2010, Ben wrote:
dear traversable geniuses --
i am looking for better implementations of
unzipMap :: M.Map a (b, c) - (M.Map a b, M.Map a c)
unzipMap m = (M.map fst m, M.map snd m)
Maybe:
mapPair (M.fromAscList, M.fromAscList) $
unzip $ map (\(a,(b,c)) - ((a,b),
On 31 July 2010 06:45, wren ng thornton w...@freegeek.org wrote:
Ben wrote:
dear traversable geniuses --
i am looking for better implementations of
unzipMap :: M.Map a (b, c) - (M.Map a b, M.Map a c)
unzipMap m = (M.map fst m, M.map snd m)
I don't think you can give a more efficient
On Fri, Jul 30, 2010 at 08:13:43PM -0700, Ben wrote:
dear traversable geniuses --
i am looking for better implementations of
unzipMap :: M.Map a (b, c) - (M.Map a b, M.Map a c)
unzipMap m = (M.map fst m, M.map snd m)
unliftMap :: (Ord a) = M.Map a (b - c) - M.Map a b - M.Map a c
Stephen Tetley wrote:
wren ng thornton wrote:
Ben wrote:
unzipMap :: M.Map a (b, c) - (M.Map a b, M.Map a c)
unzipMap m = (M.map fst m, M.map snd m)
I don't think you can give a more efficient implementation using the public
interface of Data.Map. You need to have a sort of mapping function
On 31/07/10 12:13, wren ng thornton wrote:
Stephen Tetley wrote:
wren ng thornton wrote:
Ben wrote:
unzipMap :: M.Map a (b, c) - (M.Map a b, M.Map a c)
unzipMap m = (M.map fst m, M.map snd m)
I don't think you can give a more efficient implementation using the
public
interface of Data.Map.
On 31 July 2010 12:13, wren ng thornton w...@freegeek.org wrote:
Well, that's one traversal of the original map, but you have to traverse the
new maps repeatedly with all those M.insert calls. And since Data.Map is a
balanced tree, that could lead to a whole lot of work rebalancing things.
On 31/07/10 13:49, Stephen Tetley wrote:
Although I haven't calculated the Big-O scores suspect that original
post will actually be the best, the solutions that metamorph into a
list and out again look like they're doing needless extra work.
They're both O(size m) time, and yes the original is
Claude Heiland-Allen wrote:
On 31/07/10 12:13, wren ng thornton wrote:
Stephen Tetley wrote:
wren ng thornton wrote:
Ben wrote:
unzipMap :: M.Map a (b, c) - (M.Map a b, M.Map a c)
unzipMap m = (M.map fst m, M.map snd m)
I don't think you can give a more efficient implementation using the
wren ng thornton wrote:
That O(n)+O(n) is much better than the O(n)*2*O(log n)
foldrWithKey/insert version. But it's still about the same as the
original 2*O(n) map fst/map snd version. With the primitive I mentioned
we could reduce the constant factor by about half.
Oops, the
dear traversable geniuses --
i am looking for better implementations of
unzipMap :: M.Map a (b, c) - (M.Map a b, M.Map a c)
unzipMap m = (M.map fst m, M.map snd m)
unliftMap :: (Ord a) = M.Map a (b - c) - M.Map a b - M.Map a c
unliftMap mf ma = M.mapWithKey (\k v - mf M.! k $ v) ma
the first
On Fri, Jul 30, 2010 at 08:13:43PM -0700, Ben wrote:
unliftMap :: (Ord a) = M.Map a (b - c) - M.Map a b - M.Map a c
unliftMap mf ma = M.mapWithKey (\k v - mf M.! k $ v) ma
I always thought a useful map primitive would be
unionWithJoin
:: (a - b - c) -- combine values that appear in both
Ben wrote:
unliftMap :: (Ord a) = M.Map a (b - c) - M.Map a b - M.Map a c
unliftMap mf ma = M.mapWithKey (\k v - mf M.! k $ v) ma
the first is obviously inefficient as it traverses the map twice. the
second just seems like it is some kind of fmap.
It's the (*) operator of Applicative, which
Ben wrote:
dear traversable geniuses --
i am looking for better implementations of
unzipMap :: M.Map a (b, c) - (M.Map a b, M.Map a c)
unzipMap m = (M.map fst m, M.map snd m)
I don't think you can give a more efficient implementation using the
public interface of Data.Map. You need to have
13 matches
Mail list logo