Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-17 Thread SevenThunders
Paul Johnson-2 wrote: SevenThunders wrote: Unfortunately if I wrap my matrix references in the IO monad, then at best computations like S = A + B are themselves IO computations and thus whenever they are 'invoked' the computation ends up getting performed repeatedly contrary to my

[Haskell-cafe] Sequencing Operations in a Monad

2007-09-15 Thread Dominic Steinitz
If you arrange the types to try to do all the operations inside the IO monad you can't chain together more than 1 binary operation. eg. do S - A + B Z - Q * S vs do S - Q * (A + B) Are there any suggestions for this dilemma? Am I using the wrong monad for this task?

Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-15 Thread SevenThunders
Dominic Steinitz wrote: If you arrange the types to try to do all the operations inside the IO monad you can't chain together more than 1 binary operation. eg. do S - A + B Z - Q * S vs do S - Q * (A + B) Are there any suggestions for this dilemma? Am I using

Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-15 Thread Ronald Guida
SevenThunders wrote: OK so check out what really happens with liftM2. Suppose I have an IO containing an involved matrix computation called s. For simplicity we might assume that s :: IO (Int) and the Int is an index into an array containing a bunch of matrices in C land. Assume

Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-15 Thread Paul Johnson
SevenThunders wrote: Unfortunately if I wrap my matrix references in the IO monad, then at best computations like S = A + B are themselves IO computations and thus whenever they are 'invoked' the computation ends up getting performed repeatedly contrary to my intentions. This sounds like a

[Haskell-cafe] Sequencing Operations in a Monad

2007-09-14 Thread SevenThunders
I have a matrix library written in C and interfaced into Haskell with a lot of additional Haskell support. The C library of course has a lot of side effects and actually ties into the BLAS libraries, thus at the present time, most of the interesting calls are done in the IO monad. I have no

Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-14 Thread Ryan Ingram
As long as the FFI calls don't make destructive updates to existing matrices, you can do what you want. For example, assuming you have: -- adds the second matrix to the first overwrites the first matrixAddIO :: MatrixIO - MatrixIO - IO () -- creates a new copy of a matrix matrixCopyIO ::

Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-14 Thread SevenThunders
Ryan Ingram wrote: As long as the FFI calls don't make destructive updates to existing matrices, you can do what you want. For example, assuming you have: -- adds the second matrix to the first overwrites the first matrixAddIO :: MatrixIO - MatrixIO - IO () -- creates a new copy

Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-14 Thread Ronald Guida
SevenThunders wrote: I have a matrix library written in C and interfaced into Haskell with a lot of additional Haskell support. [snip] Unfortunately if I wrap my matrix references in the IO monad, then at best computations like S = A + B are themselves IO computations and thus whenever they