[Haskell-cafe] Pure and monadic functions using the Repa arrays
Michael Orlitzky
michael at orlitzky.com
Tue Aug 21 16:53:22 CEST 2012
On 08/21/12 09:19, felipe zapata wrote:
> Hi Haskellers,
>
> 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
import Control.Monad.Identity (Identity)
...
zoom :: Values3D -> ScaleFactor -> Identity Values3D
-- Main.hs
import Control.Monad.Identity (runIdentity)
...
let output = runIdentity $ zoom dbl_data zoom_factor
This gives you the warm/fuzzy of knowing that the function is pure, but
I think I eventually just let it run in IO to avoid introducing mtl as a
dependency.
More information about the Haskell-Cafe
mailing list