packages feed

monoid-subclasses 0.4 → 0.4.0.1

raw patch · 5 files changed

+87/−12 lines, 5 files

Files

Data/Monoid/Instances/ByteString/UTF8.hs view
@@ -6,8 +6,8 @@  -- | This module defines the 'ByteStringUTF8' newtype wrapper around 'ByteString', together with its 'TextualMonoid' -- instance. The 'FactorialMonoid' instance of a wrapped 'ByteStringUTF8' value differs from the original 'ByteString':--- the prime 'factors' of the original value are bytes, while UTF8 character byte sequences make up the wrapped value's--- prime 'factors'. The following example session demonstrates the relationship:+-- the prime 'factors' of the original value are its bytes, and for the wrapped value the prime 'factors' are its valid+-- UTF8 byte sequences. The following example session demonstrates the relationship: --  -- >> let utf8@(ByteStringUTF8 bs) = fromString "E=mc\xb2" -- >> bs
Data/Monoid/Instances/Positioned.hs view
@@ -449,6 +449,8 @@    {-# INLINE span #-}    {-# INLINE foldl_' #-}    {-# INLINE foldr_ #-}+   {-# INLINE any #-}+   {-# INLINE all #-}    {-# INLINE spanMaybe_' #-}    {-# INLINE span_ #-}    {-# INLINE break_ #-}@@ -576,6 +578,8 @@    {-# INLINE find #-}    {-# INLINE foldl_' #-}    {-# INLINE foldr_ #-}+   {-# INLINE any #-}+   {-# INLINE all #-}    {-# INLINE spanMaybe_' #-}    {-# INLINE span_ #-}    {-# INLINE break_ #-}
Data/Monoid/Instances/Stateful.hs view
@@ -19,8 +19,8 @@    ) where -import Prelude hiding (all, any, break, elem, filter, foldl, foldl1, foldr, foldr1, map, concatMap,-                       length, null, reverse, scanl, scanr, scanl1, scanr1, span, splitAt)+import Prelude hiding (all, any, break, elem, drop, filter, foldl, foldl1, foldr, foldr1, map, concatMap,+                       length, null, reverse, scanl, scanr, scanl1, scanr1, span, splitAt, take) import Control.Applicative (Applicative(..)) import Data.Functor ((<$>)) import qualified Data.List as List@@ -58,23 +58,37 @@ instance (Monoid a, Monoid b) => Monoid (Stateful a b) where    mempty = Stateful mempty    mappend (Stateful x) (Stateful y) = Stateful (x <> y)+   {-# INLINE mempty #-}+   {-# INLINE mappend #-}  instance (MonoidNull a, MonoidNull b) => MonoidNull (Stateful a b) where    null (Stateful x) = null x+   {-# INLINE null #-}  instance (PositiveMonoid a, PositiveMonoid b) => PositiveMonoid (Stateful a b)  instance (LeftReductiveMonoid a, LeftReductiveMonoid b) => LeftReductiveMonoid (Stateful a b) where+   isPrefixOf (Stateful x) (Stateful x') = isPrefixOf x x'    stripPrefix (Stateful x) (Stateful x') = Stateful <$> stripPrefix x x'+   {-# INLINE isPrefixOf #-}+   {-# INLINE stripPrefix #-}  instance (RightReductiveMonoid a, RightReductiveMonoid b) => RightReductiveMonoid (Stateful a b) where+   isSuffixOf (Stateful x) (Stateful x') = isSuffixOf x x'    stripSuffix (Stateful x) (Stateful x') = Stateful <$> stripSuffix x x'+   {-# INLINE stripSuffix #-}+   {-# INLINE isSuffixOf #-}  instance (LeftGCDMonoid a, LeftGCDMonoid b) => LeftGCDMonoid (Stateful a b) where    commonPrefix (Stateful x) (Stateful x') = Stateful (commonPrefix x x')+   stripCommonPrefix (Stateful x) (Stateful x') = (Stateful prefix, Stateful suffix1, Stateful suffix2)+      where (prefix, suffix1, suffix2) = stripCommonPrefix x x'+   {-# INLINE commonPrefix #-}+   {-# INLINE stripCommonPrefix #-}  instance (RightGCDMonoid a, RightGCDMonoid b) => RightGCDMonoid (Stateful a b) where    commonSuffix (Stateful x) (Stateful x') = Stateful (commonSuffix x x')+   {-# INLINE commonSuffix #-}  instance (FactorialMonoid a, FactorialMonoid b) => FactorialMonoid (Stateful a b) where    factors (Stateful x) = List.map Stateful (factors x)@@ -94,9 +108,31 @@    foldMap f (Stateful x) = Factorial.foldMap (f . Stateful) x    span p (Stateful x) = (Stateful xp, Stateful xs)       where (xp, xs) = Factorial.span (p . Stateful) x+   spanMaybe s0 f (Stateful x) = (Stateful xp, Stateful xs, s')+      where (xp, xs, s') = Factorial.spanMaybe s0 f' x+            f' s x1 = f s (Stateful x1)+   spanMaybe' s0 f (Stateful x) = (Stateful xp, Stateful xs, s')+      where (xp, xs, s') = Factorial.spanMaybe' s0 f' x+            f' s x1 = f s (Stateful x1)    split p (Stateful x) = List.map Stateful (Factorial.split (p . Stateful) x)-   splitAt m (Stateful x) = (Stateful xp, Stateful xs)-      where (xp, xs) = splitAt m x+   splitAt n (Stateful x) = (Stateful xp, Stateful xs)+      where (xp, xs) = splitAt n x+   take n (Stateful x) = Stateful (take n x)+   drop n (Stateful x) = Stateful (drop n x)+   {-# INLINE primePrefix #-}+   {-# INLINE primeSuffix #-}+   {-# INLINE splitPrimePrefix #-}+   {-# INLINE splitPrimeSuffix #-}+   {-# INLINE foldl' #-}+   {-# INLINE foldr #-}+   {-# INLINE foldMap #-}+   {-# INLINE length #-}+   {-# INLINE span #-}+   {-# INLINE spanMaybe #-}+   {-# INLINE spanMaybe' #-}+   {-# INLINE splitAt #-}+   {-# INLINE take #-}+   {-# INLINE drop #-}  instance (StableFactorialMonoid a, StableFactorialMonoid b) => StableFactorialMonoid (Stateful a b) @@ -112,8 +148,8 @@                                                return (c, Stateful (t', x))     map f (Stateful (t, x)) = Stateful (Textual.map f t, x)-   all p = Textual.all p . extract-   any p = Textual.any p . extract+   all p = all p . extract+   any p = any p . extract     foldl fx fc a (Stateful (t, x)) = Factorial.foldl f2 (Textual.foldl f1 fc a t) x       where f1 a = fx a . fromFst@@ -123,6 +159,8 @@       where a' = Textual.foldl' f1 fc a t             f1 a = fx a . fromFst             f2 a = fx a . fromSnd+   foldl_' fc a (Stateful (t, _)) = foldl_' fc a t+   foldr_ fc a (Stateful (t, _)) = Textual.foldr_ fc a t     scanl f c (Stateful (t, x)) = Stateful (Textual.scanl f c t, x)    scanl1 f (Stateful (t, x)) = Stateful (Textual.scanl1 f t, x)@@ -137,16 +175,49 @@       where (tp, ts) = Textual.span (pt . fromFst) pc t             (xp, xs) | null ts = Factorial.span (pt . fromSnd) x                      | otherwise = (mempty, x)+   span_ bt pc (Stateful (t, x)) = (Stateful (tp, xp), Stateful (ts, xs))+      where (tp, ts) = Textual.span_ bt pc t+            (xp, xs) | null ts && bt = (x, mempty)+                     | otherwise = (mempty, x)    break pt pc (Stateful (t, x)) = (Stateful (tp, xp), Stateful (ts, xs))       where (tp, ts) = Textual.break (pt . fromFst) pc t             (xp, xs) | null ts = Factorial.break (pt . fromSnd) x                      | otherwise = (mempty, x)+   spanMaybe s0 ft fc (Stateful (t, x)) = (Stateful (tp, xp), Stateful (ts, xs), s'')+      where (tp, ts, s') = Textual.spanMaybe s0 ft' fc t+            (xp, xs, s'') = Factorial.spanMaybe s' ft'' x+            ft' s t1 = ft s (Stateful (t1, mempty))+            ft'' s x1 = ft s (Stateful (mempty, x1))+   spanMaybe' s0 ft fc (Stateful (t, x)) = (Stateful (tp, xp), Stateful (ts, xs), s'')+      where (tp, ts, s') = Textual.spanMaybe' s0 ft' fc t+            (xp, xs, s'') = Factorial.spanMaybe' s' ft'' x+            ft' s t1 = ft s (Stateful (t1, mempty))+            ft'' s x1 = ft s (Stateful (mempty, x1))+   spanMaybe_' s0 fc (Stateful (t, x)) = (Stateful (tp, xp), Stateful (ts, xs), s')+      where (tp, ts, s') = Textual.spanMaybe_' s0 fc t+            (xp, xs) | null ts = (x, mempty)+                     | otherwise = (mempty, x)    split p (Stateful (t, x)) = restore id ts       where ts = Textual.split p t             restore f [t] = f [Stateful (t, x)]             restore f (hd:tl) = restore (f . (Stateful (hd, mempty):)) tl    find p = find p . extract    elem c = elem c . extract++   {-# INLINE characterPrefix #-}+   {-# INLINE splitCharacterPrefix #-}+   {-# INLINE map #-}+   {-# INLINE foldl' #-}+   {-# INLINE foldr #-}+   {-# INLINE spanMaybe' #-}+   {-# INLINE span #-}+   {-# INLINE spanMaybe_' #-}+   {-# INLINE span_ #-}+   {-# INLINE any #-}+   {-# INLINE all #-}+   {-# INLINE split #-}+   {-# INLINE find #-}+   {-# INLINE elem #-}  {-# INLINE fromFst #-} fromFst :: Monoid b => a -> Stateful b a
Data/Monoid/Textual.hs view
@@ -4,7 +4,7 @@     License: BSD3 (see BSD3-LICENSE.txt file) -} --- | This module defines the 'TextualMonoid' class and its most important instances for 'String' and 'Text'.+-- | This module defines the 'TextualMonoid' class and several of its instances. --   {-# LANGUAGE Haskell2010, FlexibleInstances, Trustworthy #-}
monoid-subclasses.cabal view
@@ -1,5 +1,5 @@ Name:                monoid-subclasses-Version:             0.4+Version:             0.4.0.1 Cabal-Version:       >= 1.10 Build-Type:          Simple Synopsis:            Subclasses of Monoid@@ -24,14 +24,14 @@   Exposed-Modules:   Data.Monoid.Cancellative, Data.Monoid.Factorial, Data.Monoid.Null, Data.Monoid.Textual,                      Data.Monoid.Instances.ByteString.UTF8, Data.Monoid.Instances.Concat,                      Data.Monoid.Instances.Measured, Data.Monoid.Instances.Positioned, Data.Monoid.Instances.Stateful-  Build-Depends:     base >= 4 && < 5, bytestring >= 0.9 && < 1.0, containers == 0.5.*, text >= 0.11 && < 1.3,+  Build-Depends:     base >= 4 && < 5, bytestring >= 0.9 && < 1.0, containers >= 0.5.2.0 && < 0.6, text >= 0.11 && < 1.3,                      primes == 0.2.*, vector >= 0.9 && < 0.11   GHC-prof-options:  -auto-all   default-language:  Haskell2010  test-suite Main   Type:              exitcode-stdio-1.0-  Build-Depends:     base >= 4 && < 5, bytestring >= 0.9 && < 1.0, containers == 0.5.*, text >= 0.11 && < 1.3,+  Build-Depends:     base >= 4 && < 5, bytestring >= 0.9 && < 1.0, containers >= 0.5.2.0 && < 0.6, text >= 0.11 && < 1.3,                      vector >= 0.9 && < 0.11, primes == 0.2.*,                      QuickCheck == 2.*, quickcheck-instances == 0.3.*, tasty >= 0.7, tasty-quickcheck >= 0.7,                      monoid-subclasses