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

2007-09-21 Thread SevenThunders
Al Falloon wrote: > > SevenThunders wrote: >> Well it certainly requires some thought here. As I see it, I now have >> two >> reasonable choices. Either I pull all my matrix operations back inside >> the >> IO monad and avoid the matrix action as a matrix variable paradigm (due >> to >> the

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 contrar

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

2007-09-15 Thread SevenThunders
Ronald Guida wrote: > > > > > I could translate your example to the following: > >> let S = A += B in >> do >> s <- S >> (r,c) <- size (return s) >> k <- matindex (return s) > > This should only perform action S one time. > That's a good point actually. If I am caref

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

2007-09-15 Thread SevenThunders
apfelmus wrote: > > SevenThunders wrote: >> 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 >>> matrix

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 c

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. A

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

[Haskell-cafe] Sequencing Operations in a Monad

2007-09-14 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

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 a

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

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 :: Mat

[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 inte