Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action instances for Identity, Void, Semigroup.First and Monoid.First #56

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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