作者:张淑男尧珊肇玲 | 来源:互联网 | 2022-11-30 11:14
假设你有
let a = array ((1,1),(2,2)) [((2,1),3),((1,2),2),((1,1),2),((2,2),3)]
现在我希望将最后一个元组中的3乘以一些数字.我怎样才能做到这一点?
1> typetetris..:
如果你想乘以5
它那将是:
accum (*) a [((2,2),5)]
-- ^ ^ ^ ^
-- function to combine values
-- array to read
-- one of the indices to manipulated
-- value to give to f for the associated index
该函数的签名读取
accum :: Ix i => (e -> a -> e) -> Array i e -> [(i, a)] -> Array i e
它的文件说:
accum f采用数组和关联列表,并使用累加函数f将列表中的对累积到数组中.
因此,调用accum f arrayValue listWithPairsOfIndicesAndValues
将调用f
为此索引listWithPairsOfIndicesAndValues
提供旧值和值的每个索引,listWithPairsOfIndicesAndValues
并返回一个新数组,其中包含listWithPairsOfIndicesAndValues
更新中提到的所有位置以及相应调用返回的值f
.