Good work, Alberto. hmatrix looks like a good solution answer to some of the nested arrays questions we have in Haskell
aruiz: > Hello Bulat and Anatoly, > > I have written a first version of an interface to inplace updates in the > ST monad for the hmatrix vectors and matrices. Many things must be > improved (range checking, documentation, etc.) but I hope that the > general idea makes sense. > > A few usage examples: > > http://perception.inf.um.es/~aruiz/darcs/hmatrix/examples/inplace.hs > > Code: > > http://perception.inf.um.es/~aruiz/darcs/hmatrix/lib/Data/Packed/ST.hs > > http://perception.inf.um.es/~aruiz/darcs/hmatrix/doc/html/Data-Packed-ST.html > > Any suggestion will be welcome. I'm impressed by the power of the ST > monad, it is extremely useful and elegant. Thank you again for your help! > > In the future I will also try to include efficient conversions to/from > standard Haskell arrays and those of other related libraries like Jed > Brown's CArray. > > Thanks, > > Alberto > > > Bulat Ziganshin wrote: > >Hello Alberto, > > > >Tuesday, June 3, 2008, 12:56:50 PM, you wrote: > > > >>Good! So you can easily "hide" the IO operations in the ST monad. I will > >>definitely look into it. > > > >from implementation POV ST monad is nothing but renamed IO monad which > >exports only subset of its operations which are guaranteed to safe. > >or, saying in other words, it's just type hackery around IO monad that > >provides safe operations > > > >it's possible to define ST monad and its operations as following: > > > >newtype ST s a = forall s. ST_Constructor (IO a) > > > >unsafeIOtoSt action = ST_Constructor action > > > >runST (ST_Constructor action) = unsafePerformIO action > > > >newtype STRef s a = forall s. STRef (IORef a) > > > >readSTRef (STRef ref) = unsafeIOtoSt (readIORef ref) > > > >and so on. GHC uses technically (but not ideologically!) different > >implementation where both monads are specializations of one generic > >type. while Hugs afair uses exactly this approach. you may also look > >at ArrayRef lib which reimplements arrays/refs for both compilers in > >more unified way > > > >anyway, because ST is just IO monad modulo type tricks, you can > >execute any IO action inside ST by lifting it with unsafeIOtoSt > > > _______________________________________________ > Haskell-Cafe mailing list > [email protected] > http://www.haskell.org/mailman/listinfo/haskell-cafe _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
