21 Aug 2012 15:19

## Pure and monadic functions using the Repa arrays

I have been playing with the Repa functions and trying the Repa-examples. In order to gain experience with the Repa functions I have written some small linear algebra utilities and import this module to a bigger project. In the beginning of my project I used the mmultP function from the repa-examples to calculate a big matrix, therefore I have and array of type:

arr :: Monad m => m (Array U DIM2 Double)

Then I carried this array in a lot of functions which become Monadic function and then it is necessary to introduce the monadic machinery for manipulating this functions . The Question is then if there is the possibility to work with a pure function in place of the monadic version?

There is something like a runRepa function?

runRepa :: Monad m => m (Array U DIM2 Double) - > Array U DIM2 Double

or could I used the unsafePerformIO function ?

or the evaluation of the parallel arrays must be postponed until the Repa.Array is called in the main function?

Felipe.

```_______________________________________________
```
21 Aug 2012 16:53

### Re: Pure and monadic functions using the Repa arrays

```On 08/21/12 09:19, felipe zapata wrote:
>
> I have been playing with the Repa functions and trying the
> Repa-examples. In order to gain experience with the Repa functions I
> have written some small linear algebra utilities and import this module
> to a bigger project. In the beginning of my project I used the mmultP
> function from the repa-examples to calculate a big matrix, therefore I
> have and array of type:
>
>
> arr :: Monad m => m (Array U DIM2 Double)
>
>
> Then I carried this array in a lot of functions which become Monadic
> function and then it is necessary to introduce the monadic machinery for
> manipulating this functions . The Question is then if there is the
> possibility to work with a pure function in place of the monadic version?
>
> There is something like a runRepa function?
>
> runRepa :: Monad m => m (Array U DIM2 Double) - > Array U DIM2 Double
>
>
> or could I used the unsafePerformIO function ?
>
>
> or the evaluation of the parallel arrays must be postponed until the
> Repa.Array is called in the main function?

When this change was introduced (there wasn't always the arbitrary monad
m around everything), I remember I just wrapped my one big repa function
in the identity monad and it worked fine. For example,

-- Grid.hs
...
zoom :: Values3D -> ScaleFactor -> Identity Values3D

-- Main.hs