[added Data.Sequence
ekmett@gmail.com**20090327040022] {
hunk ./Data/Monoid/Generator.hs 20
+import Data.Sequence (Seq)
+import Data.FingerTree (Measured, FingerTree)
hunk ./Data/Monoid/Generator.hs 49
+
+instance Measured v m => Generator (FingerTree v m) where
+ type Elem (FingerTree v m) = m
+ mapReduce f = foldMap (unit . f)
+
+instance Generator (Seq c) where
+ type Elem (Seq c) = c
+ mapReduce f = foldMap (unit . f)
hunk ./Data/Monoid/Multiplicative.hs 5
+ , Seminearring
hunk ./Data/Monoid/Multiplicative.hs 14
+import qualified Data.Sequence as Seq
+import Data.Sequence (Seq)
hunk ./Data/Monoid/Multiplicative.hs 31
- xss `times` yss = getSelf . reduce . fmap (\xs -> fmap' (xs `mappend`) yss) $ toList xss
+ xss `times` yss = getSelf $ mapReduce (flip fmap' yss . mappend) xss
+
+instance (Monoid m) => MultiplicativeMonoid (Seq m) where
+ one = Seq.singleton mempty
+ xss `times` yss = getSelf $ mapReduce (flip fmap yss . mappend) xss
hunk ./Data/Monoid/Multiplicative.hs 47
+-- class Absorbing m where isZero :: m -> Bool
+
hunk ./Data/Monoid/Reducer.hs 14
+import qualified Data.Sequence as Seq
+import Data.Sequence (Seq)
hunk ./Data/Monoid/Reducer.hs 88
+-- orphan, which should be in Data.FingerTree
hunk ./Data/Monoid/Reducer.hs 98
+instance Reducer a (Seq a) where
+ unit = Seq.singleton
+ cons = (Seq.<|)
+ snoc = (Seq.|>)
+
hunk ./Data/Monoid/Self.hs 8
-import Data.Foldable
hunk ./Data/Monoid/Self.hs 10
-import GHC.Exts
hunk ./dist/doc/html/monoids/Data-Monoid-Generator.html 268
+>
| Instances | | Reducer a (Seq a) | Seminearring | Data.Monoid.Multiplicative, Data.Monoid.Multiplicative.Transformers, Data.Monoid.Multiplicative.Sugar |
-
-class Generator c where
- type Elem c :: *
- mapReduce :: (e `Reducer` m) => (Elem c -> e) -> c -> m
- mapTo :: (e `Reducer` m) => (Elem c -> e) -> m -> c -> m
- mapFrom :: (e `Reducer` m) => (Elem c -> e) -> c -> m -> m
-
- mapReduce f = mapTo f mempty
- mapTo f m = mappend m . mapReduce f
- mapFrom f = mappend . mapReduce f
-
-instance Generator Strict.ByteString where
- type Elem Strict.ByteString = Word8
- mapTo f = Strict.foldl' (\a -> snoc a . f)
-
-instance Generator Lazy.ByteString where
- type Elem Lazy.ByteString = Elem Strict.ByteString
- mapReduce f = fold . parMap rwhnf (mapReduce f) . Lazy.toChunks
-
-instance Generator Text where
- type Elem Text = Char
- mapTo f = Text.foldl' (\a -> snoc a . f)
-
-instance Generator [c] where
- type Elem [c] = c
- mapReduce f = foldMap (unit . f)
-
-
-
-
-
-
-
-reduce :: (Generator c, Elem c `Reducer` m) => c -> m
-reduce = mapReduce id
+import Data.Sequence (Seq)
+import Data.FingerTree (Measured, FingerTree)
+
+
+class Generator c where
+ type Elem c :: *
+ mapReduce :: (e `Reducer` m) => (Elem c -> e) -> c -> m
+ mapTo :: (e `Reducer` m) => (Elem c -> e) -> m -> c -> m
+ mapFrom :: (e `Reducer` m) => (Elem c -> e) -> c -> m -> m
+
+ mapReduce f = mapTo f mempty
+ mapTo f m = mappend m . mapReduce f
+ mapFrom f = mappend . mapReduce f
+
+instance Generator Strict.ByteString where
+ type Elem Strict.ByteString = Word8
+ mapTo f = Strict.foldl' (\a -> snoc a . f)
+
+instance Generator Lazy.ByteString where
+ type Elem Lazy.ByteString = Elem Strict.ByteString
+ mapReduce f = fold . parMap rwhnf (mapReduce f) . Lazy.toChunks
+
+instance Generator Text where
+ type Elem Text = Char
+ mapTo f = Text.foldl' (\a -> snoc a . f)
+
+instance Generator [c] where
+ type Elem [c] = c
+ mapReduce f = foldMap (unit . f)
+
+instance Measured v m => Generator (FingerTree v m) where
+ type Elem (FingerTree v m) = m
+ mapReduce f = foldMap (unit . f)
+
+instance Generator (Seq c) where
+ type Elem (Seq c) = c
+ mapReduce f = foldMap (unit . f)
+
+
+
+
+
+
+
+reduce :: (Generator c, Elem c `Reducer` m) => c -> m
+reduce = mapReduce id
hunk ./dist/doc/html/monoids/src/Data-Monoid-Multiplicative.html 13
- ) where
-
-import Data.Monoid.Additive
-import Data.FingerTree
-import Data.Monoid.Self
-import Data.Monoid.FromString
-import Data.Monoid.Generator
-import Data.Foldable
-
-class MultiplicativeMonoid m where
- one :: m
- times :: m -> m -> m
-
-class (MultiplicativeMonoid m, Monoid m) => Seminearring m
-
-instance Monoid m => MultiplicativeMonoid [m] where
- one = [mempty]
- xss `times` yss = [ xs `mappend` ys | xs <- xss, ys <- yss ]
-
-instance Monoid m => Seminearring [m]
-
-instance (Measured v m, Monoid m) => MultiplicativeMonoid (FingerTree v m) where
- one = singleton mempty
- xss `times` yss = getSelf . reduce . fmap (\xs -> fmap' (xs `mappend`) yss) $ toList xss
-
-instance (Measured v m, Monoid m) => Seminearring (FingerTree v m)
-
-instance MultiplicativeMonoid m => MultiplicativeMonoid (Self m) where
- one = Self one
- Self a `times` Self b = Self (a `times` b)
-
-instance MultiplicativeMonoid m => MultiplicativeMonoid (FromString m) where
- one = FromString one
- FromString a `times` FromString b = FromString (a `times` b)
+ , Seminearring
+ ) where
+
+import Data.Monoid.Additive
+import Data.FingerTree
+import Data.Monoid.Self
+import Data.Monoid.FromString
+import Data.Monoid.Generator
+import Data.Foldable
+import qualified Data.Sequence as Seq
+import Data.Sequence (Seq)
+
+class MultiplicativeMonoid m where
+ one :: m
+ times :: m -> m -> m
+
+class (MultiplicativeMonoid m, Monoid m) => Seminearring m
+
+instance Monoid m => MultiplicativeMonoid [m] where
+ one = [mempty]
+ xss `times` yss = [ xs `mappend` ys | xs <- xss, ys <- yss ]
+
+instance Monoid m => Seminearring [m]
+
+instance (Measured v m, Monoid m) => MultiplicativeMonoid (FingerTree v m) where
+ one = singleton mempty
+ xss `times` yss = getSelf $ mapReduce (flip fmap' yss . mappend) xss
+
+instance (Monoid m) => MultiplicativeMonoid (Seq m) where
+ one = Seq.singleton mempty
+ xss `times` yss = getSelf $ mapReduce (flip fmap yss . mappend) xss
+
+instance (Measured v m, Monoid m) => Seminearring (FingerTree v m)
+
+instance MultiplicativeMonoid m => MultiplicativeMonoid (Self m) where
+ one = Self one
+ Self a `times` Self b = Self (a `times` b)
+
+instance MultiplicativeMonoid m => MultiplicativeMonoid (FromString m) where
+ one = FromString one
+ FromString a `times` FromString b = FromString (a `times` b)
+
+
hunk ./dist/doc/html/monoids/src/Data-Monoid-Reducer.html 22
-
-
-class Monoid m => Reducer c m where
- unit :: c -> m
- snoc :: m -> c -> m
- cons :: c -> m -> m
-
- unit = snoc mempty
- snoc m = mappend m . unit
- cons = mappend . unit
-
-foldMapReduce :: (Foldable f, e `Reducer` m) => (a -> e) -> f a -> m
-foldMapReduce f = foldMap (unit . f)
-
-foldReduce :: (Foldable f, e `Reducer` m) => f e -> m
-foldReduce = foldMap unit
-
-instance (Reducer c m, Reducer c n) => Reducer c (m,n) where
- unit x = (unit x,unit x)
- (m,n) `snoc` x = (m `snoc` x, n `snoc` x)
- x `cons` (m,n) = (x `cons` m, x `cons` n)
-
-instance (Reducer c m, Reducer c n, Reducer c o) => Reducer c (m,n,o) where
- unit x = (unit x,unit x, unit x)
- (m,n,o) `snoc` x = (m `snoc` x, n `snoc` x, o `snoc` x)
- x `cons` (m,n,o) = (x `cons` m, x `cons` n, x `cons` o)
-
-instance (Reducer c m, Reducer c n, Reducer c o, Reducer c p) => Reducer c (m,n,o,p) where
- unit x = (unit x,unit x, unit x, unit x)
- (m,n,o,p) `snoc` x = (m `snoc` x, n `snoc` x, o `snoc` x, p `snoc` x)
- x `cons` (m,n,o,p) = (x `cons` m, x `cons` n, x `cons` o, x `cons` p)
-
-instance Reducer c [c] where
- unit = return
- cons = (:)
- xs `snoc` x = xs ++ [x]
-
-instance Reducer c () where
- unit _ = ()
- _ `snoc` _ = ()
- _ `cons` _ = ()
-
-instance Reducer Bool Any where
- unit = Any
-
-instance Reducer Bool All where
- unit = All
-
-instance Reducer (a -> a) (Endo a) where
- unit = Endo
-
-instance Monoid a => Reducer a (Dual a) where
- unit = Dual
-
-instance Num a => Reducer a (Sum a) where
- unit = Sum
-
-instance Num a => Reducer a (Product a) where
- unit = Product
-
-instance Reducer (Maybe a) (First a) where
- unit = First
-
-instance Reducer a (First a) where
- unit = First . Just
-
-instance Reducer (Maybe a) (Last a) where
- unit = Last
-
-instance Reducer a (Last a) where
- unit = Last . Just
-
-instance Measured v a => Monoid (FingerTree v a) where
- mempty = empty
- mappend = (><)
-
-instance Measured v a => Reducer a (FingerTree v a) where
- unit = singleton
- cons = (<|)
- snoc = (|>)
+import qualified Data.Sequence as Seq
+import Data.Sequence (Seq)
+
+
+class Monoid m => Reducer c m where
+ unit :: c -> m
+ snoc :: m -> c -> m
+ cons :: c -> m -> m
+
+ unit = snoc mempty
+ snoc m = mappend m . unit
+ cons = mappend . unit
+
+foldMapReduce :: (Foldable f, e `Reducer` m) => (a -> e) -> f a -> m
+foldMapReduce f = foldMap (unit . f)
+
+foldReduce :: (Foldable f, e `Reducer` m) => f e -> m
+foldReduce = foldMap unit
+
+instance (Reducer c m, Reducer c n) => Reducer c (m,n) where
+ unit x = (unit x,unit x)
+ (m,n) `snoc` x = (m `snoc` x, n `snoc` x)
+ x `cons` (m,n) = (x `cons` m, x `cons` n)
+
+instance (Reducer c m, Reducer c n, Reducer c o) => Reducer c (m,n,o) where
+ unit x = (unit x,unit x, unit x)
+ (m,n,o) `snoc` x = (m `snoc` x, n `snoc` x, o `snoc` x)
+ x `cons` (m,n,o) = (x `cons` m, x `cons` n, x `cons` o)
+
+instance (Reducer c m, Reducer c n, Reducer c o, Reducer c p) => Reducer c (m,n,o,p) where
+ unit x = (unit x,unit x, unit x, unit x)
+ (m,n,o,p) `snoc` x = (m `snoc` x, n `snoc` x, o `snoc` x, p `snoc` x)
+ x `cons` (m,n,o,p) = (x `cons` m, x `cons` n, x `cons` o, x `cons` p)
+
+instance Reducer c [c] where
+ unit = return
+ cons = (:)
+ xs `snoc` x = xs ++ [x]
+
+instance Reducer c () where
+ unit _ = ()
+ _ `snoc` _ = ()
+ _ `cons` _ = ()
+
+instance Reducer Bool Any where
+ unit = Any
+
+instance Reducer Bool All where
+ unit = All
+
+instance Reducer (a -> a) (Endo a) where
+ unit = Endo
+
+instance Monoid a => Reducer a (Dual a) where
+ unit = Dual
+
+instance Num a => Reducer a (Sum a) where
+ unit = Sum
+
+instance Num a => Reducer a (Product a) where
+ unit = Product
+
+instance Reducer (Maybe a) (First a) where
+ unit = First
+
+instance Reducer a (First a) where
+ unit = First . Just
+
+instance Reducer (Maybe a) (Last a) where
+ unit = Last
+
+instance Reducer a (Last a) where
+ unit = Last . Just
+
+
+instance Measured v a => Monoid (FingerTree v a) where
+ mempty = empty
+ mappend = (><)
+
+instance Measured v a => Reducer a (FingerTree v a) where
+ unit = singleton
+ cons = (<|)
+ snoc = (|>)
+
+instance Reducer a (Seq a) where
+ unit = Seq.singleton
+ cons = (Seq.<|)
+ snoc = (Seq.|>)
hunk ./dist/doc/html/monoids/src/Data-Monoid-Self.html 16
-import Data.Foldable
-import Data.Monoid.Reducer
-import Data.Monoid.Generator
-import GHC.Exts
+import Data.Monoid.Reducer
+import Data.Monoid.Generator
+
+newtype Self m = Self { getSelf :: m } deriving (Monoid)
hunk ./dist/doc/html/monoids/src/Data-Monoid-Self.html 21
-newtype Self m = Self { getSelf :: m } deriving (Monoid)
-
-instance Monoid m => Reducer m (Self m) where
- unit = Self
-
-instance Functor Self where
- fmap f = Self . f . getSelf
-
-instance Pointed Self where
- point = Self
-
-instance Copointed Self where
- extract = getSelf
-
+instance Monoid m => Reducer m (Self m) where
+ unit = Self
+
+instance Functor Self where
+ fmap f = Self . f . getSelf
+
+instance Pointed Self where
+ point = Self
+
+instance Copointed Self where
+ extract = getSelf
+
}
|