ersatz icon indicating copy to clipboard operation
ersatz copied to clipboard

updating a relation (want `//` operator)

Open jwaldmann opened this issue 1 year ago • 0 comments

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) 

jwaldmann avatar Oct 23 '24 22:10 jwaldmann