packages feed

mono-traversable 0.3.0.2 → 0.3.0.3

raw patch · 3 files changed

+24/−7 lines, 3 files

Files

mono-traversable.cabal view
@@ -1,5 +1,5 @@ name:                mono-traversable-version:             0.3.0.2+version:             0.3.0.3 synopsis:            Type classes for mapping, folding, and traversing monomorphic containers description:         Monomorphic variants of the Functor, Foldable, and Traversable typeclasses. Contains even more experimental code for abstracting containers and sequences. homepage:            https://github.com/snoyberg/mono-traversable
src/Data/MonoTraversable.hs view
@@ -29,8 +29,7 @@ import qualified Data.ByteString.Lazy as L import qualified Data.Foldable        as F import           Data.Functor-import           Data.Monoid (Monoid (..), Any (..), All (..), Sum (..))-import qualified Data.Monoid+import           Data.Monoid (Monoid (..), Any (..), All (..)) import qualified Data.Text            as T import qualified Data.Text.Lazy       as TL import           Data.Traversable@@ -39,7 +38,7 @@ import           GHC.Exts             (build) import           Prelude              (Bool (..), const, Char, flip, ($), IO, Maybe (..), Either (..),                                        replicate, (+), Integral, Ordering (..), compare, fromIntegral, Num, (>=),-                                       seq, otherwise, maybe, Ord, (-))+                                       seq, otherwise, maybe, Ord, (-), (*)) import qualified Prelude import qualified Data.ByteString.Internal as Unsafe import qualified Foreign.ForeignPtr.Unsafe as Unsafe@@ -608,12 +607,12 @@  -- | The 'sum' function computes the sum of the numbers of a structure. osum :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono-osum = getSum . ofoldMap Sum+osum = ofoldl' (+) 0 {-# INLINE osum #-}  -- | The 'product' function computes the product of the numbers of a structure. oproduct :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono-oproduct = Data.Monoid.getProduct . ofoldMap Data.Monoid.Product+oproduct = ofoldl' (*) 1 {-# INLINE oproduct #-}  class (MonoFoldable mono, Monoid mono) => MonoFoldableMonoid mono where -- FIXME is this really just MonoMonad?
test/Spec.hs view
@@ -17,7 +17,7 @@ import qualified Data.Vector.Storable as VS import Data.Sequences import Prelude (Bool (..), ($), IO, min, abs, Eq (..), (&&), fromIntegral, Ord (..), String, mod, Int, show,-                return, asTypeOf, (.), Show, id, (+), succ, Maybe (..), (*), mod, map, flip)+                return, asTypeOf, (.), Show, id, (+), succ, Maybe (..), (*), mod, map, flip, otherwise, (-), div, seq) import qualified Prelude import Control.Monad.Trans.Writer import qualified Data.NonNull as NN@@ -37,6 +37,24 @@         it "non-empty list" $ onull [()] `shouldBe` False         it "empty text" $ onull ("" :: Text) `shouldBe` True         it "non-empty text" $ onull ("foo" :: Text) `shouldBe` False+    describe "osum" $ do+        it "list" $ do+            let x = 1+                y = 10000000 :: Int+                list = [x..y]+            osum list `shouldBe` ((x + y) * (y - x + 1) `div` 2)+    describe "oproduct" $ do+        it "list" $ do+            let x = 1+                y = 10000000 :: Int+                list = [x..y]+                fact n =+                    go 1 1+                  where+                    go i j+                        | i `seq` j `seq` j >= n = i+                        | otherwise = go (i * j) (j + 1)+            oproduct list `shouldBe` fact y `div` (fact (x - 1))     describe "clength" $ do         prop "list" $ \i' ->             let x = replicate i () :: [()]