packages feed

semigroups 0.8 → 0.8.0.1

raw patch · 2 files changed

+46/−46 lines, 2 files

Files

Data/Semigroup.hs view
@@ -8,22 +8,22 @@ -- Stability   :  provisional -- Portability :  portable ----- In mathematics, a semigroup is an algebraic structure consisting of a --- set together with an associative binary operation. A semigroup --- generalizes a monoid in that there might not exist an identity --- element. It also (originally) generalized a group (a monoid with all --- inverses) to a type where every element did not have to have an inverse, +-- In mathematics, a semigroup is an algebraic structure consisting of a+-- set together with an associative binary operation. A semigroup+-- generalizes a monoid in that there might not exist an identity+-- element. It also (originally) generalized a group (a monoid with all+-- inverses) to a type where every element did not have to have an inverse, -- thus the name semigroup. ----- The use of (<>) in this module conflicts with an operator with the same--- name that is being exported by Data.Monoid. However, this package +-- The use of @(\<\>)@ in this module conflicts with an operator with the same+-- name that is being exported by Data.Monoid. However, this package -- re-exports (most of) the contents of Data.Monoid, so to use semigroups -- and monoids in the same package just -- -- > import Data.Semigroup -- -----------------------------------------------------------------------------module Data.Semigroup ( +module Data.Semigroup (     Semigroup(..)   -- * Semigroups   , Min(..)@@ -31,7 +31,7 @@   , First(..)   , Last(..)   , WrappedMonoid(..)-  -- * Re-exported monoids from Data.Monoid +  -- * Re-exported monoids from Data.Monoid   , Monoid(..)   , Dual(..)   , Endo(..)@@ -68,18 +68,18 @@ import Data.Data #endif -infixr 6 <> +infixr 6 <>  class Semigroup a where-  -- | An associative operation. -  -- +  -- | An associative operation.+  --   -- > (a <> b) <> c = a <> (b <> c)   (<>) :: a -> a -> a    -- | Reduce a non-empty list with @\<\>@   --   -- The default definition should be sufficient, but this can be overridden for efficiency.-  -- +  --   sconcat :: NonEmpty a -> a   sconcat (a :| as) = go a as where     go b (c:cs) = b <> go c cs@@ -88,10 +88,10 @@   -- | Repeat a value (n + 1) times.   --   -- > times1p n a = a <> a <> ... <> a  -- using <> n times-  -- +  --   -- The default definition uses peasant multiplication, exploiting associativity to only   -- require /O(log n)/ uses of @\<\>@.-  +   times1p :: Whole n => n -> a -> a   times1p y0 x0 = f x0 (1 Prelude.+ y0)     where@@ -134,7 +134,7 @@ instance (Semigroup a, Semigroup b) => Semigroup (a, b) where   (a,b) <> (a',b') = (a<>a',b<>b')   times1p n (a,b) = (times1p n a, times1p n b)-  + instance (Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) where   (a,b,c) <> (a',b',c') = (a<>a',b<>b',c<>c')   times1p n (a,b,c) = (times1p n a, times1p n b, times1p n c)@@ -152,15 +152,15 @@   times1p n (Dual a) = Dual (times1p n a)  instance Semigroup (Endo a) where-  Endo f <> Endo g = Endo (f . g) +  Endo f <> Endo g = Endo (f . g)  instance Semigroup All where   All a <> All b = All (a && b)-  times1p _ a = a +  times1p _ a = a  instance Semigroup Any where   Any a <> Any b = Any (a || b)-  times1p _ a = a +  times1p _ a = a  instance Num a => Semigroup (Sum a) where   Sum a <> Sum b = Sum (a + b)@@ -171,17 +171,17 @@ instance Semigroup (Monoid.First a) where   Monoid.First Nothing <> b = b   a                    <> _ = a-  times1p _ a = a +  times1p _ a = a  instance Semigroup (Monoid.Last a) where   a <> Monoid.Last Nothing = a   _ <> b                   = b-  times1p _ a = a +  times1p _ a = a  instance Semigroup (NonEmpty a) where   (a :| as) <> ~(b :| bs) = a :| (as ++ b : bs) -newtype Min a = Min { getMin :: a } deriving +newtype Min a = Min { getMin :: a } deriving   ( Eq, Ord, Bounded, Show, Read #ifdef LANGUAGE_DeriveDataTypeable   , Data, Typeable@@ -190,13 +190,13 @@  instance Ord a => Semigroup (Min a) where   Min a <> Min b = Min (a `min` b)-  times1p _ a = a +  times1p _ a = a  instance (Ord a, Bounded a) => Monoid (Min a) where   mempty = maxBound-  mappend = (<>) +  mappend = (<>) -newtype Max a = Max { getMax :: a } deriving +newtype Max a = Max { getMax :: a } deriving   ( Eq, Ord, Bounded, Show, Read #ifdef LANGUAGE_DeriveDataTypeable   , Data, Typeable@@ -205,14 +205,14 @@  instance Ord a => Semigroup (Max a) where   Max a <> Max b = Max (a `max` b)-  times1p _ a = a +  times1p _ a = a  instance (Ord a, Bounded a) => Monoid (Max a) where   mempty = minBound-  mappend = (<>) +  mappend = (<>)  -- | Use @'Option' ('First' a)@ -- to get the behavior of 'Data.Monoid.First'-newtype First a = First { getFirst :: a } deriving +newtype First a = First { getFirst :: a } deriving   ( Eq, Ord, Bounded, Show, Read #ifdef LANGUAGE_DeriveDataTypeable   , Data@@ -222,10 +222,10 @@  instance Semigroup (First a) where   a <> _ = a-  times1p _ a = a +  times1p _ a = a  -- | Use @'Option' ('Last' a)@ -- to get the behavior of 'Data.Monoid.Last'-newtype Last a = Last { getLast :: a } deriving +newtype Last a = Last { getLast :: a } deriving   ( Eq, Ord, Bounded, Show, Read #ifdef LANGUAGE_DeriveDataTypeable   , Data, Typeable@@ -234,14 +234,14 @@  instance Semigroup (Last a) where   _ <> b = b-  times1p _ a = a +  times1p _ a = a  -- (==)/XNOR on Bool forms a 'Semigroup', but has no good name   -- | Provide a Semigroup for an arbitrary Monoid.-newtype WrappedMonoid m = WrapMonoid -  { unwrapMonoid :: m } deriving +newtype WrappedMonoid m = WrapMonoid+  { unwrapMonoid :: m } deriving   ( Eq, Ord, Bounded, Show, Read #ifdef LANGUAGE_DeriveDataTypeable   , Data, Typeable@@ -258,8 +258,8 @@  -- | Option is effectively 'Maybe' with a better instance of 'Monoid', built off of an underlying 'Semigroup' -- instead of an underlying 'Monoid'. Ideally, this type would not exist at all and we would just fix the 'Monoid' intance of 'Maybe'-newtype Option a = Option -  { getOption :: Maybe a } deriving +newtype Option a = Option+  { getOption :: Maybe a } deriving   ( Eq, Ord, Show, Read #ifdef LANGUAGE_DeriveDataTypeable   , Data, Typeable@@ -301,12 +301,12 @@ instance Traversable Option where   traverse f (Option (Just a)) = Option . Just <$> f a   traverse _ (Option Nothing)  = pure (Option Nothing)-  + option :: b -> (a -> b) -> Option a -> b option n j (Option m) = maybe n j m  instance Semigroup a => Semigroup (Option a) where-  Option a <> Option b = Option (a <> b) +  Option a <> Option b = Option (a <> b)  instance Semigroup a => Monoid (Option a) where   mempty = empty@@ -321,16 +321,16 @@  instance Semigroup IntSet where   (<>) = mappend-  times1p _ a = a +  times1p _ a = a  instance Ord a => Semigroup (Set a) where   (<>) = mappend-  times1p _ a = a +  times1p _ a = a  instance Semigroup (IntMap v) where   (<>) = mappend-  times1p _ a = a +  times1p _ a = a  instance Ord k => Semigroup (Map k v) where   (<>) = mappend-  times1p _ a = a +  times1p _ a = a
semigroups.cabal view
@@ -1,6 +1,6 @@ name:          semigroups category:      Algebra, Data, Data Structures, Math-version:       0.8+version:       0.8.0.1 license:       BSD3 cabal-version: >= 1.6 license-file:  LICENSE@@ -10,11 +10,11 @@ homepage:      http://github.com/ekmett/semigroups/ copyright:     Copyright (C) 2011 Edward A. Kmett synopsis:      Haskell 98 semigroups-description:   +description:     Haskell 98 semigroups     .     In mathematics, a semigroup is an algebraic structure consisting of a set together with an associative binary operation. A semigroup generalizes a monoid in that there might not exist an identity element. It also (originally) generalized a group (a monoid with all inverses) to a type where every element did not have to have an inverse, thus the name semigroup.-build-type:    Simple  +build-type:    Simple  source-repository head   type: git@@ -26,8 +26,8 @@   manual: False  library-  build-depends: -    base >= 4 && < 5, +  build-depends:+    base >= 4 && < 5,     containers >= 0.3 && < 0.5    ghc-options: -Wall