Haskell newtype that flips semigroup operation?
Asked Answered
C

1

6

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
Cienfuegos answered 1/8, 2023 at 8:2 Comment(0)
M
11

Yep. That would be called Dual.

Manasseh answered 1/8, 2023 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.