monoid-extras 0.7 → 0.7.0.1
raw patch · 4 files changed
+33/−7 lines, 4 files
Files
- CHANGES +6/−0
- monoid-extras.cabal +1/−1
- src/Data/Monoid/Action.hs +14/−6
- src/Data/Monoid/SemiDirectProduct.hs +12/−0
CHANGES view
@@ -1,3 +1,9 @@+* 0.7.0.1: 29 January 2026++ - Add some cautionary comments to `Regular` and `Semi`. In+ particular, `Regular` cannot be used to create a lawful semidirect+ product of a monoid/semigroup with itself. ([#63](https://github.com/diagrams/monoid-extras/issues/63))+ * 0.7: 12 May 2025 - Updates to `Data.Monoid.Coproduct`:
monoid-extras.cabal view
@@ -1,5 +1,5 @@ name: monoid-extras-version: 0.7+version: 0.7.0.1 synopsis: Various extra monoid-related definitions and utilities description: Various extra monoid-related definitions and utilities, such as monoid actions, monoid coproducts, semi-direct
src/Data/Monoid/Action.hs view
@@ -39,12 +39,16 @@ -- * @act (m1 \`mappend\` m2) = act m1 . act m2@ -- -- Semigroup instances are required to satisfy the second law but with--- ('<>') instead of 'mappend'. Additionally, if the type @s@ has--- any algebraic structure, @act m@ should be a homomorphism. For--- example, if @s@ is also a monoid we should have @act m mempty =--- mempty@ and @act m (s1 \`mappend\` s2) = (act m s1) \`mappend\`--- (act m s2)@.+-- ('<>') instead of 'mappend'. --+-- Additionally, if the type @s@ has any algebraic structure, @act+-- m@ should typically be a homomorphism. For example, if @s@ is+-- also a monoid we should have @act m mempty = mempty@ and @act m+-- (s1 \`mappend\` s2) = (act m s1) \`mappend\` (act m s2)@. In+-- particular, these laws are necessary for the semidirect product+-- @Semi s m@ to be a valid semigroup/monoid. For a more+-- fine-grained treatment of these ideas, see the @lr-acts@ package.+-- -- By default, @act = const id@, so for a type @M@ which should have -- no action on anything, it suffices to write --@@ -123,7 +127,11 @@ -- | Any monoid acts on itself by left multiplication. -- This newtype witnesses this action: -- @'getRegular' $ 'Regular' m1 `'act'` 'Regular' m2 = m1 '<>' m2@-newtype Regular m = Regular { getRegular :: m }+--+-- Note that this typically does NOT satisfy the distributivity law+-- @m `act` (m1 <> m2) = (m `act` m1) <> (m `act` m2)@, and hence+-- cannot be used to form a lawful semidirect product of a monoid with itself.+newtype Regular m = Regular {getRegular :: m} instance Semigroup m => Action m (Regular m) where m1 `act` Regular m2 = Regular $ m1 <> m2
src/Data/Monoid/SemiDirectProduct.hs view
@@ -24,6 +24,18 @@ -- We think of the @m@ values as a "tag" decorating the @s@ values, -- which also affect the way the @s@ values combine. --+-- NOTE: this is only a valid semigroup/monoid if the action of @m@+-- on @s@ satisfies BOTH:+--+-- 1. @act@ is a monoid/semigroup homomorphism from @m@ to @(s ->+-- s)@, that is, @act mempty = id@ and @act (m1 <> m2) = act m1+-- . act m2@+-- 2. @act m@ is a monoid/semigroup homomorphism for any @m@, that is,+-- @act m mempty = mempty@ and @act m (s1 <> s2) = act m s1 <> act m s2@.+--+-- For a more fine-grained treatment of these ideas, see the+-- @lr-acts@ package.+-- -- We call the monoid @m@ the quotient monoid and the monoid @s@ the -- sub-monoid of the semi-direct product. The semi-direct product -- @Semi s m@ is an extension of the monoid @s@ with @m@ being the