【发布时间】:2015-03-07 11:47:37
【问题描述】:
我想在 Data.Vector 上使用累加器制作地图。
我想写函数inc:
inc :: Vector.Vector Bool -> Vector.Vector Bool
向向量“加一”,例如:
inc <False, False, False> = <False, False, True>
inc <False, False, True> = <False, True, False>
inc <True, True, True> = <False, False, False>
如果有像 Data.List 的 mapAccumR 这样的东西,用 type 说:
mapAccumR :: (acc -> x -> (acc, y)) -> acc -> Vector x -> (acc, Vector y)
这可以用
inc = snd . Vector.mapAccumR inc' True
where
inc' x y = (x && y, (x || y) && (not (x && y)))
但我不知道如何处理 Data.Vector.Unboxed 中的内容。有可能吗?
【问题讨论】:
标签: haskell