[英]In Haskell, how to generate an arbitrary number of mutable variables and put them in a vector?
Lets say I wanted to make 4 mutable arrays then later access them and mutate them based on their index of a vector:假设我想制作 4 个可变的 arrays 然后稍后访问它们并根据它们的向量索引对它们进行变异:
fn = do $
v1 <- newMArray (Sz1 1) 0
v2 <- newMArray (Sz1 1) 0
v3 <- newMArray (Sz1 1) 0
v4 <- newMArray (Sz1 1) 0
let vls = Data.Vector.fromList [v1,v2,v3,v4]
loopM 0 (<= 3) (+1) (\k -> modifyM_ (vls ! k) (+1) 0)
Now how would I generate N number of mutable arrays simply by supplying an integer N as an argument to fn
?现在,我将如何通过将 integer N 作为参数提供给
fn
来生成 N 个可变 arrays ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.