Re: [Haskell-cafe] mapM for vectors
Don Stewart schrieb: > alexey.skladnoy: >> Hello >> >> I found that there is no monadic map for vector. It's possible to define to >> define such map using conversion to list, but I suppose it's not efficient. >> I >> didn't make any measurements. >> >>> mapM' :: Monad m => (a -> m b) -> V.Vector a -> m (V.Vector b) >>> mapM' f = return . V.fromList <=< mapM f . V.toList >> Any suggestions about implementation of such function? >> Specifically I want to use Random monad. >> > > > There's a tutorial here on usving vectors, > > > http://haskell.org/haskellwiki/Numeric_Haskell:_A_Vector_Tutorial#Random_numbers > > mapM is available via Fusion.Stream.Monadic.mapM But can it be efficient? It must handle cases like m = [] and thus creation of the (V.Vector b) result means a lot of copying, right? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] mapM for vectors
alexey.skladnoy: > Hello > > I found that there is no monadic map for vector. It's possible to define to > define such map using conversion to list, but I suppose it's not efficient. I > didn't make any measurements. > > > mapM' :: Monad m => (a -> m b) -> V.Vector a -> m (V.Vector b) > > mapM' f = return . V.fromList <=< mapM f . V.toList > > Any suggestions about implementation of such function? > Specifically I want to use Random monad. > There's a tutorial here on usving vectors, http://haskell.org/haskellwiki/Numeric_Haskell:_A_Vector_Tutorial#Random_numbers mapM is available via Fusion.Stream.Monadic.mapM -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] mapM for vectors
Hello I found that there is no monadic map for vector. It's possible to define to define such map using conversion to list, but I suppose it's not efficient. I didn't make any measurements. > mapM' :: Monad m => (a -> m b) -> V.Vector a -> m (V.Vector b) > mapM' f = return . V.fromList <=< mapM f . V.toList Any suggestions about implementation of such function? Specifically I want to use Random monad. -- Khudyakov Alexey ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe