From 1e6a6df8d367468dc534b092f939833d0c0c481b Mon Sep 17 00:00:00 2001 From: Heinrich Apfelmus Date: Mon, 8 Sep 2025 13:38:12 +0200 Subject: [PATCH] Use `seq` directly in `partialProduct` --- src/Math/Combinatorics/Exact/Factorial.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Math/Combinatorics/Exact/Factorial.hs b/src/Math/Combinatorics/Exact/Factorial.hs index 5d443c2..0751681 100644 --- a/src/Math/Combinatorics/Exact/Factorial.hs +++ b/src/Math/Combinatorics/Exact/Factorial.hs @@ -111,15 +111,15 @@ factorial n -- argument is the largest previously used term. partialProduct :: (Integral a) => Int -> a -> (a,a) partialProduct len j - | half == 0 = (,) (j+2) (j+2) - | len == 2 = (,) ((j+2)*(j+4)) (j+4) + | half == 0 = mkPair (j+2) (j+2) + | len == 2 = mkPair ((j+2)*(j+4)) (j+4) | otherwise = - let (qL, j' ) = partialProduct (len - half) j - (qR, j'') = partialProduct half j' - in (,) (qL*qR) j'' + let (qL , j' ) = partialProduct (len - half) j + (qR , j'') = partialProduct half j' + in mkPair (qL*qR) j'' where - half = len `quot` 2 - () = ($!) -- fix associativity + mkPair = \x y -> x `seq` y `seq` (x,y) + half = len `quot` 2 {- floorLog2 :: (Integral a, Bits a) => a -> Int