Feature request: traverse/fold with accumulator

34 views
Skip to first unread message

Jonas H.

unread,
Jan 25, 2014, 4:29:00 PM1/25/14
to haskel...@googlegroups.com
I’d like to make a feature request: Add a version of foldS (maybe even foldP) that adds an accumulator, i.e. allows you to pass some state around.

There seem to be other people missing this feature too:

http://stackoverflow.com/questions/13570354/haskell-repa-how-to-reduce-array-and-return-index
http://stackoverflow.com/questions/13298778/calculate-an-image-histogram-with-repa

From the 2nd thread:

> This is really only a problem because Repa doesn't have what I consider a normal traverse function. Repa's traverse is more of an array construction that happens to provide an indexing function into another array. We want traverse in the form:
>
> newTraverse :: Array r sh e -> a -> (a -> sh -> e -> a) -> a
> but of coarse this is actually just a malformed fold. So lets rename it and reorder the arguments:
>
> foldAllIdxS :: (sh -> a - > e -> a) -> a -> Array r sh e -> a
> which contrasts nicely with the (preexisting) foldAllS operation:
>
> foldAllS :: (a -> a -> a) -> a -> Array r sh a -> a
> Notice how our new fold has two critical characteristics. The result type is not required to match the element type, so we could start with a tuple of Histograms. Second, our version of fold passes the index, which allows you to select which histogram in the tuple to update (if any).

Jonas

Ben Lippmeier

unread,
Feb 11, 2014, 6:23:43 AM2/11/14
to Jonas H., haskel...@googlegroups.com

Sorry for the delayed reply, I've moved jobs and been maxed out for the last couple of weeks.

On 26 Jan 2014, at 8:29 , Jonas H. <jo...@lophus.org> wrote:

> I'd like to make a feature request: Add a version of foldS (maybe even foldP) that adds an accumulator, i.e. allows you to pass some state around.
>
> There seem to be other people missing this feature too:
>
> http://stackoverflow.com/questions/13570354/haskell-repa-how-to-reduce-array-and-return-index
> http://stackoverflow.com/questions/13298778/calculate-an-image-histogram-with-repa

We could generalise the type of foldS and friends, but the fact that the foldP worker has type (a -> a-> a) and not something like (a -> b -> b) is implied by the parallel implementation.

I've made a ticket in the trac. I'll fix this and others in the new release once GHC 7.8 is out properly.

Cheers,
Ben.


Reply all
Reply to author
Forward
0 new messages