我看到我可以使用 mapArray 在可变数组上映射一个函数,但似乎没有像 mapM(和 mapM_)这样的东西。mapArray 不会让我打印它的元素,例如:
import Data.Array.Storable
arr <- newArray (1,10) 42 :: IO -- answer to Life, Universe and Everything
x <- readLn :: IO Int
mapArray (putStrLn.show) arr -- <== this doesn't work!
结果将是:
No instances for (MArray StorableArray Int m,
MArray StorableArray (IO ()) m)
arising from a use of `mapArray' at <interactive>:1:0-27
Possible fix:
add an instance declaration for
(MArray StorableArray Int m, MArray StorableArray (IO ()) m)
In the expression: mapArray (putStrLn . show) arr
In the definition of `it': it = mapArray (putStrLn . show) arr
Haskell 中是否有类似的东西(或者在 GHC 中,即使不是标准的 Haskell)?
此外,我发现没有用于数组的 foldr/foldl 函数(可变与否)。它们存在吗?
非常感谢!