Clinton
Clinton

Reputation: 23135

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

Upvotes: 6

Views: 199

Answers (1)

luqui
luqui

Reputation: 60463

Yep. That would be called Dual.

Upvotes: 11

Related Questions