Search code examples
haskellrepa

Haskell Repa - traversing a 2D array


I am trying to traverse a 2D array i created using repa, so far i have the function that gets called on every element, but i dont understand what fundamental concept exists that wont let me execute expressions inside that function, what i have so far is as follows:

 drawTile ::(DIM2 -> Int) -> DIM2 -> Int
 drawTile f (Z :. i :. j) = do
   <this is where i want to do some IO>

 drawScene :: [GLuint] -> Array U DIM2 Int -> GLFW.Window -> IO()
 drawScene texs map win = do
   x <- computeP $(traverse map id drawTile)::IO (Array UDIM2 Int)
   return ()

You can ignore the stuff about textures and OpenGL, this is going to be a game. i get compile errors when i try and use a function with side effects in the drawTile function. how do i execute some sort of expression (print "hello" for example), where I want? is there some other easier way to apply a function to each element in a repa array?


Solution

  • i did what user alec suggested and returned a list of IO then sequenced them all together using the following function:

    resequence_ :: [IO ()] -> IO ()
    resequence_ = foldr (>>) (return ())
    

    thanks again for the help. for future reference, i was mistakenly passing around IO, and the problem wasnt with repa.