packages feed

monoid-extras 0.2.0.0 → 0.2.1.0

raw patch · 4 files changed

+104/−10 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.Monoid.MList: class :>: l a
- Data.Monoid.MList: type ::: a l = (Option a, l)
+ Data.Monoid.Cut: (:||:) :: m -> m -> Cut m
+ Data.Monoid.Cut: Uncut :: m -> Cut m
+ Data.Monoid.Cut: cut :: Monoid m => Cut m
+ Data.Monoid.Cut: data Cut m
+ Data.Monoid.Cut: instance (Semigroup m, Monoid m) => Monoid (Cut m)
+ Data.Monoid.Cut: instance Semigroup m => Semigroup (Cut m)
+ Data.Monoid.Cut: instance Show m => Show (Cut m)
+ Data.Monoid.MList: class (:>:) l a
+ Data.Monoid.MList: type (:::) a l = (Option a, l)
+ Data.Monoid.Split: instance Show m => Show (Split m)

Files

CHANGES view
@@ -1,4 +1,10 @@-* 0.2.0.0+* 0.2.1.0: 28 September 2012++  - Add new module Data.Monoid.Cut+  - Documentation improvements+  - Add Show instance for Split++* 0.2.0.0: 3 September 2012    - Remove instances for actions on pairs and triples, and add some     commentary explaining why adding them was a bad idea in the first
monoid-extras.cabal view
@@ -1,9 +1,9 @@ name:                monoid-extras-version:             0.2.0.0+version:             0.2.1.0 synopsis:            Various extra monoid-related definitions and utilities description:         Various extra monoid-related definitions and utilities,                      such as monoid actions, monoid coproducts, "deletable"-                     monoids, and "split" monoids.+                     monoids, "split" monoids, and "cut" monoids. license:             BSD3 license-file:        LICENSE extra-source-files:  CHANGES@@ -22,6 +22,7 @@   default-language:  Haskell2010   exposed-modules:   Data.Monoid.Action,                      Data.Monoid.Coproduct,+                     Data.Monoid.Cut,                      Data.Monoid.Deletable,                      Data.Monoid.MList,                      Data.Monoid.PosInf,
+ src/Data/Monoid/Cut.hs view
@@ -0,0 +1,71 @@++-----------------------------------------------------------------------------+-- |+-- Module      :  Data.Monoid.Cut+-- Copyright   :  (c) 2012 diagrams-core team (see LICENSE)+-- License     :  BSD-style (see LICENSE)+-- Maintainer  :  diagrams-discuss@googlegroups.com+--+-- The @Cut@ monoid transformer introduces \"cut points\" such that+-- all values between any two cut points are thrown away.  That is,+--+-- > a b c | d e | f g h i | j k  ==  a b c | j k+--+-----------------------------------------------------------------------------++module Data.Monoid.Cut+       ( Cut(..), cut++       ) where++import Data.Semigroup++infix 5 :||:++-- | A value of type @Cut m@ is either a single @m@, or a pair of+--   @m@'s separated by a divider.  The divider represents a \"cut+--   point\".+--+--   @Cut@ is similar to "Data.Monoid.Split", but split keeps only the+--   rightmost divider and accumulates all values, whereas cut always+--   keeps the leftmost and rightmost divider, coalescing them into+--   one and throwing away all the information in between.+--+--   @Split@ uses the asymmetric constructor @:|@, and @Cut@ the+--   symmetric constructor @:||:@, to emphasize the inherent asymmetry+--   of @Split@ and symmetry of @Cut@.  @Split@ keeps only the+--   rightmost split and combines everything on the left; @Cut@ keeps+--   the outermost splits and throws away everything in between.+data Cut m = Uncut m+           | m :||: m+  deriving (Show)++-- | If @m@ is a @Semigroup@, then @Cut m@ is a semigroup which+--   contains @m@ as a sub-semigroup, but also contains elements of+--   the form @m1 :||: m2@.  When elements of @m@ combine with such+--   \"cut\" elements they are combined with the value on the+--   corresponding side of the cut (/e.g./ @(Uncut m1) \<\> (m1' :||:+--   m2) = (m1 \<\> m1') :||: m2@).  When two \"cut\" elements meet, the+--   two inside values are thrown away and only the outside values are+--   kept.+instance Semigroup m => Semigroup (Cut m) where+  (Uncut m1)    <> (Uncut m2)    = Uncut (m1 <> m2)+  (Uncut m1)    <> (m1' :||: m2) = m1 <> m1' :||: m2+  (m1  :||: m2) <> (Uncut m2')   = m1        :||: m2 <> m2'+  (m11 :||: _)  <> (_ :||: m22)  = m11       :||: m22++instance (Semigroup m, Monoid m) => Monoid (Cut m) where+  mempty  = Uncut mempty+  mappend = (<>)++-- | A convenient name for @mempty :||: mempty@, so composing with+-- @cut@ introduces a cut point.  For example, @Uncut a \<\> cut \<\>+-- Uncut b == a :||: b@.+cut :: Monoid m => Cut m+cut = mempty :||: mempty++-- Note that it is impossible for a cut monoid to have an action in+-- general -- the composition operation can throw away information so+-- it is impossible to satisfy the law (act (m1 <> m2) x = act m1 (act+-- m2 x)) in general (although it may be possible for specific types+-- x).
src/Data/Monoid/Split.hs view
@@ -11,12 +11,15 @@ -- -- Sometimes we want to accumulate values from some monoid, but have -- the ability to introduce a \"split\" which separates values on--- either side.  For example, in the diagrams graphics framework this--- is used when accumulating transformations to be applied to--- primitive diagrams: the 'freeze' operation introduces a split,--- since only transformations occurring outside the freeze should be--- applied to attributes.+-- either side.  Only the rightmost split is kept.  For example, --+-- > a b c | d e | f g h == a b c d e | f g h+--+-- In the diagrams graphics framework this is used when accumulating+-- transformations to be applied to primitive diagrams: the 'freeze'+-- operation introduces a split, since only transformations occurring+-- outside the freeze should be applied to attributes.+-- -----------------------------------------------------------------------------  module Data.Monoid.Split@@ -31,9 +34,21 @@ infix 5 :|  -- | A value of type @Split m@ is either a single @m@, or a pair of---   @m@'s separated by a divider.+--   @m@'s separated by a divider.  Single @m@'s combine as usual;+--   single @m@'s combine with split values by combining with the+--   value on the appropriate side; when two split values meet only+--   the rightmost split is kept, with both the values from the left+--   split combining with the left-hand value of the right split.+--+--   "Data.Monoid.Cut" is similar, but uses a different scheme for+--   composition.  @Split@ uses the asymmetric constructor @:|@, and+--   @Cut@ the symmetric constructor @:||:@, to emphasize the inherent+--   asymmetry of @Split@ and symmetry of @Cut@.  @Split@ keeps only+--   the rightmost split and combines everything on the left; @Cut@+--   keeps the outermost splits and throws away everything in between. data Split m = M m              | m :| m+  deriving (Show)  -- | If @m@ is a @Semigroup@, then @Split m@ is a semigroup which --   combines values on either side of a split, keeping only the@@ -48,7 +63,8 @@   mempty  = M mempty   mappend = (<>) --- | A convenient name for @mempty :| mempty@, so @a \<\> split \<\> b == a :| b@.+-- | A convenient name for @mempty :| mempty@, so @M a \<\> split \<\>+--   M b == a :| b@. split :: Monoid m => Split m split = mempty :| mempty