Efficient way to change a single value in a repa array

I am trying to use Gloss.Raster.Arrayto effectively build a set of points on the screen. It uses Array D DIM2 Colorpoints as a container for plotting. This is currently a 500x500 array representing a bitmap.

Suppose each frame generates 1 new point to display.

I did not find another way to configure the existing repa array to contain only one new point, rather than making repa traverse, which looks something like this:

{-# INLINE traverseFn #-}
traverseFn px py = (\lookupfn i@(Z :. x :. y) -> 
    if x == px && y == py then red else lookupfn i)

newarr px py = R.traverse oldarr id (traverseFn px py)

I suspected that this could be quite inefficient: moving the entire 500x500 array for one point. But I thought that maybe ghc will do some optimization magic, and it won’t.

It turns out that it is. I tried a profile and it says it newarrtakes 97.2% of the time. And it works very slowly.

I am new to the whole haskell and repa ecosystem, taking the first steps, so I probably don’t know something or something is wrong (in my repo code or in my profiling attempts), so I ask for help :)

Is there any efficient way to change one value in the repa array on each frame? Or, if I want to add 500 points per frame - what will be the answer then?

+4
source share