diff --git a/src/BinomialQueue/Internals.hs b/src/BinomialQueue/Internals.hs index 2f6a5d6..eeb48b7 100644 --- a/src/BinomialQueue/Internals.hs +++ b/src/BinomialQueue/Internals.hs @@ -536,8 +536,8 @@ instance Functor rk => Functor (BinomTree rk) where instance Functor rk => Functor (BinomForest rk) where fmap _ Nil = Nil - fmap f (Skip ts) = Skip (fmap f ts) - fmap f (Cons t ts) = Cons (fmap f t) (fmap f ts) + fmap f (Skip ts) = Skip $! fmap f ts + fmap f (Cons t ts) = Cons (fmap f t) $! fmap f ts instance Foldr Zero where foldr_ _ z ~Zero = z diff --git a/src/Data/PQueue/Internals.hs b/src/Data/PQueue/Internals.hs index f2b742d..cd6f0d7 100644 --- a/src/Data/PQueue/Internals.hs +++ b/src/Data/PQueue/Internals.hs @@ -341,11 +341,11 @@ toListUApp (MinQueue _ x ts) app = x : BQ.foldrU (:) app ts -- | \(O(\log n)\). @seqSpine q r@ forces the spine of @q@ and returns @r@. -- --- Note: The spine of a 'MinQueue' is stored somewhat lazily. Most operations --- take great care to prevent chains of thunks from accumulating along the --- spine to the detriment of performance. However, @mapU@ can leave expensive --- thunks in the structure and repeated applications of that function can --- create thunk chains. +-- Note: The spine of a 'MinQueue' is stored somewhat lazily. In earlier +-- versions of this package, some operations could produce chains of thunks +-- along the spine, occasionally necessitating manual forcing. Now, all +-- operations are careful to force enough to avoid this problem. +{-# DEPRECATED seqSpine "This function is no longer necessary or useful." #-} seqSpine :: MinQueue a -> b -> b seqSpine Empty z = z seqSpine (MinQueue _ _ ts) z = BQ.seqSpine ts z diff --git a/src/Data/PQueue/Max.hs b/src/Data/PQueue/Max.hs index 6a81739..20bd27e 100644 --- a/src/Data/PQueue/Max.hs +++ b/src/Data/PQueue/Max.hs @@ -369,10 +369,10 @@ keysQueue (Prio.MaxPQ q) = MaxQ (Min.keysQueue q) -- | \(O(\log n)\). @seqSpine q r@ forces the spine of @q@ and returns @r@. -- --- Note: The spine of a 'MaxQueue' is stored somewhat lazily. Most operations --- take great care to prevent chains of thunks from accumulating along the --- spine to the detriment of performance. However, 'mapU' can leave expensive --- thunks in the structure and repeated applications of that function can --- create thunk chains. +-- Note: The spine of a 'MaxQueue' is stored somewhat lazily. In earlier +-- versions of this package, some operations could produce chains of thunks +-- along the spine, occasionally necessitating manual forcing. Now, all +-- operations are careful to force enough to avoid this problem. +{-# DEPRECATED seqSpine "This function is no longer necessary or useful." #-} seqSpine :: MaxQueue a -> b -> b seqSpine (MaxQ q) = Min.seqSpine q diff --git a/src/Data/PQueue/Min.hs b/src/Data/PQueue/Min.hs index 55479a3..21733ba 100644 --- a/src/Data/PQueue/Min.hs +++ b/src/Data/PQueue/Min.hs @@ -262,7 +262,7 @@ keysQueue (Prio.MinPQ n k _ ts) = MinQueue n k (BQ.MinQueue (keysF (const Zero) keysF :: (pRk k a -> rk k) -> Prio.BinomForest pRk k a -> BinomForest rk k keysF f ts0 = case ts0 of Prio.Nil -> Nil - Prio.Skip ts' -> Skip (keysF f' ts') + Prio.Skip ts' -> Skip $! keysF f' ts' Prio.Cons (Prio.BinomTree k _ ts) ts' - -> Cons (BinomTree k (f ts)) (keysF f' ts') + -> Cons (BinomTree k (f ts)) $! keysF f' ts' where f' (Prio.Succ (Prio.BinomTree k _ ts) tss) = Succ (BinomTree k (f ts)) (f tss) diff --git a/src/Data/PQueue/Prio/Internals.hs b/src/Data/PQueue/Prio/Internals.hs index 04005d4..38edea7 100644 --- a/src/Data/PQueue/Prio/Internals.hs +++ b/src/Data/PQueue/Prio/Internals.hs @@ -615,9 +615,9 @@ extract = start mapForest :: (k -> a -> b) -> (rk k a -> rk k b) -> BinomForest rk k a -> BinomForest rk k b mapForest f fCh ts0 = case ts0 of Nil -> Nil - Skip ts' -> Skip (mapForest f fCh' ts') + Skip ts' -> Skip $! mapForest f fCh' ts' Cons (BinomTree k a ts) tss - -> Cons (BinomTree k (f k a) (fCh ts)) (mapForest f fCh' tss) + -> Cons (BinomTree k (f k a) (fCh ts)) $! mapForest f fCh' tss where fCh' (Succ (BinomTree k a ts) tss) = Succ (BinomTree k (f k a) (fCh ts)) (fCh tss) @@ -715,12 +715,12 @@ traverseWithKeyU f (MinPQ n k a ts) = liftA2 (MinPQ n k) (f k a) (traverseForest traverseForest :: (Applicative f) => (k -> a -> f b) -> (rk k a -> f (rk k b)) -> BinomForest rk k a -> f (BinomForest rk k b) traverseForest f fCh ts0 = case ts0 of Nil -> pure Nil - Skip ts' -> Skip <$> traverseForest f fCh' ts' + Skip ts' -> (Skip $!) <$> traverseForest f fCh' ts' Cons (BinomTree k a ts) tss - -> liftA3 (\p q -> Cons (BinomTree k p q)) (f k a) (fCh ts) (traverseForest f fCh' tss) + -> liftA3 (\a' ts' tss' -> Cons (BinomTree k a' ts') $! tss') (f k a) (fCh ts) (traverseForest f fCh' tss) where fCh' (Succ (BinomTree k a ts) tss) - = Succ <$> (BinomTree k <$> f k a <*> fCh ts) <*> fCh tss + = liftA3 (\a' ts' -> Succ (BinomTree k a' ts')) (f k a) (fCh ts) (fCh tss) -- | Unordered right fold on a binomial forest. foldrWithKeyF_ :: (k -> a -> b -> b) -> (rk k a -> b -> b) -> BinomForest rk k a -> b -> b @@ -748,20 +748,20 @@ foldlWithKeyF_ f fCh ts0 = case ts0 of mapKeysMonoF :: (k -> k') -> (rk k a -> rk k' a) -> BinomForest rk k a -> BinomForest rk k' a mapKeysMonoF f fCh ts0 = case ts0 of Nil -> Nil - Skip ts' -> Skip (mapKeysMonoF f fCh' ts') + Skip ts' -> Skip $! mapKeysMonoF f fCh' ts' Cons (BinomTree k a ts) ts' - -> Cons (BinomTree (f k) a (fCh ts)) (mapKeysMonoF f fCh' ts') + -> Cons (BinomTree (f k) a (fCh ts)) $! mapKeysMonoF f fCh' ts' where fCh' (Succ (BinomTree k a ts) tss) = Succ (BinomTree (f k) a (fCh ts)) (fCh tss) -- | \(O(\log n)\). @seqSpine q r@ forces the spine of @q@ and returns @r@. -- --- Note: The spine of a 'MinPQueue' is stored somewhat lazily. Most operations --- take great care to prevent chains of thunks from accumulating along the --- spine to the detriment of performance. However, 'mapKeysMonotonic' can leave --- expensive thunks in the structure and repeated applications of that function --- can create thunk chains. +-- Note: The spine of a 'MinPQueue' is stored somewhat lazily. In earlier +-- versions of this package, some operations could produce chains of thunks +-- along the spine, occasionally necessitating manual forcing. Now, all +-- operations are careful to force enough to avoid this problem. +{-# DEPRECATED seqSpine "This function is no longer necessary or useful." #-} seqSpine :: MinPQueue k a -> b -> b seqSpine Empty z0 = z0 seqSpine (MinPQ _ _ _ ts0) z0 = ts0 `seqSpineF` z0 where diff --git a/src/Data/PQueue/Prio/Max/Internals.hs b/src/Data/PQueue/Prio/Max/Internals.hs index 161cbc1..6bfa5ea 100644 --- a/src/Data/PQueue/Prio/Max/Internals.hs +++ b/src/Data/PQueue/Prio/Max/Internals.hs @@ -578,10 +578,10 @@ toListU (MaxPQ q) = fmap (first' unDown) (Q.toListU q) -- | \(O(\log n)\). @seqSpine q r@ forces the spine of @q@ and returns @r@. -- --- Note: The spine of a 'MaxPQueue' is stored somewhat lazily. Most operations --- take great care to prevent chains of thunks from accumulating along the --- spine to the detriment of performance. However, 'mapKeysMonotonic' can leave --- expensive thunks in the structure and repeated applications of that function --- can create thunk chains. +-- Note: The spine of a 'MaxPQueue' is stored somewhat lazily. In earlier +-- versions of this package, some operations could produce chains of thunks +-- along the spine, occasionally necessitating manual forcing. Now, all +-- operations are careful to force enough to avoid this problem. +{-# DEPRECATED seqSpine "This function is no longer necessary or useful." #-} seqSpine :: MaxPQueue k a -> b -> b seqSpine (MaxPQ q) = Q.seqSpine q