semigroups 0.7.1 → 0.7.1.1
raw patch · 4 files changed
+50/−3 lines, 4 files
Files
- Data/Semigroup.hs +17/−1
- Numeric/Natural.hs +13/−0
- Numeric/Natural/Internal.hs +15/−0
- semigroups.cabal +5/−2
Data/Semigroup.hs view
@@ -8,6 +8,13 @@ -- 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, +-- thus the name semigroup.+-- ---------------------------------------------------------------------------- module Data.Semigroup ( Semigroup(..)@@ -56,14 +63,21 @@ infixl 6 <> class Semigroup a where+ -- | An associative operation. + -- + -- > (a <> b) <> c = a <> (b <> c) (<>) :: a -> a -> a + -- | Reduce a non-empty list with (<>) sconcat :: NonEmpty a -> a sconcat (a :| as) = go a as where go b (c:cs) = b <> go c cs go b [] = b - -- replicate1p n r = replicate (1 + n) r+ -- | /O(log n)/ Repeat a value (n + 1) times.+ --+ -- > replicate1p n a = a <> a <> ... n + 1 times <> a+ replicate1p :: Whole n => n -> a -> a replicate1p y0 x0 = f x0 (1 Prelude.+ y0) where@@ -210,6 +224,8 @@ -- (==)/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 ( Eq, Ord, Bounded, Show, Read
Numeric/Natural.hs view
@@ -1,3 +1,16 @@+-----------------------------------------------------------------------------+-- |+-- Module : Numeric.Natural+-- Copyright : (C) 2011 Edward Kmett,+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+-- Natural numbers.+--+---------------------------------------------------------------------------- module Numeric.Natural ( Natural , Whole(toNatural)
Numeric/Natural/Internal.hs view
@@ -1,3 +1,17 @@+-----------------------------------------------------------------------------+-- |+-- Module : Numeric.Natural.Internal+-- Copyright : (C) 2011 Edward Kmett,+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+-- This module exposes the potentially unsafe operations that are sometimes+-- needed for efficiency: The Natural data constructor and unsafePred.+--+---------------------------------------------------------------------------- module Numeric.Natural.Internal ( Natural(..) , Whole(..)@@ -67,6 +81,7 @@ quotRem (Natural a) (Natural b) = (Natural q, Natural r) where (q,r) = quotRem a b toInteger = runNatural +-- | A refinement of Integral to represent types that do not contain negative numbers. class Integral n => Whole n where toNatural :: n -> Natural unsafePred :: n -> n
semigroups.cabal view
@@ -1,6 +1,6 @@ name: semigroups category: Algebra, Data, Data Structures, Math-version: 0.7.1+version: 0.7.1.1 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -10,7 +10,10 @@ homepage: http://github.com/ekmett/semigroups/ copyright: Copyright (C) 2011 Edward A. Kmett synopsis: Haskell 98 semigroups-description: Haskell 98 semigroups+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 source-repository head