[Haskell-cafe] Histogram creation

Ketil Malde ketil at malde.org
Tue Nov 11 03:30:17 EST 2008


Duncan Coutts <duncan.coutts at worc.ox.ac.uk> writes:

> Perhaps I misunderstood but I think Alexey means that he wants to
> accumulate several different histograms (ie different arrays) but to
> only make one pass over the input data. 

This is precicely my problem, too.

> The form of accumArray does not make that possible (unless one
> managed to pack the different histograms into different parts of the
> same array). 

This would have been a good match for my case.

Of course, that is a bit of a hack, and it would be much nicer and
safer to do an accumArray with tuple elements.  But I need to use an
UArray in order to avoid the array filling up with unevaluated thunks,
and - correct me if I'm wrong - there's no way to do a 'seq' before
accumArray's insertion for complex types.  So the stack blows up.

/me wishes for s/Data.Array.Unboxed/Data.Array.Strict/g and instances
for arbitrary types.

Anyway, I thought of using offsets in the same UArray too late, and
chose to finish my ST-based implementation instead. 

> If a fold using a pure persistent map type really is too slow then it
> should still be possible to do an ST implementation in a reasonably
> elegant way using a foldr on the input list, accumulating an ST action. 

Or must mapM_ an insert operation (in ST) over the input data?

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants


More information about the Haskell-Cafe mailing list