-
Code module Sum (Sum.sum) where import Prelude hiding (sum) sum :: (Foldable t) => t Integer -> Integer sum = foldr (+) 0
Test Cases module SumSpec (spec) where import Prelude hiding (sum) import qualified Prelude as Pre (sum) import Sum (sum) import Test.Hspec spec :: Spec spec = do it "tests" $ do Sum.sum [1] `shouldBe` Pre.sum [1] it "Empty list" $ do Sum.sum [] `shouldBe` Pre.sum [] it "Different container" $ do Sum.sum (Just 1) `shouldBe` Pre.sum (Just 1) it "negative numbers" $ do Sum.sum [-1] `shouldBe` Pre.sum [-1] it "big numbers" $ do Sum.sum [18446744073709551615] `shouldBe` Pre.sum [18446744073709551615]
Output:
-
Code - module Sum (Sum.sum) where
- import Prelude hiding (sum)
- sum :: (Foldable t) => t Integer -> Integer
sum xs | null xs = 0 | otherwise = foldr1 (+) xs- sum = foldr (+) 0
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}