packages feed

semigroups 0.9 → 0.9.1

raw patch · 2 files changed

+14/−1 lines, 2 files

Files

semigroups.cabal view
@@ -1,6 +1,6 @@ name:          semigroups category:      Algebra, Data, Data Structures, Math-version:       0.9+version:       0.9.1 license:       BSD3 cabal-version: >= 1.10 license-file:  LICENSE
src/Data/Semigroup.hs view
@@ -35,6 +35,7 @@   , First(..)   , Last(..)   , WrappedMonoid(..)+  , timesN   -- * Re-exported monoids from Data.Monoid   , Monoid(..)   , Dual(..)@@ -95,6 +96,8 @@   --   -- The default definition uses peasant multiplication, exploiting associativity to only   -- require /O(log n)/ uses of @\<\>@.+  --+  -- See also 'times'.    times1p :: Whole n => n -> a -> a   times1p y0 x0 = f x0 (1 Prelude.+ y0)@@ -268,6 +271,16 @@ instance Monoid m => Monoid (WrappedMonoid m) where   mempty = WrapMonoid mempty   WrapMonoid a `mappend` WrapMonoid b = WrapMonoid (a `mappend` b)++-- | Repeat a value @n@ times.+--+-- > times n a = a <> a <> ... <> a  -- using <> (n-1) times+--+-- Implemented using 'times1p'.+timesN :: (Whole n, Monoid a) => n -> a -> a+timesN n x | n == 0    = mempty+           | otherwise = unwrapMonoid . times1p (unsafePred n) . WrapMonoid $ x+{-# INLINE timesN #-}   -- | Option is effectively 'Maybe' with a better instance of 'Monoid', built off of an underlying 'Semigroup'