packages feed

monoids 0.1.5 → 0.1.8

raw patch · 16 files changed

+489/−46 lines, 16 filesdep ~QuickCheckdep ~arraydep ~base

Dependency ranges changed: QuickCheck, array, base, bitset, bytestring, category-extras, containers, fingertree, mtl, parallel, parsec, stm, text

Files

Data/Monoid/Applicative.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, GeneralizedNewtypeDeriving, FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, GeneralizedNewtypeDeriving, FlexibleContexts, TypeOperators #-}  ----------------------------------------------------------------------------- -- |@@ -16,14 +16,17 @@ module Data.Monoid.Applicative      ( module Data.Monoid.Reducer     , module Data.Ring.Semi.Near+    , module Data.Ring.Module     , Traversal(Traversal,getTraversal)     , WrappedApplicative(WrappedApplicative,getWrappedApplicative)+    , TraversalWith(TraversalWith,getTraversalWith)     , snocTraversal     ) where  import Control.Applicative import Data.Monoid.Reducer import Data.Ring.Semi.Near+import Data.Ring.Module import Control.Functor.Pointed  -- | A 'Traversal' uses an glues together 'Applicative' actions with (*>)@@ -69,3 +72,28 @@     unit = WrappedApplicative . pure . unit  instance (Alternative f, Monoid a) => LeftSemiNearRing (WrappedApplicative f a)++-- | if @m@ is a 'Module' and @f@ is a 'Applicative' then @f `TraversalWith` m@ is a 'Module' as well++newtype TraversalWith f m = TraversalWith { getTraversalWith :: f m } +    deriving (Eq,Ord,Show,Read,Functor,Pointed,Applicative,Alternative,Copointed)++instance (Monoid m, Applicative f) => Monoid (f `TraversalWith` m) where+    mempty = pure mempty+    mappend = liftA2 mappend++instance (Group m, Applicative f) => Group (f `TraversalWith` m) where+    gnegate = fmap gnegate+    minus = liftA2 minus+    gsubtract = liftA2 gsubtract++instance (c `Reducer` m, Applicative f) => Reducer c (f `TraversalWith` m) where+    unit = pure . unit++instance (LeftModule r m, Applicative f) => LeftModule r (f `TraversalWith` m) where+    x *. m = (x *.) <$> m++instance (RightModule r m, Applicative f) => RightModule r (f `TraversalWith` m) where+    m .* y = (.* y) <$> m++instance (Module r m, Applicative f) => Module r (f `TraversalWith` m)
+ Data/Monoid/Generator/LZ78.hs view
@@ -0,0 +1,94 @@+{-# LANGUAGE TypeFamilies, MultiParamTypeClasses #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  Data.Monoid.Generator.LZ78+-- Copyright   :  (c) Edward Kmett 2009+-- License     :  BSD-style+-- Maintainer  :  libraries@haskell.org+-- Stability   :  experimental+-- Portability :  portable+--+-- Compression algorithms are all about exploiting redundancy. When applying+-- an expensive 'Reducer' to a redundant source, it may be better to +-- extract the structural redundancy that is present. 'LZ78' is a compression+-- algorithm that does so, without requiring the dictionary to be populated+-- with all of the possible values of a data type unlike its later +-- refinement LZW, and which has fewer comparison reqirements during encoding+-- than its earlier counterpart LZ77. Since we aren't storing these as a +-- bitstream the LZSS refinement of only encoding pointers once you cross+-- the break-even point is a net loss. +-----------------------------------------------------------------------------+++module Data.Monoid.Generator.LZ78 +    ( module Data.Monoid.Generator+    , LZ78(LZ78, getLZ78)+    , decode+    , encode+    , encodeEq+    , prop_decode_encode+    , prop_decode_encodeEq+    ) where++import qualified Data.Sequence as Seq+import Data.Sequence (Seq,(|>))+import qualified Data.Map as Map+import Data.Map (Map)+import qualified Data.List as List+import Data.Monoid.Generator+import Data.Monoid.Self++-- | An LZ78 compressing 'Generator', which supports efficient 'mapReduce' operations++newtype LZ78 a = LZ78 { getLZ78 :: [(Int,a)] } ++emptyDict :: Monoid m => Seq m+emptyDict = Seq.singleton mempty++instance Generator (LZ78 a) where+    type Elem (LZ78 a) = a+    mapTo f m (LZ78 xs) = mapTo' f m emptyDict xs++mapTo' :: (e `Reducer` m) => (a -> e) -> m -> Seq m -> [(Int,a)] -> m+mapTo' _ m _   []         = m+mapTo' f m s ((w,c):ws) = mapTo' f (m `mappend` v) (s |> v) ws +    where +        v = Seq.index s w `mappend` unit (f c)++-- | a type-constrained 'reduce' operation+    +decode :: LZ78 a -> [a]+decode = reduce++-- | contruct an LZ78-compressed 'Generator' using a 'Map' internally, requires an instance of Ord.++encode :: Ord a => [a] -> LZ78 a+encode = LZ78 . encode' Map.empty 1 0++encode' :: Ord a => Map (Int,a) Int -> Int -> Int -> [a] -> [(Int,a)]+encode' _ _ p [c] = [(p,c)]+encode' d f p (c:cs) = case Map.lookup (p,c) d of+    Just p' -> encode' d f p' cs+    Nothing -> (p,c):encode' (Map.insert (p,c) f d) (succ f) 0 cs+encode' _ _ _ [] = []++-- | contruct an LZ78-compressed 'Generator' using a list internally, requires an instance of Eq.++encodeEq :: Eq a => [a] -> LZ78 a+encodeEq = LZ78 . encodeEq' [] 1 0++encodeEq' :: Eq a => [((Int,a),Int)] -> Int -> Int -> [a] -> [(Int,a)]+encodeEq' _ _ p [c] = [(p,c)]+encodeEq' d f p (c:cs) = case List.lookup (p,c) d of+    Just p' -> encodeEq' d f p' cs+    Nothing -> (p,c):encodeEq' (((p,c),f):d) (succ f) 0 cs+encodeEq' _ _ _ [] = []++-- | QuickCheck property: decode . encode = id+prop_decode_encode :: Ord a => [a] -> Bool+prop_decode_encode xs = decode (encode xs) == xs++-- | QuickCheck property: decode . encodeEq = id+prop_decode_encodeEq :: Eq a => [a] -> Bool+prop_decode_encodeEq xs = decode (encodeEq xs) == xs
+ Data/Monoid/Generator/RLE.hs view
@@ -0,0 +1,99 @@+{-# LANGUAGE TypeFamilies, MultiParamTypeClasses, TypeOperators, FlexibleInstances, FlexibleContexts #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  Data.Monoid.Generator.RLE+-- Copyright   :  (c) Edward Kmett 2009+-- License     :  BSD-style+-- Maintainer  :  libraries@haskell.org+-- Stability   :  experimental+-- Portability :  portable+--+-- Compression algorithms are all about exploiting redundancy. When applying+-- an expensive 'Reducer' to a redundant source, it may be better to +-- extract the structural redundancy that is present. Run length encoding+-- can do so for long runs of identical inputs.+-----------------------------------------------------------------------------++module Data.Monoid.Generator.RLE+    ( module Data.Monoid.Generator+    , RLE(RLE, getRLE)+    , decode+    , encode+    , encodeList+    , prop_decode_encode+    , prop_decode_encodeList+    ) where++import qualified Data.Sequence as Seq+import Data.Sequence (Seq,(|>),(<|),ViewL(..),ViewR(..),(><),viewl,viewr)+import Data.Foldable+import Data.Monoid.Generator+import qualified Data.Monoid.Combinators as Monoid +import Control.Functor.Pointed++-- | A single run with a strict length+data Run a = Run a {-# UNPACK #-} !Int++instance Functor Run where+    fmap f (Run a n) = Run (f a) n++instance Pointed Run where+    point a = Run a 1++-- | A 'Generator' which supports efficient 'mapReduce' operations over run-length encoded data.+newtype RLE f a = RLE { getRLE :: f (Run a) } ++instance Functor f => Functor (RLE f) where+    fmap f = RLE . fmap (fmap f) . getRLE++instance Foldable f => Generator (RLE f a) where+    type Elem (RLE f a) = a+    mapReduce f = foldMap run . getRLE where+        run (Run a n) = unit (f a) `Monoid.replicate` n++decode :: Foldable f => RLE f a -> [a]+decode = reduce++-- | naive left to right encoder++encodeList :: Eq a => [a] -> RLE [] a+encodeList [] = RLE []+encodeList (a:as) = RLE (point a `before` as)++before :: Eq a => Run a -> [a] -> [Run a]+r           `before` []                 = [r]+r@(Run a n) `before` (b:bs) | a == b    = Run a (n+1) `before` bs+                            | otherwise = r : point b `before` bs++-- | QuickCheck property: decode . encode = id+prop_decode_encodeList :: Eq a => [a] -> Bool+prop_decode_encodeList xs = decode (encode xs) == xs++-- One nice property that run-length encoding has is that it can be computed monoidally as follows++instance Eq a => Monoid (RLE Seq a) where+    mempty = RLE Seq.empty+    RLE l `mappend` RLE r = viewr l `merge` viewl r where+        (l' :> Run a m) `merge` (Run b n :< r')+            | a == b     = RLE ((l' |> Run a (m+n)) >< r')+            | otherwise  = RLE (l >< r)+        EmptyR `merge` _ = RLE r+        _ `merge` EmptyL = RLE l++instance Eq a => Reducer a (RLE Seq a) where+    unit = RLE . Seq.singleton . point+    cons a (RLE r) = case viewl r of+            Run b n :< r' | a == b    -> RLE (Run a (n+1) <| r')+                          | otherwise -> RLE (Run a 1     <| r )+            EmptyL                    -> RLE (return (point a))+    snoc (RLE l) a = case viewr l of+            l' :> Run b n | a == b    -> RLE (l' |> Run b (n+1))+                          | otherwise -> RLE (l  |> Run a 1    )+            EmptyR                    -> RLE (return (point a))++encode :: (Generator c, Eq (Elem c)) => c -> RLE Seq (Elem c)+encode = reduce++prop_decode_encode :: (Generator c, Eq (Elem c)) => c -> Bool+prop_decode_encode xs = decode (encode xs) == reduce xs
− Data/Monoid/Lexical/RunLengthEncoding.hs
@@ -1,35 +0,0 @@-{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Monoid.Lexical.RunLengthEncoding--- Copyright   :  (c) Edward Kmett 2009--- License     :  BSD-style--- Maintainer  :  libraries@haskell.org--- Stability   :  experimental--- Portability :  non-portable (MPTCs)------ A simple 'Monoid' transformer that turns any monoidal 'Reducer' into a--- a reducer that expects to be supplied both a run length @n@ with each item--- and which efficiently exponentiates the result of 'unit' @n@ times through --- 'replicate'.-----------------------------------------------------------------------------------module Data.Monoid.Lexical.RunLengthEncoding -    ( module Data.Monoid.Reducer-    , RLE(RLE,getRLE) -    ) where--import Prelude hiding (replicate)-import Data.Monoid.Reducer-import Data.Monoid.Combinators (replicate)--newtype RLE n m = RLE { getRLE :: m } --instance (Integral n, Monoid m) => Monoid (RLE n m) where-    mempty = RLE mempty-    RLE a `mappend` RLE b = RLE (a `mappend` b)--instance (Integral n, Reducer c m) => Reducer (n,c) (RLE n m) where-    unit ~(n,c) = RLE $ replicate (unit c) n
Data/Monoid/Monad.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, GeneralizedNewtypeDeriving, FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, GeneralizedNewtypeDeriving, FlexibleContexts, TypeOperators #-}  ----------------------------------------------------------------------------- -- |@@ -19,6 +19,8 @@     -- * Actions     , Action(Action,getAction)     , snocAction+    -- * Lifting Modules+    , ActionWith(ActionWith,getActionWith)     -- * Wrapped Monads     , WrappedMonad(WrappedMonad, getWrappedMonad)     ) where@@ -26,6 +28,7 @@ import Control.Functor.Pointed import Data.Monoid.Reducer import Data.Ring.Semi.Near+import Data.Ring.Module import Control.Monad  -- | An 'Action' uses glues together 'Monad' actions with (>>)@@ -70,3 +73,28 @@     unit = WrappedMonad . return . unit  instance (MonadPlus m, Monoid a) => LeftSemiNearRing (WrappedMonad m a)++-- | if @m@ is a 'Module' over @r@ and @f@ is a 'Monad' then @f `ActionWith` m@ is a 'Module' as well++newtype ActionWith f m = ActionWith { getActionWith :: f m } +    deriving (Eq,Ord,Show,Read,Functor,Pointed, Monad,MonadPlus)++instance (Monoid m, Monad f) => Monoid (f `ActionWith` m) where+    mempty = return mempty+    mappend = liftM2 mappend++instance (Group m, Monad f) => Group (f `ActionWith` m) where+    gnegate = liftM gnegate+    minus = liftM2 minus+    gsubtract = liftM2 gsubtract++instance (c `Reducer` m, Monad f) => Reducer c (f `ActionWith` m) where+    unit = return . unit++instance (LeftModule r m, Monad f) => LeftModule r (f `ActionWith` m) where+    x *. m = liftM (x *.) m++instance (RightModule r m, Monad f) => RightModule r (f `ActionWith` m) where+    m .* y = liftM (.* y) m++instance (Module r m, Monad f) => Module r (f `ActionWith` m)
Data/Monoid/Multiplicative.hs view
@@ -69,6 +69,8 @@ import Data.Monoid.Instances () import Data.Monoid.Self +import Data.Ratio+ import qualified Data.Sequence as Seq import Data.Sequence (Seq) @@ -219,4 +221,20 @@ instance Monoid m => Multiplicative (Const m a) where     one = pure undefined     times = liftA2 undefined+++-- Numeric instances++instance Multiplicative Int where+    one = 1+    times = (*)+++instance Multiplicative Integer where+    one = 1+    times = (*)++instance Integral m => Multiplicative (Ratio m) where+    one = 1+    times = (*) 
Data/Monoid/Ord.hs view
@@ -20,13 +20,15 @@     , Min(Min,getMin)     -- * MaxPriority: Max semigroup w/ added bottom     , MaxPriority(MaxPriority,getMaxPriority)+    , minfinity     -- * MinPriority: Min semigroup w/ added top     , MinPriority(MinPriority,getMinPriority)+    , infinity     ) where  import Control.Functor.Pointed import Data.Monoid.Reducer (Reducer, unit, Monoid, mappend, mempty)-+import Data.Ring.Semi  -- | The 'Monoid' @('max','minBound')@ newtype Max a = Max { getMax :: a } deriving (Eq,Ord,Show,Read,Bounded)@@ -66,6 +68,9 @@ instance Copointed Min where     extract = getMin +minfinity :: MaxPriority a+minfinity = MaxPriority Nothing+ -- | The 'Monoid' @('max','Nothing')@ over @'Maybe' a@ where 'Nothing' is the bottom element newtype MaxPriority a = MaxPriority { getMaxPriority :: Maybe a } deriving (Eq,Ord,Show,Read) @@ -81,6 +86,9 @@  instance Pointed MaxPriority where     point = MaxPriority . Just++infinity :: MinPriority a+infinity = MinPriority Nothing  -- | The 'Monoid' @('min','Nothing')@ over @'Maybe' a@ where 'Nothing' is the top element newtype MinPriority a = MinPriority { getMinPriority :: Maybe a } deriving (Eq,Show,Read)
Data/Monoid/Reducer.hs view
@@ -21,28 +21,40 @@     , unit, snoc, cons     , foldMapReduce     , foldReduce+    , pureUnit+    , returnUnit     ) where +import Control.Applicative+import Control.Monad + import Data.Monoid import Data.Monoid.Instances ()+ import Data.Foldable import Data.FingerTree+ import qualified Data.Sequence as Seq import Data.Sequence (Seq)+ import qualified Data.Set as Set import Data.Set (Set)+ import qualified Data.IntSet as IntSet import Data.IntSet (IntSet)+ import qualified Data.IntMap as IntMap import Data.IntMap (IntMap)+ import qualified Data.Map as Map+ import Data.Map (Map)+ import Text.Parsec.Prim-import Control.Monad + --import qualified Data.BitSet as BitSet --import Data.BitSet (BitSet) - -- | This type may be best read infix. A @c `Reducer` m@ is a 'Monoid' @m@ that maps -- values of type @c@ through @unit@ to values of type @m@. A @c@-'Reducer' may also -- supply operations which tack-on another @c@ to an existing 'Monoid' @m@ on the left@@ -78,6 +90,12 @@ -- | Apply a 'Reducer' to a 'Foldable' mapping each element through 'unit' foldReduce :: (Foldable f, e `Reducer` m) => f e -> m foldReduce = foldMap unit++returnUnit :: (Monad m, c `Reducer` n) => c -> m n +returnUnit = return . unit++pureUnit :: (Applicative f, c `Reducer` n) => c -> f n+pureUnit = pure . unit  instance (Reducer c m, Reducer c n) => Reducer c (m,n) where     unit x = (unit x,unit x)
Data/Ring/Boolean.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}  ----------------------------------------------------------------------------- -- |
Data/Ring/FromNum.hs view
@@ -44,3 +44,4 @@      instance Num a => Reducer Integer (FromNum a) where     unit = fromInteger+
+ Data/Ring/Module.hs view
@@ -0,0 +1,46 @@+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Data.Ring.Module+-- Copyright   :  (c) Edward Kmett 2009+-- License     :  BSD-style+-- Maintainer  :  libraries@haskell.org+-- Stability   :  experimental+-- Portability :  non-portable (MPTCs)+--+-- Left- and right- modules over rings, semirings, and Seminearrings.+-- To avoid a proliferation of classes. These only require that there+-- be an addition and multiplication operation for the 'Ring'+--+-----------------------------------------------------------------------------++module Data.Ring.Module +    ( module Data.Ring+    , LeftModule+    , (*.)+    , RightModule+    , (.*)+    , Module+    ) where++import Data.Ring+-- import qualified Data.Monoid.Combinators as Monoid++-- | @ (x * y) *. m = x * (y *. m) @+class (Monoid r, Multiplicative r, Monoid m) => LeftModule r m where+    (*.) :: r -> m -> m+    +-- | @ (m .* x) * y = m .* (x * y) @+class (Monoid r, Multiplicative r, Monoid m) => RightModule r m where+    (.*) :: m -> r -> m++-- | @ (x *. m) .* y = x *. (m .* y) @+class (LeftModule r m, RightModule r m) => Module r m ++-- instance Monoid m => LeftModule Int m where i *. m = Monoid.replicate m i +-- instance Monoid m => RightModule Int m where m .* i = Monoid.replicate m i +-- instance Monoid m => Module Int m+    +-- instance Monoid m => LeftModule Integer m where i *. m = Monoid.replicate m i +-- instance Monoid m => RightModule Integer m where m .* i = Monoid.replicate m i +-- instance Monoid m => Module Integer m
+ Data/Ring/Module/AutomaticDifferentiation.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}+module Data.Ring.Module.AutomaticDifferentiation +    ( module Data.Ring.Module+    , D+    ) where++import Prelude hiding ((*),(+),(-),subtract,negate)+import Data.Ring.Sugar+import Data.Ring.Module+import Data.Monoid.Reducer++data D r m = D r m++instance (Monoid r, Monoid m) => Monoid (D r m) where+    mempty = D mempty mempty+    D x m `mappend` D y n = D (x + y) (m + n)++instance (Module r m) => Multiplicative (D r m) where+    one = D one zero+    D x m `times` D y n = D (x * y) (x *. n + m .* y)++instance (Group r, Module r m, Group m) => Group (D r m) where+    gnegate (D x m) = D (gnegate x) (gnegate m)+    D x m `minus` D y n = D (x `minus` y) (m `minus` n)+    D x m `gsubtract` D y n = D (x `gsubtract` y) (m `gsubtract` n)++instance (LeftSemiNearRing r, Module r m) => LeftSemiNearRing (D r m)+instance (RightSemiNearRing r, Module r m) => RightSemiNearRing (D r m)+instance (SemiRing r, Module r m) => SemiRing (D r m)+instance (Ring r, Module r m, Group m) => Ring (D r m)++instance (c `Reducer` r, c `Reducer` m) => Reducer c (D r m) where+    unit c = D (unit c) (unit c)+    c `cons` D x m = D (c `cons` x) (c `cons` m)+    D x m `snoc` c = D (x `snoc` c) (m `snoc` c)++{--+infix 0 ><++(><) :: Multiplicatve a => (a -> a) -> (AD a -> AD a) -> AD a -> AD a+(f >< f') a@(AD a0 a') = D (f a0) (a' * f' a)++data AD r = AD r (Maybe (AD r))++instance (Monoid r) => Monoid (AD r) where+    mempty = K mempty+    AD x m + AD y n = D (x + y) (m + n)++instance (c `Reducer` r) => Reducer c (AD r) where+    unit c = c' where c' = AD (unit c) c'+--}
Data/Ring/Semi.hs view
@@ -20,4 +20,3 @@ -- | A 'SemiRing' is an instance of both 'Multiplicative' and 'Monoid' where  --   'times' distributes over 'plus'. class (RightSemiNearRing a, LeftSemiNearRing a) => SemiRing a-
Data/Ring/Semi/Near.hs view
@@ -11,7 +11,7 @@ -- Portability :  portable (instances use MPTCs) -- -- Defines left- and right- seminearrings. Every 'MonadPlus' wrapped around--- a 'Monoid' qualifies do to the distributivity of (>>=) over mplus.+-- a 'Monoid' qualifies due to the distributivity of (>>=) over 'mplus'. -- -- See <http://conway.rutgers.edu/~ccshan/wiki/blog/posts/WordNumbers1/> --@@ -87,3 +87,4 @@ instance (MonadPlus m, Monoid w, Monoid n) => LeftSemiNearRing (SWriter.WriterT w m n)  instance (MonadPlus m, Monoid w, Monoid n) => LeftSemiNearRing (LWriter.WriterT w m n)+
+ Data/Ring/Semi/Tropical.hs view
@@ -0,0 +1,71 @@+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}+-----------------------------------------------------------------------------+---- |+---- Module      :  Data.Ring.Semi.Tropical+---- Copyright   :  (c) Edward Kmett 2009+---- License     :  BSD-style+---- Maintainer  :  libraries@haskell.org+---- Stability   :  experimental+---- Portability :  portable+----+-----------------------------------------------------------------------------++module Data.Ring.Semi.Tropical+    ( module Data.Monoid.Reducer+    , module Data.Ring.Semi+    -- * Tropical Semirings+    , infinity+    , Tropical(Tropical,getTropical)+    ) where++import Control.Functor.Pointed+import Data.Monoid.Reducer (Reducer, unit, Monoid, mappend, mempty)+import Data.Ring.Semi+import Data.Monoid.Ord hiding (infinity)++infinity :: Tropical a+infinity = Tropical Nothing++-- | The 'SemiRing' @('min','+')@ over @'a' extended with 'infinity'@.+--   When @a@ has a Num instance with an addition that respects order, then this is +--   transformed into a tropical semiring. It is assumed that 0 is the least element+--   of a.+--+--   <http://hal.archives-ouvertes.fr/docs/00/11/37/79/PDF/Tropical.pdf>++newtype Tropical a = Tropical { getTropical :: Maybe a } deriving (Eq,Show,Read)++instance Ord a => Ord (Tropical a) where+    Tropical Nothing  `compare` Tropical Nothing  = EQ+    Tropical Nothing  `compare` _                    = GT+    _                 `compare` Tropical Nothing  = LT+    Tropical (Just a) `compare` Tropical (Just b) = a `compare` b++instance Ord a => Monoid (Tropical a) where+    mempty = infinity+    mappend = min++instance Ord a => Reducer a (Tropical a) where+    unit = Tropical . Just++instance Ord a => Reducer (Maybe a) (Tropical a) where+    unit = Tropical++instance Ord a => Reducer (MinPriority a) (Tropical a) where+    unit = Tropical . getMinPriority++instance Functor Tropical where+    fmap f (Tropical a) = Tropical (fmap f a)++instance Pointed Tropical where+    point = Tropical . Just++instance Num a => Multiplicative (Tropical a) where+    one = point $ fromInteger 0+    Tropical Nothing `times` _       = infinity+    Tropical (Just a) `times` Tropical (Just b) = point (a + b)+    _  `times` Tropical Nothing      = infinity++instance (Ord a, Num a) => LeftSemiNearRing (Tropical a)+instance (Ord a, Num a) => RightSemiNearRing (Tropical a)+instance (Ord a, Num a) => SemiRing (Tropical a)
monoids.cabal view
@@ -1,5 +1,5 @@ name:		    monoids-version:	    0.1.5+version:	    0.1.8 license:	    BSD3 license-file:   LICENSE author:		    Edward A. Kmett@@ -14,7 +14,20 @@ cabal-version:  >=1.2  library-  build-depends: base >= 4, text, fingertree, bytestring, category-extras, parallel, containers, mtl, stm, bitset, QuickCheck, array, parsec >= 3+  build-depends: +    base >= 4 && < 4.1,+    containers >= 0.2 && < 0.3, +    text >= 0.1 && < 0.2, +    parsec >= 3.0 && < 3.1,+    fingertree >= 0.0 && < 0.1, +    bytestring >= 0.9 && < 1.0, +    category-extras >= 0.53 && < 0.60, +    parallel >= 1.1 && < 1.2, +    mtl >= 1.0 && < 1.2, +    stm >= 2.1 && < 2.2, +    bitset >= 1.0 && < 1.1, +    QuickCheck < 2.2, +    array >= 0.2 && < 0.3   exposed-modules:     Data.Group     Data.Group.Combinators@@ -26,8 +39,9 @@     Data.Monoid.Combinators     Data.Monoid.FromString     Data.Monoid.Generator+    Data.Monoid.Generator.LZ78+    Data.Monoid.Generator.RLE     Data.Monoid.Lexical.SourcePosition-    Data.Monoid.Lexical.RunLengthEncoding     Data.Monoid.Lexical.UTF8.Decoder     Data.Monoid.Lexical.Words     Data.Monoid.Monad@@ -41,8 +55,11 @@     Data.Ring     Data.Ring.Boolean     Data.Ring.Semi+    Data.Ring.Semi.Tropical     Data.Ring.Semi.Near     Data.Ring.Semi.Ord     Data.Ring.FromNum+    Data.Ring.Module+    Data.Ring.Module.AutomaticDifferentiation     Data.Ring.Sugar   ghc-options: -Wall -fno-warn-duplicate-exports