Skip to content

Commit 77e94c8

Browse files
committed
Merge pull request #156 from adubovik/master
Removed unnecessary strictness in IntSet.foldl accumulator.
2 parents 10f0a88 + bdd7b33 commit 77e94c8

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

Data/IntSet/Base.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,6 @@ foldl f z = \t -> -- Use lambda t to be inlinable with two arguments only.
882882
| otherwise -> go (go z l) r
883883
_ -> go z t
884884
where
885-
STRICT_1_OF_2(go)
886885
go z' Nil = z'
887886
go z' (Tip kx bm) = foldlBits kx f z' bm
888887
go z' (Bin _ _ l r) = go (go z' l) r

containers.cabal

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,21 @@ test-suite intmap-strictness-properties
252252

253253
ghc-options: -Wall
254254
include-dirs: include
255+
256+
test-suite intset-strictness-properties
257+
hs-source-dirs: tests, .
258+
main-is: intset-strictness.hs
259+
type: exitcode-stdio-1.0
260+
261+
build-depends:
262+
array,
263+
base >= 4.2 && < 5,
264+
ChasingBottoms,
265+
deepseq >= 1.2 && < 1.5,
266+
QuickCheck >= 2.4.0.1,
267+
ghc-prim,
268+
test-framework >= 0.3.3,
269+
test-framework-quickcheck2 >= 0.2.9
270+
271+
ghc-options: -Wall
272+
include-dirs: include

tests/intset-strictness.hs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving #-}
2+
{-# OPTIONS_GHC -fno-warn-orphans #-}
3+
4+
module Main (main) where
5+
6+
import Prelude hiding (foldl)
7+
8+
import Test.ChasingBottoms.IsBottom
9+
import Test.Framework (Test, defaultMain, testGroup)
10+
import Test.Framework.Providers.QuickCheck2 (testProperty)
11+
12+
import Data.IntSet
13+
14+
------------------------------------------------------------------------
15+
-- * Properties
16+
17+
------------------------------------------------------------------------
18+
-- ** Lazy module
19+
20+
pFoldlAccLazy :: Int -> Bool
21+
pFoldlAccLazy k =
22+
isn'tBottom $ foldl (\_ x -> x) (bottom :: Int) (singleton k)
23+
24+
------------------------------------------------------------------------
25+
-- * Test list
26+
27+
tests :: [Test]
28+
tests =
29+
[
30+
-- Basic interface
31+
testGroup "IntSet"
32+
[ testProperty "foldl is lazy in accumulator" pFoldlAccLazy
33+
]
34+
]
35+
36+
------------------------------------------------------------------------
37+
-- * Test harness
38+
39+
main :: IO ()
40+
main = defaultMain tests
41+
42+
------------------------------------------------------------------------
43+
-- * Utilities
44+
45+
isn'tBottom :: a -> Bool
46+
isn'tBottom = not . isBottom

0 commit comments

Comments
 (0)