mapping unfreeze over an IntMap of IOUArrays

Hello cafe, I've hit a bit of a monadic snag here... I'm scanning a big file, building a table of statistics. I end up with something like IO (IntMap (IOUArray Int Double)) Once I've read in the whole file and built my statistics, I don't need any more updates, so I'd like to do something like IntMap (IOUArray Int Double) -> IO (IntMap (UArray Int Double)), using unsafeFreeze. I'm getting stuck here, since the IntMap library is not so monad-friendly. I could rebuild the whole thing using sequence and lists, but the table is pretty big (4.5 million keys on a first run), so I'd prefer to avoid that. Any ideas? BTW, I probably "should" be using ST for this, but I hit the usual "type s escapes" irritation and gave up. If that would work more easily, that would be fine with me too. Thanks! Chad Scherrer

chad.scherrer:
Hello cafe,
I've hit a bit of a monadic snag here...
I'm scanning a big file, building a table of statistics. I end up with something like
IO (IntMap (IOUArray Int Double))
Once I've read in the whole file and built my statistics, I don't need any more updates, so I'd like to do something like
IntMap (IOUArray Int Double) -> IO (IntMap (UArray Int Double)),
using unsafeFreeze. I'm getting stuck here, since the IntMap library is not so monad-friendly.
Hmm. So you'd need to construct a new IntMap, made by fmap'ping unsafeFreeze over each element of the old map. -- Don

On Tue, Nov 11, 2008 at 07:39:53PM +0000, Chad Scherrer wrote:
Don Stewart
writes: Hmm. So you'd need to construct a new IntMap, made by fmap'ping unsafeFreeze over each element of the old map.
I guess if we had a Traversable instance for Data.IntMap things would be just fine. Would this be a bad thing in any way?
I don't think so. It's a straightforward instance, and its omission was an oversight.

Bulat wrote:
Hello Chad,
Tuesday, November 11, 2008, 10:23:09 PM, you wrote:
using unsafeFreeze. I'm getting stuck here, since the IntMap library is not so monad-friendly.
Data.Hashtable is
Well, I need mutable update for a while... after that, I prefer a pure interface, which is why I'm trying to freeze all the values. Anyway, I haven't used hashtables in Haskell, but I vaguely remember some discussion about them being really slow. Is this no longer the case? I guess if I really need to go this route I could try out HsJudy or something. Thanks, Chad
participants (5)
-
Bulat Ziganshin
-
Chad Scherrer
-
Don Stewart
-
Ross Paterson
-
Scherrer, Chad