3 ms·
pflags = protRead <> protWrite mflags = mapAnon .|. mapPrivate What's the difference between these two operators?
by gue5t 9y ago
pflags = protRead <> protWrite
mflags = mapAnon .|. mapPrivate
What's the difference between these two operators?
- evincarofautumn 9y agoThere’s no difference in this case—looks like an oversight. “<>” is the Monoid “append” operator (e.g., concat lists, union sets, compose functions). If you look in JIT.hs[1], you’ll see that there’s an instance of Monoid that just calls “.|.” (bitwise OR): instance Monoid ProtOption where mempty = protNone mappend (ProtOption a) (ProtOption b) = ProtOption (a .|. b) [1]: https://github.com/sdiehl/tinyjit/blob/master/src/JIT.hs https://github.com/sdiehl/tinyjit/blob/master/src/JIT.hs
- mrkgnao 9y agoThere is no canonical monoidal operation on booleans (just as the case is in any arbitrary ring), so I'd guess using the bitwise operators explicitly is good for disambiguation.
- evincarofautumn 9y agoYes and no—in practice in Haskell we tend to choose the most convenient instance and wrap things in newtypes to get at other instances. Writing code using generic operations (Monoid, Functor, Foldable) makes it easier to refactor datatypes later—coding to the interface and not the implementation, and all that. The bitwise OR operation makes sense for ProtOption because it’s basically a set.
- mrkgnao 9y agoThat's true, for bitflag-like things OR does make sense.