Search code examples
haskellmonoidssemigroup

Haskell newtype that flips semigroup operation?


Is there any newtype in base that would basically achieve the following?

newtype SemigroupFlip a = SemigroupFlip a

instance Semigroup a => Semigroup (SemigroupFlip a) where
  (SemigroupFlip a) <> (SemigroupFlip b) = SemigroupFlip (b <> a)

instance Monoid a => Monoid (SemigroupFlip a) where
  mempty = SemigroupFlip mempty

Solution

  • Yep. That would be called Dual.