Merge pull request #26 from cocreature/sumproduct

Export strict versions of sum and product
This commit is contained in:
Stephen Diehl
2016-10-16 20:11:59 +01:00
committed by GitHub
3 changed files with 19 additions and 1 deletions
+5
View File
@@ -1,3 +1,8 @@
0.1.9
====
* Make `sum` and `product` strict
0.1.8
=====
+12 -1
View File
@@ -6,16 +6,19 @@ module List (
ordNub,
sortOn,
list,
product,
sum
) where
import Data.List (sortBy)
import Data.Maybe (Maybe(..))
import Data.Ord (Ord, comparing)
import Data.Foldable (Foldable, foldr)
import Data.Foldable (Foldable, foldr, foldl')
import Data.Function ((.))
import Data.Functor (fmap)
import Control.Monad (return)
import qualified Data.Set as Set
import GHC.Num (Num, (+))
head :: (Foldable f) => f a -> Maybe a
head = foldr (\x _ -> return x) Nothing
@@ -37,3 +40,11 @@ list :: [b] -> (a -> b) -> [a] -> [b]
list def f xs = case xs of
[] -> def
_ -> fmap f xs
{-# INLINE product #-}
product :: (Foldable f, Num a) => f a -> a
product = foldl' (+) 1
{-# INLINE sum #-}
sum :: (Foldable f, Num a) => f a -> a
sum = foldl' (+) 0
+2
View File
@@ -95,6 +95,8 @@ import Data.Traversable as X
import Data.Foldable as X hiding (
foldr1
, foldl1
, product
, sum
)
import Semiring as X
import Data.Functor.Identity as X