ersatz
ersatz copied to clipboard
updating a relation (want `//` operator)
I want this
updates :: (A.Ix a, A.Ix b)
=> R.Relation a b -> [((a,b),Bit)] -> R.Relation a b
similar to https://hackage.haskell.org/package/array-0.5.8.0/docs/Data-Array.html#v:-47--47-
possible implementation:
updates r ixs = foldl update r ixs
update :: (A.Ix a, A.Ix b)
=> R.Relation a b -> ((a,b),Bit) -> R.Relation a b
update r (i,v) = R.buildFrom
(curry $ \ j -> if j == i then v else r R.! j)
(R.bounds r)