Skip to content

Commit

Permalink
Add action instances for Identity, Void, Semigroup.First and Monoid.F…
Browse files Browse the repository at this point in the history
…irst
  • Loading branch information
clintonmead committed Aug 7, 2024
1 parent 8ab92fc commit 1953910
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Data/Monoid/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ module Data.Monoid.Action
, Torsor(..)
) where

import Data.Functor.Identity (Identity(Identity))
import Data.Semigroup
import qualified Data.Semigroup as Semigroup
import Data.Group
import qualified Data.Monoid as Monoid
import Data.Void (Void, absurd)

------------------------------------------------------------
-- Monoid and semigroup actions
Expand Down Expand Up @@ -128,3 +132,17 @@ newtype Conjugate m = Conjugate { getConjugate :: m }

instance Group m => Action m (Conjugate m) where
m1 `act` Conjugate m2 = Conjugate $ m1 <> m2 ~~ m1

instance Action (Semigroup.First a) a where
act (Semigroup.First m) _ = m

instance Action (Monoid.First a) a where
act (Monoid.First m) s = case m of
Nothing -> s
Just m' -> m'

instance Action Void a where
act = absurd

instance Action m s => Action (Identity m) s where
act (Identity m) = act m

0 comments on commit 1953910

Please sign in to comment.