How can I specify that two operations commute in a typeclass?

后端 未结 4 2444
旧时难觅i
旧时难觅i 2021-02-20 15:58

I started reading this paper on CRDTs, which is a way of sharing modifiable data concurrently by ensuring that the operations that modify the data are commutative. It seemed to

4条回答
  •  天命终不由人
    2021-02-20 16:23

    As has been stated already, there's no way to enforce this directly in Haskell using the type system. But if merely specifying constraints in comments isn't satisfying enough, as a middle ground you could provide QuickCheck tests for the desired algebraic properties.

    Something along these lines can already be found in the checkers package; you may want to consult it for inspiration.

提交回复
热议问题