ekmett / ersatz

A monad for interfacing with external SAT solvers
Other
63 stars 15 forks source link

updating a relation (want `//` operator) #98

Open jwaldmann opened 1 month ago

jwaldmann commented 1 month ago

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)